summaryrefslogtreecommitdiff
path: root/noncore/multimedia/tonleiter/tonleiterdatahelper.cpp
blob: 156dba596c432ac6de9b5e95bc559e65eb98449b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include "tonleiterdatahelper.h"

#include <math.h>

using namespace Data;

int Note::getOctaveOfNote(int note)
{
    int remain=note%12;
    return (note-remain)/12;
}
//****************************************************************************
QString Note::getNameOfNote(int note)
{
    int octave=getOctaveOfNote(note);
    return notenames[note-12*octave];
}
//****************************************************************************
int Note::getNoteFromName(QString name,int octave)
{
    int notevalue=0;
    for(int a=0;a<12;a++)
    {
        if(name==notenames[a])
        {
            notevalue=a;
            break;
        }
    }
    return notevalue+12*octave;
}
//****************************************************************************
int Note::octaveOfBaseNote(int base,int note)
{
    int normnote = (note>=base) ? note-base : (12-base)+note;
    int octave=getOctaveOfNote(normnote);
    //qDebug("note %d of %d base is norm %d -> ocatve %d",note,base,normnote,octave);
    return octave;
}
//****************************************************************************
//****************************************************************************
Instrument::Instrument()
{
    name="UNDEFINED";
    frets=0;
}
//****************************************************************************
Instrument::Instrument(QString name,int frets,QValueList<int> strings)
:name(name),frets(frets),strings(strings)
{
}
//****************************************************************************
Instrument::~Instrument()
{
}
//****************************************************************************
int Instrument::noOfStrings()
{
    return (int)strings.count();
}
//****************************************************************************
int Instrument::noOfFrets()
{
    return frets;
}
//****************************************************************************
QString Instrument::instName()
{
    return name;
}
//****************************************************************************
int Instrument::string(int id)
{
    return strings[id];
}
//****************************************************************************
int Instrument::noOfOctaves()
{
    int lowest=strings[0];
    int highest=strings[strings.count()-1]+frets;
    return (int) ceil((highest-lowest)/12.0);
}
//****************************************************************************
//****************************************************************************
Scale::Scale()
{
    name="UNDEFINED";
}
//****************************************************************************
Scale::Scale(QString name,QValueList<int> halftones)
:name(name),halftones(halftones)
{
}
//****************************************************************************
Scale::~Scale()
{
}
//****************************************************************************
int Scale::noOfHaltones()
{
    return (int)halftones.count();
}
//****************************************************************************
int Scale::getHalfTone(int id)
{
    if(id>=0 && id<noOfHaltones())
        return halftones[id];
    else
        return 0;
}
//****************************************************************************
QString Scale::scaleName()
{
    return name;
}
//****************************************************************************
bool Scale::noteInScale(int base,int note)
{
    int octave=Note::getOctaveOfNote(note);
    note-=12*octave;
    int normnote = (note>=base) ? note-base : (12-base)+note;

    if(halftones.contains(normnote)>0)
    {
        //qDebug("OK : base : %d, note %d -> norm %d",base,note,normnote);
        return true;
    }
    else
    {
        //qDebug("BAD : base : %d, note %d -> norm %d",base,note,normnote);
        return false;
    }
}
//****************************************************************************
//****************************************************************************