Finale PDK Framework  0.54
ff_stream.h
1 /*
2  * File: ff_stream.h
3  * Author: Jari Williamsson
4  *
5  * Created on den 23 mars 2012, 21:14
6  *
7  * Contains the stream classes for the Finale PDK Framework.
8  *
9  */
10 
11 #ifndef FF_STREAM_H
12 #define FF_STREAM_H
13 
14 #ifdef PDK_FRAMEWORK_STREAMS
15 
16 #include <stdio.h>
17 
19 class __FCBaseStream : public __FCBase
20 {
21 public:
22  __FCBaseStream() : __FCBase() {}
23 };
24 
25 
28 {
29 #if (FXT_VERSION < FINALEVERSION_25 || OPERATING_SYSTEM == WINDOWS)
30  FinPathSpec2009 _folderspec2009;
31 #if FXT_VERSION >= FINALEVERSION_2012
32  FinPathSpec2012 _folderspec2012;
33 #endif
34 #endif
35 #if FXT_VERSION >= FINALEVERSION_2025
36  FinPathSpec25 _folderspec2025;
37 #endif
38 
39  FCString _folder;
40  FCString _filename;
41 
42 protected:
43 #ifndef DOXYGEN_SHOULD_IGNORE_THIS
44  FILE* _pFile;
45  bool _MakeFullPath(FCString* pString);
46 #endif /* #ifndef DOXYGEN_SHOULD_IGNORE_THIS */
47 public:
50 #if FXT_VERSION < FINALEVERSION_2012
51  FinPathSpec2009* pFolder,
52 #elif FXT_VERSION < FINALEVERSION_25
53  FinPathSpec2012* pFolder,
54 #else
55  FinPathSpec25* pFolder,
56 #endif
57  FCString* pFileName) :
59  {
60  _folder.Clear();
61 #if (FXT_VERSION < FINALEVERSION_25 || OPERATING_SYSTEM == WINDOWS)
62  switch (FCString::_GetFinPathVersion())
63  {
64  case FINALEVERSION_2009:
65  memcpy(&_folderspec2009, pFolder, sizeof(_folderspec2009));
66  break;
67 #if FXT_VERSION >= FINALEVERSION_2012
68  case FINALEVERSION_2012:
69  memcpy(&_folderspec2012, pFolder, sizeof(_folderspec2012));
70  break;
71 #endif
72 #if FXT_VERSION >= FINALEVERSION_2025
73  case FINALEVERSION_2025:
74  memcpy(&_folderspec2025, pFolder, sizeof(_folderspec2025));
75  break;
76 #endif
77  }
78 #else
79  // For FinPathSpec25, use assign operator, not memcpy
80  _folderspec2025 = *pFolder;
81 #endif
82  _filename.SetString(pFileName);
83  _pFile = NULL;
84  }
85 
91  FCFileStream(FCString* pFolder, FCString* pFileName) : __FCBaseStream()
92  {
93  _folder.SetString(pFolder);
94 #if FXT_VERSION < FINALEVERSION_25 || OPERATING_SYSTEM == WINDOWS
95  switch (FCString::_GetFinPathVersion())
96  {
97  case FINALEVERSION_2009:
98  memset(&_folderspec2009, 0, sizeof(_folderspec2009));
99  break;
100 #if FXT_VERSION >= FINALEVERSION_2012
101  case FINALEVERSION_2012:
102  memset(&_folderspec2012, 0, sizeof(_folderspec2012));
103  break;
104 #endif
105 #if FXT_VERSION >= FINALEVERSION_2025
106  case FINALEVERSION_2025:
107  memset(&_folderspec2025, 0, sizeof(_folderspec2025));
108  break;
109 #endif
110  }
111 #else // Mac FXT_VERSION_25_BASE and greater
112  _folderspec2025.finPathSpecType = 0;
113  _folderspec2025.SetCFURLRef(NULL);
114 #endif
115  _filename.SetString(pFileName);
116  _pFile = NULL;
117  }
118 
120  virtual ~FCFileStream()
121  {
122  if (_pFile) fclose(_pFile);
123  _pFile = NULL;
124  }
125 
127  FILE* _GetFILE() { return _pFile; }
128 
130  bool IsOpen() { return (_pFile != NULL); }
131 
138  bool OpenFile(
139  WINCODE(WCHAR* pszMode)
140  MACCODE(const char* pszMode)
141  );
142 
144  virtual bool OpenRead() = 0;
145 
147  virtual bool OpenWrite() = 0;
148 
150  bool Close();
151 
153  void GetFullPath(FCString* pString)
154  {
155  if (!_MakeFullPath(pString)) pString->Clear();
156  }
157 };
158 
159 
166 {
167 public:
169 #if FXT_VERSION < FINALEVERSION_2012
170  FCTextFileStream(FinPathSpec2009* pFolder, FCString* pFileName) :
171  FCFileStream(pFolder, pFileName) { }
172 #elif FXT_VERSION < FINALEVERSION_25
173  FCTextFileStream(FinPathSpec2012* pFolder, FCString* pFileName) :
174  FCFileStream(pFolder, pFileName) { }
175 #else
176  FCTextFileStream(FinPathSpec25* pFolder, FCString* pFileName) :
177  FCFileStream(pFolder, pFileName) { }
178 #endif
179 
183  FCTextFileStream(FCString* pFolder, FCString* pFileName) :
184  FCFileStream(pFolder, pFileName)
185  {
186  }
187 
188  virtual bool OpenRead()
189  {
190  return this->OpenFile(
191  WINCODE(L"r")
192  MACCODE("r")
193  );
194  }
195 
196  virtual bool OpenWrite()
197  {
198  return this->OpenFile(
199  WINCODE(L"w+")
200  MACCODE("w+")
201  );
202  }
203 
214  virtual FCString* ReadString();
215 
222 
225  virtual bool WriteStrings(FCStrings *pStrings);
226 
230  virtual bool WriteText(FCString *pString);
231 
235  virtual bool WriteSettingsPairs(FCSettingsPairs* pPairs);
236 };
237 
240 {
241 public:
243 #if FXT_VERSION < FINALEVERSION_2012
244  FCTextFileUTF8Stream(FinPathSpec2009* pFolder, FCString* pFileName) :
245  FCTextFileStream(pFolder, pFileName) { }
246 #elif FXT_VERSION < FINALEVERSION_25
247  FCTextFileUTF8Stream(FinPathSpec2012* pFolder, FCString* pFileName) :
248  FCTextFileStream(pFolder, pFileName) { }
249 #else
250  FCTextFileUTF8Stream(FinPathSpec25* pFolder, FCString* pFileName) :
251  FCTextFileStream(pFolder, pFileName) { }
252 #endif
253 
254 
256  FCTextFileUTF8Stream(FCString* pFolder, FCString* pFileName) :
257  FCTextFileStream(pFolder, pFileName)
258  {
259  }
260 
262  virtual FCString* ReadString();
263 
266  virtual bool WriteStrings(FCStrings *pStrings);
267 
271  virtual bool WriteText(FCString *pString);
272 };
273 
274 
282 {
283  int _instrumentID;
284  int _parentinstrumentID;
285  int _defaultstaffpos;
286  int _generalMIDI;
287  int _groupID;
288  int _copies;
289  bool _copygroup;
290  FCString _name;
291 public:
293  {
294  _instrumentID = 0;
295  _parentinstrumentID = 0;
296  _defaultstaffpos = 0;
297  _generalMIDI = -1;
298  _groupID = 0;
299  _copies = 1;
300  _copygroup = false;
301  }
302 
310  void FormatName(FCString* pString, int orderid, int grouporderid);
311 
312 #ifndef DOXYGEN_SHOULD_IGNORE_THIS
313  void _SetName(FCString* pString) { _name.SetString(pString); }
314 
315  void _SetInstrumentID(int theID) { _instrumentID = theID; }
316  void _SetParentInstrumentID(int theID) { _parentinstrumentID = theID; }
317  void _SetDefaultStaffPos(int staffpos) { _defaultstaffpos = staffpos; }
318  void _SetGeneralMIDI(int gmnote) { _generalMIDI = gmnote; }
319  void _SetGroupID(int theID) { _groupID = theID; }
320  void _SetCopies(int count) { _copies = count; }
321  void _SetCopyGroup(bool state) { _copygroup = state; }
322 #endif /* #ifndef DOXYGEN_SHOULD_IGNORE_THIS */
323 
325  int GetInstrumentID() const { return _instrumentID; }
326 
328  int GetParentInstrumentID() const { return _parentinstrumentID; }
329 
331  int GetDefaultStaffPos() const { return _defaultstaffpos; }
332 
337  int GetGeneralMIDI() const { return _generalMIDI; }
338 
340  int GetGroupID() const { return _groupID; }
341 
343  int GetCopies() const { return _copies; }
344 
346  bool GetCopyGroup() const { return _copygroup; }
347 
348 
350  bool _IsValid()
351  {
352  if (_instrumentID == 0) return false;
353  if (_groupID == 0) return false;
354  if (_name.IsEmpty()) return false;
355  return true;
356  }
357 };
358 
366 {
367  bool _loaded;
368 public:
371  {
372  _loaded = false;
373  }
374 
376  bool FileIsAvailable();
377 
383  int LoadAll();
384 
390  FCPercussionNoteType* FindNoteType(FLAG_16 percnotetype);
391 
394 
396  bool IsLoaded() { return _loaded; }
397 };
398 
399 
400 #endif
401 
402 #endif /* FF_STREAM_H */
403 
__FCBase * GetItemAt(int index)
Returns the object at the index position. Index is 0-based.
Definition: finaleframework.cpp:12797
bool IsOpen()
Returns true if the file isn't closed.
Definition: ff_stream.h:130
Generic file stream class.
Definition: ff_stream.h:27
int LoadAll()
Loads and parses all the lines in Finale's PercNoteTypes.txt file. The result is a collection of FCPe...
Definition: finaleframework.cpp:31787
Class that contains one of Finale's global percussion note type definition.
Definition: ff_stream.h:281
FCPercussionNoteTypes()
The constructor.
Definition: ff_stream.h:370
A collection of FCPercussionNoteType objects, created by loading and parsing Finale's PercNoteTypes...
Definition: ff_stream.h:365
virtual bool WriteSettingsPairs(FCSettingsPairs *pPairs)
Writes a collection of settings pairs (with carriage return between each pair). This is an abstract F...
Definition: finaleframework.cpp:31654
bool Close()
Closes the file.
Definition: finaleframework.cpp:31501
bool GetCopyGroup() const
Returns true if the instrument should be copied into multiple groups.
Definition: ff_stream.h:346
FCTextFileUTF8Stream(FCString *pFolder, FCString *pFileName)
The constructor.
Definition: ff_stream.h:256
void Clear()
Creates an empty string.
Definition: ff_base.h:1831
virtual FCString * ReadString()
Reads the next line from the stream and creates it as a string object. NULL on error.
Definition: finaleframework.cpp:31582
FCTextFileStream(FinPathSpec25 *pFolder, FCString *pFileName)
The FinPathSpec-based constructor.
Definition: ff_stream.h:176
void GetFullPath(FCString *pString)
Fills the full path of the file.
Definition: ff_stream.h:153
FCFileStream(FinPathSpec25 *pFolder, FCString *pFileName)
The constructor.
Definition: ff_stream.h:49
void FormatName(FCString *pString, int orderid, int grouporderid)
Formats a FCString object to produce a printable name for a percussion instrument/sound.
Definition: finaleframework.cpp:31739
__FCBase()
The constructor.
Definition: ff_base.h:247
virtual ~FCFileStream()
The destructor.
Definition: ff_stream.h:120
virtual bool OpenRead()
Opens the file for reading.
Definition: ff_stream.h:188
int GetDefaultStaffPos() const
Returns the default staff position for the percussion notehead (as a starting point for the perussion...
Definition: ff_stream.h:331
virtual bool WriteText(FCString *pString)
Writes a text to the stream without any extra formatting. C-string version.
Definition: finaleframework.cpp:31646
int GetGroupID() const
Returns the group ID to where the instrument belongs.
Definition: ff_stream.h:340
virtual bool WriteText(FCString *pString)
Writes a text to the stream without any extra formatting. UTF-8 version.
Definition: finaleframework.cpp:31688
void SetString(FCString *pString)
Copies a string.
Definition: finaleframework.cpp:2132
Class for text (byte) streams.
Definition: ff_stream.h:165
FILE * _GetFILE()
For internal use only!
Definition: ff_stream.h:127
FCPercussionNoteType * GetItemAt(int index)
Overridden GetItemAt method.
Definition: ff_stream.h:393
bool FileIsAvailable()
Returns true if Finale provides a path to the PercNoteTypes.txt file.
Definition: finaleframework.cpp:31780
FCTextFileUTF8Stream(FinPathSpec25 *pFolder, FCString *pFileName)
The FinPathSpec-based constructor.
Definition: ff_stream.h:250
virtual FCString * ReadString()
Overridden method to support UTF-8 text conversion.
Definition: finaleframework.cpp:31696
int GetCopies() const
Returns the number of groups that the instrument should be copied to.
Definition: ff_stream.h:343
Base class for the Finale Framework classes.
Definition: ff_base.h:47
virtual bool WriteStrings(FCStrings *pStrings)
Writes a collection of strings with a carriage return between the lines. C-string version...
Definition: finaleframework.cpp:31634
int GetGeneralMIDI() const
Returns the general MIDI number for the note, if available.
Definition: ff_stream.h:337
virtual bool OpenWrite()
Opens the file for writing.
Definition: ff_stream.h:196
Class for UTF-8text streams.
Definition: ff_stream.h:239
Class that provides storage for text. This is to achieve platform-transparent text handling...
Definition: ff_base.h:1473
FCFileStream(FCString *pFolder, FCString *pFileName)
Constructor - folder string version. (This was a C string version for folders earlier.) NOTE: This has been changed to FCString in both arguments, since that would seem to be the easiest way to support Unicode paths.
Definition: ff_stream.h:91
virtual bool OpenWrite()=0
Opens the file for writing.
bool OpenFile()
Opens the file for a specific mode.
Definition: finaleframework.cpp:31479
FCPercussionNoteType * FindNoteType(FLAG_16 percnotetype)
Finds the a specific note type. If the instrument ID isn't found, the parent instrument ID is searche...
Definition: finaleframework.cpp:31903
FCTextFileStream(FCString *pFolder, FCString *pFileName)
The constructor. NOTE: This has been changed to FCString in both arguments, since that would seem to ...
Definition: ff_stream.h:183
Collection class for FCString class objects.
Definition: ff_basecollection.h:924
bool _IsValid()
For internal use only.
Definition: ff_stream.h:350
virtual bool OpenRead()=0
Opens the file for reading.
int GetInstrumentID() const
Returns the instrument ID.
Definition: ff_stream.h:325
Collection class for FCSettingsPair objects.
Definition: ff_basecollection.h:787
bool IsLoaded()
Returns true if the note types have been loaded successfully.
Definition: ff_stream.h:396
Abstract base class for streams.
Definition: ff_stream.h:19
virtual bool WriteStrings(FCStrings *pStrings)
Writes a collection of strings with a carriage return between the lines. UTF-8 version.
Definition: finaleframework.cpp:31676
FCStrings * ReadStrings()
Creates a FCStrings collection with all string lines. This might return NULL.
Definition: finaleframework.cpp:31615
int GetParentInstrumentID() const
Returns the parent instrument ID, which is used if the instrument ID can't be mapped.
Definition: ff_stream.h:328
Base class for all collection classes. A collection is a storage that can store multiple objects of s...
Definition: ff_basecollection.h:24
bool IsEmpty()
Returns true if the string is empty.
Definition: ff_base.h:2461