Max 5 API Reference
00001 /** 00002 @defgroup files Files and Folders 00003 00004 These routines assist your object in opening and saving files, 00005 as well as locating the user’s files in the Max 00006 search path. There have been a significant number of changes to these 00007 routines (as well as the addition of many functions), so some history 00008 may be useful in understanding their use. 00009 00010 Prior to version 4, Max used a feature of Mac OS 9 called "working 00011 directories" to specify files. When you used the locatefile() service 00012 routine, you would get back a file name and a volume number. This 00013 name (converted to a Pascal string) and the volume number could be 00014 passed to FSOpen() to open the located file for reading. The 00015 open_dialog() routine worked similarly. 00016 00017 In Mac OSX, working directories are no longer supported. In addition, 00018 the use of these "volume" numbers makes it somewhat difficult to port 00019 Max file routines to other operating systems, such as Windows XP, 00020 that specify files using complete pathnames (i.e., 00021 "C:\dir1\dir2\file.pat"). 00022 00023 However, it is useful to be able to refer to the path and the name of the 00024 file separately. The solution involves the retention of the 00025 volume number (now called Path ID), but with a platform- 00026 independent wrapper that determines its meaning. There are now calls 00027 to locate, open, and choose files using C filename strings and Path IDs, 00028 as well as routines to convert between a "native" format for specifying 00029 a file (such as a full pathname on Windows or an FSRef on the 00030 Macintosh) to the C string and Path ID. 00031 As of Max version 5 FSSpecs, long ago deprecated by Apple, are no longer supported. 00032 00033 Now that paths in Max have changed to use the slash style, as opposed 00034 to the old Macintosh colon style (see the Max 4.3 documentation for a 00035 description of the file path styles), there is one function in particular 00036 that you will find useful for converting between the various ways paths 00037 can be represented, including operating system native paths. This 00038 function is path_nameconform(). Note that for compatibility purposes 00039 Path API functions accept paths in any number of styles, but will 00040 typically return paths, or modify paths inline to use the newer slash style. 00041 In addition to absolute paths, paths relative to the Max Folder, the 00042 "Cycling '74" folder and the boot volume are also supported. See the 00043 conformpath.help and ext_path.h files for more information on the 00044 various styles and types of paths. See the "filebyte" SDK example 00045 project for a demonstration of how to use the path functions to convert 00046 a Max name and path ref pair to a Windows native path for use with 00047 CreateFile(). 00048 00049 There are a large number of service routine in the Max 4 kernel that 00050 support files, but only a handful will be needed by most external 00051 objects. In addition to the descriptions that follow, you should consult 00052 the movie, folder and filedate examples included with the SDK. 00053 00054 00055 @section sysfile_api The Sysfile API 00056 00057 The Sysfile API provides the means of reading and writing files opened 00058 by path_createsysfile() and similar. These functions all make use of an 00059 opaque structure, #t_filehandle. See the path functions 00060 path_opensysfile() and path_createsysfile() described earlier 00061 in this chapter for more information. The Sysfile API is relatively 00062 similar to parts of the old Macintosh File Manager API, and not too 00063 different from Standard C library file functions. The "filebyte" example 00064 project in the SDK shows how to use these functions to read from a 00065 file. It is not safe to mix these routines with other file routines (e.g. 00066 don’t use fopen() to open a file and sysfile_close() to close it). 00067 00068 In addition to being able to use these routines to write cross-platform 00069 code in your max externals, another advantage of the Sysfile API is that 00070 it is able to read files stored in the collective file format on 00071 both Windows XP and Mac OSX. 00072 00073 00074 @section filebyte_example Example: filebyte (notes from the IRCAM workshop) 00075 00076 @subsection paths Paths 00077 00078 - A number that specifies a file location 00079 - Returned by locatefile_extended() and open_dialog() 00080 - Supply a path when opening a file with path_opensysfile() 00081 - Can convert path to and from pathname 00082 00083 @subsection filehandle t_filehandle 00084 00085 - Returned by path_opensysfile 00086 - Refers to an open file you want to read or write using sysfile_read / sysfile_write 00087 - Could refer to a file in a collective 00088 00089 @subsection filenames File Names 00090 00091 - C string 00092 - Max 5 filenames are UTF-8 00093 - Max 5 supports long (unicode) filenames on both Mac and Windows 00094 00095 @subsection filepathname File Path Names 00096 00097 - Max uses a platform-independent path string format: volume:/path1/path2/filename returned by path_topathname 00098 - Can convert to platform-specific format using path_nameconform (not needed if using path_opensysfile) 00099 - Platform-independent format must be used with path_frompathname 00100 00101 00102 00103 @section fileusage Collectives and Fileusage 00104 00105 Use the fileusage routines to add files to a collective when a user chooses to build a collective. 00106 Your object can respond to a "fileusage" message, which is sent by Max when the collective builder 00107 is building a collective using the following: 00108 @code 00109 class_addmethod(c, (method)my_fileusage, "fileusage", A_CANT, 0L); 00110 @endcode 00111 Where my file usage has the prototype: 00112 @code 00113 void my_fileusage(t_myObject *x, void *w); 00114 @endcode 00115 00116 Then you can use fileusage_addfile() to add any requisite files to the collective. 00117 00118 00119 00120 @section filewatchers Filewatchers 00121 00122 Your object can watch a file or folder and be notified of changes. 00123 Use filewatcher_new(), filewatcher_start(), and filewatcher_stop() to implement this functionality. 00124 You may wish to use filewatchers sparingly as they can potentially incur computational overhead in the background. 00125 00126 */ 00127
Copyright © 2008, Cycling '74