Diffstat (limited to 'noncore/multimedia/tonleiter/tonleiterdatahelper.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/multimedia/tonleiter/tonleiterdatahelper.cpp | 133 |
1 files changed, 133 insertions, 0 deletions
diff --git a/noncore/multimedia/tonleiter/tonleiterdatahelper.cpp b/noncore/multimedia/tonleiter/tonleiterdatahelper.cpp new file mode 100644 index 0000000..6b8a5bd --- a/dev/null +++ b/noncore/multimedia/tonleiter/tonleiterdatahelper.cpp | |||
@@ -0,0 +1,133 @@ | |||
1 | #include "tonleiterdatahelper.h" | ||
2 | |||
3 | int Note::getOctaveOfNote(int note) | ||
4 | { | ||
5 | int remain=note%12; | ||
6 | return (note-remain)/12; | ||
7 | } | ||
8 | //**************************************************************************** | ||
9 | QString Note::getNameOfNote(int note) | ||
10 | { | ||
11 | int octave=getOctaveOfNote(note); | ||
12 | return notenames[note-12*octave]; | ||
13 | } | ||
14 | //**************************************************************************** | ||
15 | int Note::getNoteFromName(QString name,int octave) | ||
16 | { | ||
17 | int notevalue=0; | ||
18 | for(int a=0;a<12;a++) | ||
19 | { | ||
20 | if(name==notenames[a]) | ||
21 | { | ||
22 | notevalue=a; | ||
23 | break; | ||
24 | } | ||
25 | } | ||
26 | return notevalue+12*octave; | ||
27 | } | ||
28 | //**************************************************************************** | ||
29 | int Note::octaveOfBaseNote(int base,int note) | ||
30 | { | ||
31 | int normnote = (note>=base) ? note-base : (12-base)+note; | ||
32 | int octave=getOctaveOfNote(normnote); | ||
33 | //qDebug("note %d of %d base is norm %d -> ocatve %d",note,base,normnote,octave); | ||
34 | return octave; | ||
35 | } | ||
36 | //**************************************************************************** | ||
37 | //**************************************************************************** | ||
38 | Instrument::Instrument() | ||
39 | { | ||
40 | name="UNDEFINED"; | ||
41 | frets=0; | ||
42 | } | ||
43 | //**************************************************************************** | ||
44 | Instrument::Instrument(QString name,int frets,QValueList<int> strings) | ||
45 | :name(name),frets(frets),strings(strings) | ||
46 | { | ||
47 | } | ||
48 | //**************************************************************************** | ||
49 | Instrument::~Instrument() | ||
50 | { | ||
51 | } | ||
52 | //**************************************************************************** | ||
53 | int Instrument::noOfStrings() | ||
54 | { | ||
55 | return (int)strings.count(); | ||
56 | } | ||
57 | //**************************************************************************** | ||
58 | int Instrument::noOfFrets() | ||
59 | { | ||
60 | return frets; | ||
61 | } | ||
62 | //**************************************************************************** | ||
63 | QString Instrument::instName() | ||
64 | { | ||
65 | return name; | ||
66 | } | ||
67 | //**************************************************************************** | ||
68 | int Instrument::string(int id) | ||
69 | { | ||
70 | return strings[id]; | ||
71 | } | ||
72 | //**************************************************************************** | ||
73 | int Instrument::noOfOctaves() | ||
74 | { | ||
75 | int lowest=strings[0]; | ||
76 | int highest=strings[strings.count()-1]+frets; | ||
77 | return (int)((highest-lowest)/12.0); | ||
78 | } | ||
79 | //**************************************************************************** | ||
80 | //**************************************************************************** | ||
81 | Scale::Scale() | ||
82 | { | ||
83 | name="UNDEFINED"; | ||
84 | } | ||
85 | //**************************************************************************** | ||
86 | Scale::Scale(QString name,QValueList<int> halftones) | ||
87 | :name(name),halftones(halftones) | ||
88 | { | ||
89 | } | ||
90 | //**************************************************************************** | ||
91 | Scale::~Scale() | ||
92 | { | ||
93 | } | ||
94 | //**************************************************************************** | ||
95 | int Scale::noOfHaltones() | ||
96 | { | ||
97 | return (int)halftones.count(); | ||
98 | } | ||
99 | //**************************************************************************** | ||
100 | int Scale::getHalfTone(int id) | ||
101 | { | ||
102 | if(id>=0 && noOfHaltones()<id) | ||
103 | { | ||
104 | return halftones[id]; | ||
105 | } | ||
106 | else | ||
107 | return 0; | ||
108 | } | ||
109 | //**************************************************************************** | ||
110 | QString Scale::scaleName() | ||
111 | { | ||
112 | return name; | ||
113 | } | ||
114 | //**************************************************************************** | ||
115 | bool Scale::noteInScale(int base,int note) | ||
116 | { | ||
117 | int octave=Note::getOctaveOfNote(note); | ||
118 | note-=12*octave; | ||
119 | int normnote = (note>=base) ? note-base : (12-base)+note; | ||
120 | |||
121 | if(halftones.contains(normnote)>0) | ||
122 | { | ||
123 | //qDebug("OK : base : %d, note %d -> norm %d",base,note,normnote); | ||
124 | return true; | ||
125 | } | ||
126 | else | ||
127 | { | ||
128 | //qDebug("BAD : base : %d, note %d -> norm %d",base,note,normnote); | ||
129 | return false; | ||
130 | } | ||
131 | } | ||
132 | //**************************************************************************** | ||
133 | //**************************************************************************** | ||