forked from kbinani/libvsq
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNoteNumberUtil.hpp
More file actions
86 lines (79 loc) · 1.99 KB
/
NoteNumberUtil.hpp
File metadata and controls
86 lines (79 loc) · 1.99 KB
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
/**
* NoteNumberUtil.h
* Copyright © 2012 kbinani
*
* This file is part of libvsq.
*
* libvsq is free software; you can redistribute it and/or
* modify it under the terms of the BSD License.
*
* libvsq is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
#ifndef __NoteNumberUtil_hpp__
#include "vsqglobal.hpp"
#include <string>
VSQ_BEGIN_NAMESPACE
class NoteNumberUtil{
public:
/**
* @brief ノートのオクターブ,変化記号を除いた部分の文字列表記を調べます.
* 例:C4 => "C", D#4 => "D"
* @param note ノート番号
*/
static std::string getNoteStringBase( int note ){
int odd = note % 12;
switch ( odd ) {
case 0:
case 1:{
return "C";
}
case 2:{
return "D";
}
case 3:
case 4:{
return "E";
}
case 5:
case 6:{
return "F";
}
case 7:
case 8:{
return "G";
}
case 9:{
return "A";
}
case 10:
case 11:{
return "B";
}
default:{
return "";
}
}
}
/**
* @brief ノート#のオクターブ部分の表記を調べます.
* 例:C4 => 4, D#4 => 4
* @param note ノート番号
*/
static int getNoteOctave( int note ){
int odd = note % 12;
return (note - odd) / 12 - 2;
}
/**
* @brief C#4なら+1, C4なら0, Cb4なら-1
* @param note ノート番号
*/
static int getNoteAlter( int note ){
static int ALTER[13] = { 0, 1, 0, -1, 0, 0, 1, 0, 1, 0, -1, 0, 0 };
note = note % 12 + 12;
return ALTER[note % 12];
}
};
VSQ_END_NAMESPACE
#endif