~s-cecilio/lenmus/v5.3

« back to all changes in this revision

Viewing changes to include/lenmus_composer.h

  • Committer: cecilios
  • Date: 2007-05-19 11:39:03 UTC
  • Revision ID: svn-v4:2587a929-2f0e-0410-ae78-fe6f687d5efe:trunk:236

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//---------------------------------------------------------------------------------------
2
 
//    LenMus Phonascus: The teacher of music
3
 
//    Copyright (c) 2002-2012 LenMus project
4
 
//
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.
8
 
//
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.
12
 
//
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/>.
15
 
//
16
 
//    For any comment, suggestion or feature request, please contact the manager of
17
 
//    the project at cecilios@users.sourceforge.net
18
 
//
19
 
//---------------------------------------------------------------------------------------
20
 
 
21
 
#ifndef __LENMUS_COMPOSER_H__        //to avoid nested includes
22
 
#define __LENMUS_COMPOSER_H__
23
 
 
24
 
//lenmus
25
 
#include "lenmus_standard_header.h"
26
 
#include "lenmus_scores_constrains.h"
27
 
 
28
 
//lomse
29
 
#include <lomse_internal_model.h>
30
 
#include <lomse_document.h>
31
 
#include <lomse_pitch.h>
32
 
using namespace lomse;
33
 
 
34
 
//wxWidgets
35
 
#include <wx/wxprec.h>
36
 
#include <wx/wx.h>
37
 
 
38
 
//other
39
 
#include "vector"
40
 
 
41
 
 
42
 
namespace lenmus
43
 
{
44
 
 
45
 
//forward declarations
46
 
class ScoreConstrains;
47
 
 
48
 
// symbolic names for bool fUpStep
49
 
#define k_down      false
50
 
#define k_up        true
51
 
 
52
 
//---------------------------------------------------------------------------------------
53
 
class Composer
54
 
{
55
 
public:
56
 
    Composer();
57
 
    ~Composer();
58
 
 
59
 
    ImoScore* GenerateScore(ScoreConstrains* pConstrains, Document* pDoc);
60
 
 
61
 
 
62
 
 
63
 
private:
64
 
 
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);
72
 
 
73
 
    void GetNotesRange();
74
 
 
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);
78
 
    }
79
 
    wxString CreateRest(int nRestDuration, bool fCompound, bool fFinal) {
80
 
        return CreateNoteRest(nRestDuration, false, fCompound, fFinal);
81
 
    }
82
 
    wxString CreateLastMeasure(int nNumMeasure, ETimeSignature nTimeSign,
83
 
                             bool fOnlyQuarterNotes);
84
 
 
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);
92
 
    FPitch RandomPitch();
93
 
    void set_pitch(ImoNote* pNote, FPitch fp);
94
 
 
95
 
    void GenerateScale(EKeySignature nKey, FPitch notes[7]);
96
 
    FPitch GenerateInChordList(EKeySignature nKey, long nFunction,
97
 
                               std::vector<FPitch>& aValidPitch);
98
 
 
99
 
        // contour
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);
107
 
 
108
 
 
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]);
118
 
 
119
 
    FPitch MoveByChromaticStep(bool fUpStep, FPitch nPitch);
120
 
    FPitch MoveByStep(bool fUpStep, FPitch nPitch, FPitch aScale[7]);
121
 
 
122
 
    //debug
123
 
    void InstantiateWithNote(ImoScore* pScore, FPitch fp);
124
 
 
125
 
 
126
 
    ETimeSignature      m_nTimeSign;
127
 
    EClefExercise       m_nClef;
128
 
    EKeySignature       m_nKey;
129
 
    ScoreConstrains*    m_pConstrains;
130
 
 
131
 
    //variables to control note pitch generation
132
 
    FPitch      m_fpMinPitch, m_fpMaxPitch;   // the valid range of notes to generate
133
 
 
134
 
};
135
 
 
136
 
 
137
 
}   //namespace lenmus
138
 
 
139
 
#endif    // __LENMUS_COMPOSER_H__