1
// RCS-ID: $Id: ScoreConstrains.h,v 1.11 2006/02/23 19:19:53 cecilios Exp $
2
//--------------------------------------------------------------------------------------
3
// LenMus Phonascus: The teacher of music
4
// Copyright (c) 2002-2006 Cecilio Salmeron
6
// This program is free software; you can redistribute it and/or modify it under the
7
// terms of the GNU General Public License as published by the Free Software Foundation;
8
// either version 2 of the License, or (at your option) any later version.
10
// This program is distributed in the hope that it will be useful, but WITHOUT ANY
11
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
12
// PARTICULAR PURPOSE. See the GNU General Public License for more details.
14
// You should have received a copy of the GNU General Public License along with this
15
// program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street,
16
// Fifth Floor, Boston, MA 02110-1301, USA.
18
// For any comment, suggestion or feature request, please contact the manager of
19
// the project at cecilios@users.sourceforge.net
21
//-------------------------------------------------------------------------------------
22
/*! @file ScoreConstrains.h
23
@brief Header file for lmScoreConstrains class
30
#ifndef __SCORECONSTRAINS_H__ //to avoid nested includes
31
#define __SCORECONSTRAINS_H__
33
// For compilers that support precompilation, includes "wx/wx.h".
34
#include "wx/wxprec.h"
44
#include "../score/score.h"
45
#include "Constrains.h"
48
// ----------------------------------------------------------------------------------
49
/*! @page FragmentAndSegments
52
Fragment and Segments tables
53
----------------------------
59
Score composition is based on rhythmic patterns called 'fragments'.
61
A fragment is formed by concatenating notes and rests elements, for example:
62
"(n * c)(n * c)(n * n)(n * c)(n * n)(n * s g+)(n * s)(n * c g-)"
64
The elements are separated by commas (,) to form 'segments' (a segment is
65
a group of elements that must go together and accupies one or more full
67
"(n * c),(n * c)(n * n)(n * c),(n * n),(n * s g+)(n * s)(n * c g-)"
69
In certain cases, it is necesary to specify that a barline must be in a
70
specific point. This will be specified by putting a bar (|) instead of a
72
"(n * c),(n * c)(n * n)(n * c)|(n * n),(n * s g+)(n * s)(n * c g-)"
74
Fragments must always start aligned to beat. Therefore it is necessary
75
to include any requied rest at the begining. Previous example must be
77
"(s c)(n * c),(n * c)(n * n)(n * c)|(n * n),(n * s g+)(n * s)(n * c g-)"
79
Rests at the begining must occupy less than a beat. That is, no empty beats
80
are allowed at the begining.
83
b) The fragment and segments tables
84
-----------------------------------
86
A ScoreConstrains object contains a FragmentsTable with all usable fragments.
88
Each entry in the fragments table contains all data associated to a fragment:
89
usable time signatures, time to align fragment to barline border (tam), and
90
a SegmentsTable with all segments composing the fragment.
92
Each entry in the segments table (lmSegmentEntry) contains the segment pattern
93
and some segment values, such as segment's duration (ts) and time to align
94
segment to beat border (tab).
99
// ----------------------------------------------------------------------------------
104
//-------------------------------------------------------------------------------------------
106
//-------------------------------------------------------------------------------------------
108
// Definition of an entry of the segments table
112
// constructor and destructor
113
lmSegmentEntry(wxString sSegment, float rTimeAlignBeat, float rSegmentDuration)
115
m_sSegment = sSegment;
116
m_rTimeAlignBeat = rTimeAlignBeat;
117
m_rSegmentDuration = rSegmentDuration;
123
wxString GetSource() { return m_sSegment; }
124
float GetTimeAlignBeat() { return m_rTimeAlignBeat; }
125
float GetSegmentDuration() { return m_rSegmentDuration; }
127
//member variables (one entry of the table)
128
wxString m_sSegment; //the pattern for this segment
129
float m_rTimeAlignBeat; //time to align segment to beat border (tam)
130
float m_rSegmentDuration; //duration of segment, excluding tam (ts)
134
// Finally this defines the type ArrayOfSegments as an array of lmSegmentEntry pointers
135
WX_DEFINE_ARRAY(lmSegmentEntry*, ArrayOfSegments);
139
//-------------------------------------------------------------------------------------------
141
//-------------------------------------------------------------------------------------------
143
// Definition of an entry of the fragments table (corresponds to a fragment)
144
class lmFragmentEntry
147
// constructor and destructor
148
lmFragmentEntry(lmTimeSignConstrains* pValidTimeSigns, float rTimeBarlineAling=0.0)
150
m_pValidTimeSigns = pValidTimeSigns;
151
m_rTimeBarlineAling = rTimeBarlineAling;
156
delete m_pValidTimeSigns;
158
for (i=0; i < (int)m_oSegments.Count(); i++) {
159
delete m_oSegments[i];
163
void AddSegment(lmSegmentEntry* pSegment) { m_oSegments.Add(pSegment); }
164
void SetTimeToAlignToBarline(float rTime) { m_rTimeBarlineAling = rTime; }
165
ArrayOfSegments* GetSegments() { return &m_oSegments; }
168
//member variables (one entry of the table)
169
float m_rTimeBarlineAling; //time to align fragment to barline or 0 if no alignment required
170
lmTimeSignConstrains* m_pValidTimeSigns; //valid time signatures to use with this fragment
171
ArrayOfSegments m_oSegments; //table of segments composing the fragment
176
// this defines the type ArrayOfFragments as an array of lmFragmentEntry pointers
177
WX_DEFINE_ARRAY(lmFragmentEntry*, ArrayOfFragments);
179
//Finally let's define the class that implements the fragments' table and the algoritms
180
// to load, save and deal with it
181
class lmFragmentsTable
187
void AddEntry(lmTimeSignConstrains* pValidTimeSigns, wxString sPattern);
189
// methods for accesing entries
190
int SelectFragments(ETimeSignature nTimeSign);
192
lmSegmentEntry* GetNextSegment();
195
// methods for pattern analysis
196
int SplitPattern(wxString sSource);
197
int SplitFragment(wxString sSource);
198
wxString GetFirstSegmentDuracion(wxString sSegment,
199
float* pSegmentDuration, float* pTimeAlignBeat);
203
ArrayOfFragments m_aFragment; //array of fragment entries
206
wxArrayInt m_aSelectionSet; // indexes to the entries that form the selection set
207
int m_nSelItem; // choosen item
208
ArrayOfSegments* m_pSegments; // the segments of the choosen fragment
209
int m_nNextSegment; // index over *m_pSegments pointing to next segment to return
216
//-------------------------------------------------------------------------------------------
217
// The ScoreConstrains object
218
//-------------------------------------------------------------------------------------------
221
#define lmNO_DEFAULTS false
223
/*! @class lmScoreConstrains
224
@brief Options for lmTheoSideReadingCtrol control
226
class lmScoreConstrains
230
~lmScoreConstrains() {}
232
bool IsValidClef(EClefType nClef) { return m_oClefs.IsValid(nClef); }
233
void SetClef(EClefType nClef, bool fValid) { m_oClefs.SetValid(nClef, fValid); }
234
void SetMaxNote(EClefType nClef, wxString sNote) { m_oClefs.SetUpperPitch(nClef, sNote); }
235
void SetMinNote(EClefType nClef, wxString sNote) { m_oClefs.SetLowerPitch(nClef, sNote); }
236
lmClefConstrain* GetClefConstrains() { return &m_oClefs; }
238
lmKeyConstrains* GetKeyConstrains() { return &m_oValidKeys; }
239
lmTimeSignConstrains* GetTimeSignConstrains() { return &m_oValidTimeSign; }
241
void SetMaxInterval(int nValue) { m_nMaxInterval = nValue; }
242
int GetMaxInterval() { return m_nMaxInterval; }
251
int SelectFragments(ETimeSignature nTimeSign) {
252
return(m_aFragmentsTable.SelectFragments(nTimeSign));
254
void ChooseRandomFragment() { return m_aFragmentsTable.ChooseRandom(); }
255
lmSegmentEntry* GetNextSegment() { return m_aFragmentsTable.GetNextSegment(); }
256
void AddFragment(lmTimeSignConstrains* pValidTimeSigns, wxString sPattern) {
257
m_aFragmentsTable.AddEntry(pValidTimeSigns, sPattern);
259
void SetSection(wxString sSection) { m_sSection = sSection; }
265
wxString m_sSection; // section name to save the constrains
266
int m_nMaxInterval; //max interval in two consecutive notes
268
lmKeyConstrains m_oValidKeys; //allowed key signatures
269
lmClefConstrain m_oClefs; //allowed clefs and scopes
270
lmTimeSignConstrains m_oValidTimeSign; //allowed time signatures
271
lmFragmentsTable m_aFragmentsTable; //allowed fragments
275
#endif // __SCORECONSTRAINS_H__