1
//---------------------------------------------------------------------------------------
2
// LenMus Phonascus: The teacher of music
3
// Copyright (c) 2002-2012 LenMus project
5
// This program is free software; you can redistribute it and/or modify it under the
6
// terms of the GNU General Public License as published by the Free Software Foundation,
7
// either version 3 of the License, or (at your option) any later version.
9
// This program is distributed in the hope that it will be useful, but WITHOUT ANY
10
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
11
// PARTICULAR PURPOSE. See the GNU General Public License for more details.
13
// You should have received a copy of the GNU General Public License along with this
14
// program. If not, see <http://www.gnu.org/licenses/>.
16
// For any comment, suggestion or feature request, please contact the manager of
17
// the project at cecilios@users.sourceforge.net
19
//---------------------------------------------------------------------------------------
21
#ifndef __LENMUS_COMPOSER_H__ //to avoid nested includes
22
#define __LENMUS_COMPOSER_H__
25
#include "lenmus_standard_header.h"
26
#include "lenmus_scores_constrains.h"
29
#include <lomse_internal_model.h>
30
#include <lomse_document.h>
31
#include <lomse_pitch.h>
32
using namespace lomse;
35
#include <wx/wxprec.h>
45
//forward declarations
46
class ScoreConstrains;
48
// symbolic names for bool fUpStep
52
//---------------------------------------------------------------------------------------
59
ImoScore* GenerateScore(ScoreConstrains* pConstrains, Document* pDoc);
65
//Some helper static methods to deal with enum ETimeSignature
66
static int get_metronome_pulses_for(ETimeSignature nTimeSign);
67
static int get_top_number_for(ETimeSignature nTimeSign);
68
static int get_bottom_number_for(ETimeSignature nTimeSign);
69
static int get_num_ref_notes_per_pulse_for(ETimeSignature nTimeSign);
70
static float get_ref_note_duration_for(ETimeSignature nTimeSign);
71
static float get_measure_duration_for(ETimeSignature nTimeSign);
75
wxString CreateNoteRest(int nNoteRestDuration, bool fNote, bool fCompound, bool fFinal);
76
wxString CreateNote(int nNoteDuration, bool fCompound, bool fFinal) {
77
return CreateNoteRest(nNoteDuration, true, fCompound, fFinal);
79
wxString CreateRest(int nRestDuration, bool fCompound, bool fFinal) {
80
return CreateNoteRest(nRestDuration, false, fCompound, fFinal);
82
wxString CreateLastMeasure(int nNumMeasure, ETimeSignature nTimeSign,
83
bool fOnlyQuarterNotes);
85
// pitch related methods
86
bool InstantiateNotes(ImoScore* pScore, EKeySignature nKey, int numMeasures);
87
void InstantiateNotesRandom(ImoScore* pScore);
88
void GetRandomHarmony(int nFunctions, std::vector<long>& aFunction);
89
void FunctionToChordNotes(EKeySignature nKey, long nFunction, FPitch aNotes[4]);
90
FPitch NearestNoteOnChord(DiatonicPitch nPoint, ImoNote* pNotePrev, ImoNote* pNoteCur,
91
std::vector<FPitch>& aOnChordPitch);
93
void set_pitch(ImoNote* pNote, FPitch fp);
95
void GenerateScale(EKeySignature nKey, FPitch notes[7]);
96
FPitch GenerateInChordList(EKeySignature nKey, long nFunction,
97
std::vector<FPitch>& aValidPitch);
100
void GenerateContour(int nNumPoints, std::vector<DiatonicPitch>& nContour);
101
void ComputeTriangle(bool fUp, int iStart, int nPoints, DiatonicPitch nLowPitch,
102
DiatonicPitch nHighPitch, std::vector<DiatonicPitch>& aPoints);
103
void ComputeRamp(int iStart, int nPoints, DiatonicPitch nStartPitch,
104
DiatonicPitch nEndPitch, std::vector<DiatonicPitch>& aPoints);
105
void ComputeArch(bool fUp, int iStart, int nPoints, DiatonicPitch nLowPitch,
106
DiatonicPitch nHighPitch, std::vector<DiatonicPitch>& aPoints);
109
// pitch for non-chord notes
110
void AssignNonChordNotes(int nNumNotes, ImoNote* pOnChord1, ImoNote* pOnChord2,
111
ImoNote* pNonChord[], FPitch aScale[7]);
112
void NeightboringNotes(int nNumNotes, ImoNote* pOnChord1, ImoNote* pOnChord2,
113
ImoNote* pNonChord[], FPitch aScale[7]);
114
void PassingNotes(bool fUp, int nNumNotes, ImoNote* pOnChord1, ImoNote* pOnChord2,
115
ImoNote* pNonChord[], FPitch aScale[7]);
116
void ThirdFifthNotes(bool fUp, int nNumNotes, ImoNote* pOnChord1, ImoNote* pOnChord2,
117
ImoNote* pNonChord[], FPitch aScale[7]);
119
FPitch MoveByChromaticStep(bool fUpStep, FPitch nPitch);
120
FPitch MoveByStep(bool fUpStep, FPitch nPitch, FPitch aScale[7]);
123
void InstantiateWithNote(ImoScore* pScore, FPitch fp);
126
ETimeSignature m_nTimeSign;
127
EClefExercise m_nClef;
128
EKeySignature m_nKey;
129
ScoreConstrains* m_pConstrains;
131
//variables to control note pitch generation
132
FPitch m_fpMinPitch, m_fpMaxPitch; // the valid range of notes to generate
139
#endif // __LENMUS_COMPOSER_H__