MuseScore  3.4
Music composition and notation
pitchspelling.h
Go to the documentation of this file.
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 {
48  TPC_MAX = TPC_B_SS
49  };
50 
51 const int TPC_DELTA_SEMITONE = 7; // the delta in tpc value to go 1 semitone up or down
52 const int TPC_DELTA_ENHARMONIC = 12; // the delta in tpc value to reach the next (or prev) enharmonic spelling
53 //const int TPC_FIRST_STEP = 3; // the step of the first valid tpc (= F = step 3)
54 const int PITCH_DELTA_OCTAVE = 12; // the delta in pitch value to go 1 octave up or down
55 const int STEP_DELTA_OCTAVE = 7; // the number of steps in an octave
56 //const int STEP_DELTA_TPC = 4; // the number of steps in a tpc step (= a fifth = 4 steps)
57 
58 //---------------------------------------------------------
59 // pitch2tpc
60 // Returns a default tpc for a given midi pitch.
61 // Midi pitch 60 is middle C.
62 //---------------------------------------------------------
63 
64 // pitch2tpc(pitch) replaced by pitch2tpc(pitch, Key::C, Prefer::NEAREST)
65 
66 enum class Prefer : char { FLATS=8, NEAREST=11, SHARPS=13 };
68 enum class NoteCaseType : signed char { AUTO = -1, CAPITAL = 0, LOWER, UPPER };
69 
70 extern int pitch2tpc(int pitch, Key, Prefer prefer);
71 
72 extern int computeWindow(const std::vector<Note*>& notes, int start, int end);
73 extern int tpc(int idx, int pitch, int opt);
74 extern QString tpc2name(int tpc, NoteSpellingType spelling, NoteCaseType noteCase, bool explicitAccidental = false);
75 extern void tpc2name(int tpc, NoteSpellingType noteSpelling, NoteCaseType noteCase, QString& s, QString& acc, bool explicitAccidental = false);
76 extern void tpc2name(int tpc, NoteSpellingType noteSpelling, NoteCaseType noteCase, QString& s, int& acc);
77 extern int step2tpc(const QString& stepName, AccidentalVal alter);
78 extern int step2tpc(int step);
79 extern int step2tpc(int step, AccidentalVal alter);
80 extern int step2tpcByKey(int step, Key);
81 extern int tpc2pitch(int tpc);
82 extern int tpc2step(int tpc);
83 extern int tpc2stepByKey(int tpc, Key, int* pAlter);
84 extern int tpc2alterByKey(int tpc, Key);
85 extern int pitch2absStepByKey(int pitch, int tpc, Key, int* pAlter);
86 extern int absStep2pitchByKey(int step, Key);
87 extern int tpc2degree(int tpc, Key key);
88 
89 //---------------------------------------------------------
90 // tpc2alter
91 //---------------------------------------------------------
92 
93 inline static AccidentalVal tpc2alter(int tpc) {
94  return AccidentalVal(((tpc+1) / 7) - 2);
95  }
96 
97 extern QString tpc2stepName(int tpc);
98 extern bool tpcIsValid(int val);
99 inline bool pitchIsValid(int pitch) { return pitch >= 0 && pitch <= 127; }
100 
101 } // namespace Ms
102 #endif
103 
const int TPC_DELTA_SEMITONE
Definition: pitchspelling.h:51
AccidentalVal
Definition: mscore.h:147
Key
Definition: key.h:28
Definition: pitchspelling.h:42
QString tpc2stepName(int tpc)
Definition: pitchspelling.cpp:338
Definition: pitchspelling.h:44
const int STEP_DELTA_OCTAVE
Definition: pitchspelling.h:55
Definition: pitchspelling.h:44
Definition: pitchspelling.h:43
Definition: pitchspelling.h:46
Definition: pitchspelling.h:44
Definition: pitchspelling.h:46
Definition: pitchspelling.h:46
const int PITCH_DELTA_OCTAVE
Definition: pitchspelling.h:54
int tpc2pitch(int tpc)
Definition: pitchspelling.cpp:185
Definition: pitchspelling.h:42
int tpc2stepByKey(int tpc, Key key, int *pAlter)
Definition: pitchspelling.cpp:113
NoteCaseType
Definition: pitchspelling.h:68
int step2tpc(int step, AccidentalVal alter)
Definition: pitchspelling.cpp:42
NoteSpellingType
Definition: pitchspelling.h:67
Definition: pitchspelling.h:42
Definition: pitchspelling.h:42
Definition: pitchspelling.h:46
int tpc2degree(int tpc, Key key)
Definition: pitchspelling.cpp:799
Definition: pitchspelling.h:47
Definition: pitchspelling.h:43
bool pitchIsValid(int pitch)
Definition: pitchspelling.h:99
Definition: pitchspelling.h:45
int pitch2absStepByKey(int pitch, int tpc, Key key, int *pAlter)
Definition: pitchspelling.cpp:745
bool tpcIsValid(int val)
Definition: pitchspelling.cpp:33
Definition: aeolus.cpp:26
Definition: pitchspelling.h:42
Definition: pitchspelling.h:41
int pitch2tpc(int pitch, Key key, Prefer prefer)
Definition: pitchspelling.cpp:732
Definition: pitchspelling.h:44
Prefer
Definition: pitchspelling.h:66
Definition: pitchspelling.h:45
Definition: pitchspelling.h:43
Tpc
Definition: pitchspelling.h:40
Definition: pitchspelling.h:43
Definition: pitchspelling.h:46
Definition: pitchspelling.h:45
Definition: pitchspelling.h:46
Definition: pitchspelling.h:43
QString tpc2name(int tpc, NoteSpellingType noteSpelling, NoteCaseType noteCase, bool explicitAccidental)
Definition: pitchspelling.cpp:230
Definition: pitchspelling.h:42
Definition: pitchspelling.h:44
int tpc2step(int tpc)
Definition: pitchspelling.cpp:97
Definition: pitchspelling.h:44
const int INVALID_PITCH
Definition: pitchspelling.h:24
int step2tpcByKey(int step, Key key)
Definition: pitchspelling.cpp:82
int tpc(int idx, int pitch, int opt)
Definition: pitchspelling.cpp:539
Definition: pitchspelling.h:45
Definition: pitchspelling.h:45
int tpc2alterByKey(int tpc, Key key)
Definition: pitchspelling.cpp:221
int computeWindow(const std::vector< Note *> &notes, int start, int end)
Definition: pitchspelling.cpp:557
Definition: pitchspelling.h:43
const int TPC_DELTA_ENHARMONIC
Definition: pitchspelling.h:52
Definition: pitchspelling.h:45
Definition: pitchspelling.h:42
int absStep2pitchByKey(int step, Key key)
Definition: pitchspelling.cpp:777
Definition: pitchspelling.h:48
Definition: pitchspelling.h:46
Definition: pitchspelling.h:43
Definition: pitchspelling.h:45
Definition: pitchspelling.h:44