1 //=============================================================================
2 // MuseScore
3 // Music Composition & Notation
4 //
5 // Copyright (C) 2002-2011 Werner Schweer
6 //
7 // This program is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License version 2
9 // as published by the Free Software Foundation and appearing in
10 // the file LICENCE.GPL
11 //=============================================================================
12
13 #ifndef __PITCHSPELLING_H__
14 #define __PITCHSPELLING_H__
15
16 #include "mscore.h"
17
18 namespace Ms {
19
20 class MidiNote;
21 class Note;
22 enum class Key;
23
24 const int INVALID_PITCH = -1;
25
26 #if 0
27 enum {
28 STEP_NONE = -1,
29 STEP_C,
30 STEP_D,
31 STEP_E,
32 STEP_F,
33 STEP_G,
34 STEP_A,
35 STEP_B
36 };
37 #endif
38
39 // a list of tpc's, with legal ranges, not really an enum, so no way to cnvert into a class
40 enum Tpc : signed char {
41 TPC_INVALID = -9,
42 TPC_F_BBB, TPC_C_BBB, TPC_G_BBB, TPC_D_BBB, TPC_A_BBB, TPC_E_BBB, TPC_B_BBB,
43 TPC_F_BB, TPC_C_BB, TPC_G_BB, TPC_D_BB, TPC_A_BB, TPC_E_BB, TPC_B_BB,
44 TPC_F_B, TPC_C_B, TPC_G_B, TPC_D_B, TPC_A_B, TPC_E_B, TPC_B_B,
45 TPC_F, TPC_C, TPC_G, TPC_D, TPC_A, TPC_E, TPC_B,
46 TPC_F_S, TPC_C_S, TPC_G_S, TPC_D_S, TPC_A_S, TPC_E_S, TPC_B_S,
47 TPC_F_SS, TPC_C_SS, TPC_G_SS, TPC_D_SS, TPC_A_SS, TPC_E_SS, TPC_B_SS,
48 TPC_F_SSS, TPC_C_SSS, TPC_G_SSS, TPC_D_SSS, TPC_A_SSS, TPC_E_SSS, TPC_B_SSS,
49 TPC_MIN = TPC_F_BBB,
50 TPC_MAX = TPC_B_SSS
51 };
52
53 const int TPC_DELTA_SEMITONE = 7; // the delta in tpc value to go 1 semitone up or down
54 const int TPC_DELTA_ENHARMONIC = 12; // the delta in tpc value to reach the next (or prev) enharmonic spelling
55 //const int TPC_FIRST_STEP = 3; // the step of the first valid tpc (= F = step 3)
56 const int PITCH_DELTA_OCTAVE = 12; // the delta in pitch value to go 1 octave up or down
57 const int STEP_DELTA_OCTAVE = 7; // the number of steps in an octave
58 //const int STEP_DELTA_TPC = 4; // the number of steps in a tpc step (= a fifth = 4 steps)
59 const int TPCS_PER_STEP = (Tpc::TPC_MAX - Tpc::TPC_MIN + 1) / STEP_DELTA_OCTAVE;
60
61 //---------------------------------------------------------
62 // pitch2tpc
63 // Returns a default tpc for a given midi pitch.
64 // Midi pitch 60 is middle C.
65 //---------------------------------------------------------
66
67 // pitch2tpc(pitch) replaced by pitch2tpc(pitch, Key::C, Prefer::NEAREST)
68
69 enum class Prefer : char { FLATS=8, NEAREST=11, SHARPS=13 };
70 enum class NoteSpellingType : char { STANDARD = 0, GERMAN, GERMAN_PURE, SOLFEGGIO, FRENCH };
71 enum class NoteCaseType : signed char { AUTO = -1, CAPITAL = 0, LOWER, UPPER };
72
73 extern int pitch2tpc(int pitch, Key, Prefer prefer);
74
75 extern int computeWindow(const std::vector<Note*>& notes, int start, int end);
76 extern int tpc(int idx, int pitch, int opt);
77 extern QString tpc2name(int tpc, NoteSpellingType spelling, NoteCaseType noteCase, bool explicitAccidental = false);
78 extern void tpc2name(int tpc, NoteSpellingType noteSpelling, NoteCaseType noteCase, QString& s, QString& acc, bool explicitAccidental = false);
79 extern void tpc2name(int tpc, NoteSpellingType noteSpelling, NoteCaseType noteCase, QString& s, AccidentalVal& acc);
80 extern int step2tpc(const QString& stepName, AccidentalVal alter);
81 extern int step2tpc(int step);
82 extern int step2tpc(int step, AccidentalVal alter);
83 extern int step2tpcByKey(int step, Key);
84 extern int tpc2pitch(int tpc);
85 extern int tpc2step(int tpc);
86 extern int tpc2stepByKey(int tpc, Key, int& alter);
87 extern int tpc2alterByKey(int tpc, Key);
88 extern int pitch2absStepByKey(int pitch, int tpc, Key, int& alter);
89 extern int absStep2pitchByKey(int step, Key);
90 extern int tpc2degree(int tpc, Key key);
91 extern int tpcInterval(int startTpc, int interval, int alter);
92 extern int step2pitchInterval(int step, int alter);
93 extern int function2Tpc(const QString& s, Key key);
94
95 //---------------------------------------------------------
96 // tpc2alter
97 //---------------------------------------------------------
98
tpc2alter(int tpc)99 inline static AccidentalVal tpc2alter(int tpc) {
100 return AccidentalVal(((tpc - Tpc::TPC_MIN) / TPC_DELTA_SEMITONE) + int(AccidentalVal::MIN));
101 }
102
103 extern QString tpc2stepName(int tpc);
104 extern bool tpcIsValid(int val);
pitchIsValid(int pitch)105 inline bool pitchIsValid(int pitch) { return pitch >= 0 && pitch <= 127; }
106
107 } // namespace Ms
108 #endif
109
110