Finale PDK Framework  0.54
ff_parts.h
1 /*
2  * File: ff_parts.h
3  * Author: Jari Williamsson
4  *
5  * Created on den 22 mars 2011, 13:01
6  */
7 
8 #ifndef FF_PARTS_H
9 #define FF_PARTS_H
10 
11 #include "ff_basecollection.h"
12 #include "ff_othercollection.h"
13 
14 #ifndef DOXYGEN_SHOULD_IGNORE_THIS
15 /* Undocumented - For internal use only */
16 #include "pragma_align_begin.h"
17 struct __XEDTPartDef
18 {
19  CMPER nameID; // The EDTTextBlock2004 text block ID for the part's name.
20  utwobyte partOrder; // The unique order of the part that determines its tab
21  // order and position in the Edit Part submenu. (1-based)
22  twobyte copies; // The number of copies of the part to print.
23  FLAG_16 flags;
24  twobyte m_nSmartMusicInst; // The number of the SmartMusic instrument
25  // to use for this part.
26  twobyte m_DefaultNameStaffOrGroup; // Contains the cmper of the staff or
28 };
29 #include "pragma_align_end.h"
30 
31 
32 const EXTAG xot_PartDef = MAKEEXTAG(edOther,'p','D');
33 /* cmper = EPARTID; inci = 0 */
34 
35 const FLAG_16 __PARTDEF_PRINTPART = 0x0001;
36 const FLAG_16 __PARTDEF_EXTRACTPART = 0x0002;
37 const FLAG_16 __PARTDEF_APPLYFORMAT = 0x0004;
38 const FLAG_16 __PARTDEF_NEEDS_RECALC = 0x0008; /* Need to call recalc()
39 next time part is viewed */
40 const FLAG_16 __PARTDEF_NEEDS_SPACING = 0x0010; /* Need to space music next
41 time part is viewed */
42 const FLAG_16 __PARTDEF_IS_NEW = 0x0020;
43 const FLAG_16 __PARTDEF_IS_MODIFIED = 0x0040; /* A staff was added or
44 deleted. Apply part creation prefs
45  // but don't do any other "New Part" stuff. */
46 const FLAG_16 __PARTDEF_NAMEISDEFAULT = 0x0080; /* Part name is a default
47  staff or group name,
48  e.g. [Staff 1] or [Group 1]. */
49 const FLAG_16 __PARTDEF_USE_AS_SMP_INST = 0x0100; /* This part will be
50  available as an item in SmartMusic's instrument list
51  when the file is opened in SmartMusic. */
52 const FLAG_16 __PARTDEF_UNLINK_INSTS = 0x0200; /* Part's instrument
53 settings are unlinked from the score's instrument settings. */
54 
55 #endif
56 
57 
67 class FCPart : public __FCNoInciOther
68 {
69 #ifndef DOXYGEN_SHOULD_IGNORE_THIS
70 private:
71  __XEDTPartDef _partdata;
72  FCString _astring;
73  EPARTID _partid;
74  EDOCID _documentid;
75  EPARTID _previouspart;
76 
77  virtual EXTAG Tag() { return MAKEEXTAG(edOther,'p','D'); }
78 
79  virtual int DataSizeLoad() { return sizeof(_partdata); }
80  virtual void* Allocate() { return (void*) &_partdata; }
81 
86  virtual void CloneMemoryFrom(__FCBaseData* pSource)
87  {
88  memcpy(&_partdata, ((FCPart*)pSource)->_GetDataPtr(), sizeof(_partdata));
89  _datablock = &_partdata;
90  _loadedsize = sizeof(_partdata);
91  }
92 
94  virtual __FCBaseData* CreateObject()
95  {
96  return new FCPart();
97  }
98 
99 #endif /* #ifndef DOXYGEN_SHOULD_IGNORE_THIS */
100 
101 public:
111 
114 
117  };
118 public:
119 
120  virtual const char* ClassName() { return "FCPart"; }
121  virtual const PDKFRAMEWORK_CLASSID GetClassID() { return FCID_PART; }
122 
123 #ifndef DOXYGEN_SHOULD_IGNORE_THIS
124 
127  void* _GetDataPtr() { return &_partdata; }
128 #endif /* DOXYGEN_SHOULD_IGNORE_THIS */
129 
130 
138  FCPart(EPARTID partid = PARTID_CURRENT) : __FCNoInciOther() {
139  if (partid == PARTID_CURRENT) {
140  partid = FX_GetCurrentPartID();
141  }
142  _partid = partid;
143  _documentid = FX_GetCurrentEnigmaDocument();
144  _previouspart = PARTID_UNKNOWN;
145  memset(&_partdata, 0, sizeof(_partdata));
146  }
147 
150  virtual ~FCPart() {
151 #ifdef PDK_FRAMEWORK_DIAGNOSE
152  if (_previouspart != PARTID_UNKNOWN) {
153  DebugOut("FCPart::SwitchTo() has been called without a FCPart::SwitchBack()!!!");
154  }
155 #endif
156  }
157 
163  EPARTID GetID() const {
164  return _partid;
165  }
166 
167 
180 
181 #ifdef PDK_FRAMEWORK_LUAFRIENDLY
182 
183  FCString* CreateCustomTextString_GC();
184 #endif
185 
193  bool DeleteCustomText();
194 
205  bool SaveCustomTextString(FCString* pString);
206 
207 
214  EDOCID GetDocumentID() const {
215  return _documentid;
216  }
217 
224  bool SetID(FCPart* pPart) {
225  if (_previouspart != PARTID_UNKNOWN) return false;
226  _partid = pPart->GetID();
227  _documentid = FX_GetCurrentEnigmaDocument();
228  _previouspart = PARTID_UNKNOWN;
229  return true;
230  }
231 
240  bool SwitchTo() {
241  if (!IsCurrentDocument()) return false;
242  if (_previouspart != PARTID_UNKNOWN) return false;
243  _previouspart = FX_GetCurrentPartID();
244  FX_SetCurrentPartID(_partid);
245  return true;
246  }
247 
256  bool SwitchBack()
257  {
258  if (_previouspart == PARTID_UNKNOWN) return false;
259  if (!IsCurrentDocument()) return false;
260  FX_SetCurrentPartID(_previouspart);
261  _previouspart = PARTID_UNKNOWN;
262  return true;
263  }
264 
271  bool ViewInDocument() {
272  if (!IsCurrentDocument()) return false;
273  FX_SetCurrentPartInView(_partid);
274  return true;
275  }
276 
282  bool IsStaffIncluded(int staffno);
283 
289  bool IsScore() {
290  return GetID() == PARTID_SCORE;
291  }
292 
298  bool IsPart() {
299  return GetID() != PARTID_SCORE;
300  }
301 
302 
308  bool IsCurrent() {
309  if (_partid != FX_GetCurrentPartID()) return false;
310  if (!IsCurrentDocument()) return false;
311  return true;
312  }
313 
321  return (_documentid == FX_GetCurrentEnigmaDocument());
322  }
323 
331  bool HasCustomText() const { return (_partdata.nameID != 0); }
332 
334  virtual bool IsIdentical(__FCBase* pCompareObject) {
335  if (!__FCBase::IsIdentical(pCompareObject)) return false;
336  FCPart* pComparePart = (FCPart*) pCompareObject;
337  if (GetID() != pComparePart->GetID()) return false;
338  if (GetDocumentID() != pComparePart->GetDocumentID()) return false;
339  return true;
340  }
341 
350  bool SetCurrent()
351  {
352  if (_previouspart != PARTID_UNKNOWN) return false;
353  _documentid = FX_GetCurrentEnigmaDocument();
354  _partid = FX_GetCurrentPartID();
355  _previouspart = PARTID_UNKNOWN;
356  return true;
357  }
358 
371  void GetName(FCString* pString);
372 
377  bool GetShouldPrint() const { return GetBitFlag(_partdata.flags, __PARTDEF_PRINTPART); }
378 
383  bool GetShouldExtract() const { return GetBitFlag(_partdata.flags, __PARTDEF_EXTRACTPART); }
384 
392  bool GetShouldUpdateLayout() const { return GetBitFlag(_partdata.flags, __PARTDEF_NEEDS_RECALC); }
393 
401  bool GetShouldUpdateSpacing() const { return GetBitFlag(_partdata.flags, __PARTDEF_NEEDS_SPACING); }
402 
407  bool GetUnlinkedInstrument() const { return GetBitFlag(_partdata.flags, __PARTDEF_UNLINK_INSTS); }
408 
417  utwobyte GetOrderID() const { return _partdata.partOrder; }
418 
423  twobyte GetPrintCopies() const { return _partdata.copies; }
424 
429  void SetShouldPrint(bool state) { Set16BitFlag(&_partdata.flags, __PARTDEF_PRINTPART, state); }
430 
435  void SetShouldExtract(bool state) { Set16BitFlag(&_partdata.flags, __PARTDEF_EXTRACTPART, state); }
436 
444  void SetShouldUpdateLayout(bool state) { Set16BitFlag(&_partdata.flags, __PARTDEF_NEEDS_RECALC, state); }
445 
453  void SetShouldUpdateSpacing(bool state) { Set16BitFlag(&_partdata.flags, __PARTDEF_NEEDS_SPACING, state); }
454 
459  void SetUnlinkedInstrument(bool state) { Set16BitFlag(&_partdata.flags, __PARTDEF_UNLINK_INSTS, state); }
460 
471  void SetOrderID(utwobyte idvalue)
472  {
473  if (idvalue < 1) return;
474  if (IsScore()) return;
475  _partdata.partOrder = idvalue;
476  }
477 
482  void SetPrintCopies(twobyte value) { _partdata.copies = value; }
483 
495  bool Print(FCPrintSettings* pSettings);
496 
497 #ifdef PDK_FRAMEWORK_DEBUG
498 
499  virtual void DebugDump() {
501  DebugOutDigit("Part ID: ", GetID());
502  FCString astring;
503  GetName(&astring);
504  DebugOutString("Part name: ", astring.GetCString());
505  }
506 #endif
507 };
508 
517 class FCParts : public __FCCollection {
518 public:
525  {
526  }
527 
528  virtual const char* ClassName() {
529  return "FCParts";
530  }
531 
538  int LoadAll();
539 
542  int ForEachWithScope(FCIteratorHandler* pIterator);
543 
551  FCPart* GetCurrent();
552 
559  {
560  FCPart* pPart = GetCurrent();
561  if (!pPart) return -1;
562  return GetIndexOf(pPart);
563  }
564 
572  FCPart* GetScore();
573 
582  static int CountPartsOnly()
583  {
584  return FX_CountParts();
585  }
586 
591  FCPart* GetItemAt(int index) { return (FCPart*) __FCCollection::GetItemAt(index); }
592 
598  void SortByOrderID();
599 
610  FCPart* FindPart(FCPart* pPartFind)
611  {
612  if (!pPartFind) return NULL;
613  for (int i = 0; i < GetCount(); i++)
614  {
615  FCPart* pPart = GetItemAt(i);
616  if (pPart->GetDocumentID() != pPartFind->GetDocumentID()) continue;
617  if (pPart->GetID() != pPartFind->GetID()) continue;
618  return pPart;
619  }
620  return NULL;
621  }
622 };
623 
624 
625 
626 #endif /* FF_PARTS_H */
627 
__FCBase * GetItemAt(int index)
Returns the object at the index position. Index is 0-based.
Definition: finaleframework.cpp:12797
const char * GetCString() const
Returns a C-string version of the string.
Definition: finaleframework.cpp:1159
static void DebugOutString(const char *pszPrefixText, const char *thestring)
Static method that outputs a line for debugging purposes (C string version). The text appears with th...
Definition: finaleframework.cpp:375
void GetName(FCString *pString)
Returns the local string object that stores the part string.
Definition: finaleframework.cpp:26968
virtual ~FCPart()
The destructor. Checks if SwitchBack has been called (if PDK_FRAMEWORK_DIAGNOSE has been defined)...
Definition: ff_parts.h:150
bool GetShouldUpdateLayout() const
Returns if the part is marked for a required layout update.
Definition: ff_parts.h:392
FCString * CreateCustomTextString()
Creates the raw string part name as a FCString object, for the parts that doesn't use the default-gen...
Definition: finaleframework.cpp:26921
virtual const char * ClassName()
Returns the name of the class, for diagnostic purposes. This method MUST be overwritten in each child...
Definition: ff_parts.h:528
int LoadAll()
Loads all parts (including the "score part") for the document.
Definition: finaleframework.cpp:27034
Definition: ff_parts.h:113
twobyte GetPrintCopies() const
Returns the number of print copies for the part.
Definition: ff_parts.h:423
FCPart * GetScore()
Returns the score object from the collection.
Definition: finaleframework.cpp:27087
static void DebugOut(const char *pszLine)
Static method to output a line of text for debugging purposes.
Definition: finaleframework.cpp:465
void * _datablock
Pointer to the object's data block, the meaning is implementation-specific for each derived subclass...
Definition: ff_base.h:640
bool GetUnlinkedInstrument() const
Returns if the part's instrument info is unlinked for the part.
Definition: ff_parts.h:407
int ForEachWithScope(FCIteratorHandler *pIterator)
Works like ForEach, but sets each part into scope before calling the Iterate handler method...
Definition: finaleframework.cpp:27053
void Set16BitFlag(FLAG_16 *flag, FLAG_16 flagbits, bool state)
Sets a 16 bit flag in the data block.
Definition: finaleframework.cpp:573
bool IsScore()
Returns true if the part is the score.
Definition: ff_parts.h:289
PDKFRAMEWORK_CLASSID
Constants for the GetClassID method.
Definition: ff_base.h:60
FCPart(EPARTID partid=PARTID_CURRENT)
The constructor. Sets the basic data for the part.
Definition: ff_parts.h:138
EDOCID GetDocumentID() const
Returns the internal document ID that is connected to the part.
Definition: ff_parts.h:214
virtual void CloneMemoryFrom(__FCBaseData *pSource)
Definition: finaleframework.cpp:753
static void DebugOutDigit(const char *pszPrefixText, int i)
Static method that outputs a line for debugging purposes. The text appears with the extra digit (in d...
Definition: finaleframework.cpp:274
Base class for the "Other" (ot_*) Enigma structures that don't use the inci parameter.
Definition: ff_other.h:212
static int CountPartsOnly()
Returns the number of available parts in the active document, without loading any parts...
Definition: ff_parts.h:582
FCPart * GetCurrent()
Returns a pointer to the element in the parts collection that is the "current" part (that has the dat...
Definition: finaleframework.cpp:27077
Class that represent one part in a document. The class also provides methods to switch between parts...
Definition: ff_parts.h:67
Definition: ff_parts.h:116
virtual bool IsIdentical(__FCBase *pCompareObject)
Returns true if the data in the passed object is considered to be identical to the current object...
Definition: ff_base.h:492
bool SetID(FCPart *pPart)
Sets up the object's part ID to be assigned to another part.
Definition: ff_parts.h:224
int GetCount() const
Returns the number of elements of the collection.
Definition: ff_basecollection.h:86
bool IsPart()
Returns true if the part is a part (and not the score).
Definition: ff_parts.h:298
Collection class for FCPart objects.
Definition: ff_parts.h:517
bool GetBitFlag(FLAG_32 flag, FLAG_32 flagbits) const
Gets a state from flag bits. Returns true if any bit in the mask is set.
Definition: ff_base.h:449
void SetUnlinkedInstrument(bool state)
Sets if the part's instrument info is unlinked for the part.
Definition: ff_parts.h:459
virtual const PDKFRAMEWORK_CLASSID GetClassID()
Returns the internal class ID for the PDK Framework class. This is implemented mostly because Lua has...
Definition: ff_parts.h:121
bool SetCurrent()
Maps the part to the part/document currently in focus.
Definition: ff_parts.h:350
virtual void * Allocate()=0
Definition: ff_parts.h:110
bool IsStaffIncluded(int staffno)
Returns true if the staff number is included in the part.
Definition: finaleframework.cpp:26990
void SetShouldUpdateLayout(bool state)
Sets if the part is marked for a required layout update.
Definition: ff_parts.h:444
int GetIndexOf(__FCBase *pObject)
Returns the 0-based order index for the object within the collection.
Definition: finaleframework.cpp:12805
bool ViewInDocument()
Switch the document display to another part.
Definition: ff_parts.h:271
EPARTID GetID() const
Returns the internal part ID.
Definition: ff_parts.h:163
Base class for the Finale Framework classes.
Definition: ff_base.h:47
void SetShouldUpdateSpacing(bool state)
Sets if the part is marked for a required music spacing update.
Definition: ff_parts.h:453
bool Print(FCPrintSettings *pSettings)
Quick-access method to print only one part in the currently active document.
Definition: finaleframework.cpp:27002
bool GetShouldUpdateSpacing() const
Returns if the part is marked for a required music spacing update.
Definition: ff_parts.h:401
int _loadedsize
Loaded size of the data block for a loaded object, in bytes. Since the datablock is implementation-sp...
Definition: ff_base.h:653
FCParts()
The construtor.
Definition: ff_parts.h:524
void SortByOrderID()
Sorts the loaded collection by order ID, which will result in the same order as in the parts definiti...
Definition: finaleframework.cpp:27113
Base class for all data-related classes (that handles Finale data).
Definition: ff_base.h:628
bool SwitchTo()
Sets the focus to this part (but does not set it in view).
Definition: ff_parts.h:240
bool HasCustomText() const
Returns true if part name is a custom text.
Definition: ff_parts.h:331
bool GetShouldPrint() const
Returns if the part should print or not.
Definition: ff_parts.h:377
virtual __FCBaseData * CreateObject()=0
Creates a new instance of the object.
PREDEFINED_PARTIDS
Predefined constants for part IDs.
Definition: ff_parts.h:108
Class for iterator handlers.
Definition: ff_iterator.h:25
void SetShouldExtract(bool state)
Sets if the part should be checked for part extraction.
Definition: ff_parts.h:435
Class containing printing settings (and the ability to print documents).
Definition: ff_base.h:3969
Class that provides storage for text. This is to achieve platform-transparent text handling...
Definition: ff_base.h:1473
bool IsCurrent()
Returns true if the part is the very same as the current part in the editing focus.
Definition: ff_parts.h:308
bool SaveCustomTextString(FCString *pString)
Saves the raw Enigma string as a custom text.
Definition: finaleframework.cpp:26947
utwobyte GetOrderID() const
Returns the part's internal (1-based) order ID.
Definition: ff_parts.h:417
virtual EXTAG Tag()=0
The Enigma tag for the derived class.
int GetCurrentIndex()
Returns the 0-based index to the element in the parts collection that is the "current" part (that has...
Definition: ff_parts.h:558
FCPart * GetItemAt(int index)
Definition: ff_parts.h:591
void SetOrderID(utwobyte idvalue)
Sets the part's internal (1-based) order ID. Use with care!!!
Definition: ff_parts.h:471
bool IsCurrentDocument()
Returns true if the document connected with the part in the object is the current document...
Definition: ff_parts.h:320
bool DeleteCustomText()
Deletes the custom text, resulting in the part using only default part names.
Definition: finaleframework.cpp:26938
virtual int DataSizeLoad()=0
Returns the data size for the data structure that should be loaded.
bool GetShouldExtract() const
Returns if the part should be checked for part extraction.
Definition: ff_parts.h:383
void SetPrintCopies(twobyte value)
Sets the number of print copies for the part.
Definition: ff_parts.h:482
virtual bool IsIdentical(__FCBase *pCompareObject)
Overridden method to provide comparison mechanism for parts.
Definition: ff_parts.h:334
void SetShouldPrint(bool state)
Sets if the part should print or not.
Definition: ff_parts.h:429
FCPart * FindPart(FCPart *pPartFind)
Finds a part by matching against a FCPart object.
Definition: ff_parts.h:610
virtual void DebugDump()
Outputs the class data/information for debugging purposes.
Definition: ff_parts.h:499
virtual const char * ClassName()
Returns the name of the class, for diagnostic purposes. This method MUST be overwritten in each child...
Definition: ff_parts.h:120
Base class for all collection classes. A collection is a storage that can store multiple objects of s...
Definition: ff_basecollection.h:24
virtual void DebugDump()
Outputs the class data/information for debugging purposes.
Definition: finaleframework.cpp:547
bool SwitchBack()
Switches back yo the "original" current part, that was in focus at the call to SwitchTo.
Definition: ff_parts.h:256