CLAM-Development
1.4.0
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
src
Processing
Controls
ControlPiano.hxx
Go to the documentation of this file.
1
/*
2
*
3
*
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
8
*
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
*
18
*/
19
20
#ifndef _ControlPiano_
21
#define _ControlPiano_
22
23
#include "
Processing.hxx
"
24
#include "
InControl.hxx
"
25
#include "
OutControl.hxx
"
26
27
#include "
MIDIMessage.hxx
"
28
29
namespace
CLAM
30
{
31
32
class
ControlPiano
:
public
Processing
33
{
34
public
:
35
const
char
*
GetClassName
()
const
{
return
"ControlPiano"
; }
36
37
protected
:
39
InControl< MIDI::Message >
mInputMIDIMessage
;
40
OutControl< MIDI::Message >
mOutputMIDIMessage
;
41
42
public
:
43
44
ControlPiano
(
const
Config
& config=
Config
())
45
:
46
mInputMIDIMessage
(
"MIDI Message In"
, this, &
ControlPiano
::
DoCallback
),
47
mOutputMIDIMessage
(
"MIDI Message Out"
, this)
48
{
49
Configure
( config );
50
51
_notes
.resize(12);
// one octave
52
for
(
unsigned
int
i=0;i<
_notes
.size();i++) {
_notes
[i]=
false
; }
53
54
_velocity
= 90;
// fixed velocity. TODO: add it as a processing configuration parameter.
55
_octave
= 4;
// fixed octave (C4). TODO: add it as a processing configuration parameter.
56
}
57
58
~ControlPiano
()
59
{
60
}
61
62
bool
Do
() {
return
true
; }
63
64
void
DoCallback
(
const
MIDI::Message
& inMessage)
65
{
66
MIDI::Message
message = inMessage;
67
68
mOutputMIDIMessage
.
SendControl
(message);
//delivers the same input message to the output
69
70
MIDI::Message
voidMessage;
71
if
(message==voidMessage)
return
;
72
73
if
(message[1]>=21 && message[1]<=108)
74
{
75
if
(message[0]==144)
//note on
76
{
77
_notes
[(message[1]-21)%12]=
true
;
78
}
79
else
if
(message[0]==128)
//note off
80
{
81
_notes
[(message[1]-21)%12]=
false
;
82
}
83
}
84
};
85
86
void
SendMIDIMessage
(
MIDI::Message
&msg)
87
{
88
mOutputMIDIMessage
.
SendControl
(msg);
89
}
90
91
void
SetNoteStatus
(
TSize
i,
bool
state)
92
{
93
_notes
[i] = state;
94
}
95
96
bool
GetNoteStatus
(
TSize
i)
97
{
98
return
_notes
[i];
99
}
100
101
TSize
GetVelocity
()
102
{
103
return
_velocity
;
104
}
105
106
TSize
GetOctave
()
107
{
108
return
_octave
;
109
}
110
111
protected
:
112
std::vector<bool>
_notes
;
113
TSize
_velocity
;
114
TSize
_octave
;
115
};
116
117
}
118
119
#endif
Generated by
1.8.1