CLAM-Development
1.4.0
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
src
Processing
MIDIIO
MIDI2Melody.cxx
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2001-2004 MUSIC TECHNOLOGY GROUP (MTG)
3
* UNIVERSITAT POMPEU FABRA
4
*
5
*
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
10
*
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
*
20
*/
21
22
#include "
MIDI2Melody.hxx
"
23
24
namespace
CLAM {
25
26
MIDI2Melody::MIDI2Melody
()
27
: mOutput(
"Output"
,this),
28
mTime(
"time"
,this)
29
{
30
ConcreteConfigure
(
Control2DataConfig
());
31
}
32
33
bool
MIDI2Melody::GenerateOutputData
(
int
id
,
TControlData
val)
34
{
35
switch
(
id
)
36
{
37
case
0:
//key for note off
38
{
39
//find the note with that key in the member buffers, remove it, add it to melody after computing duration
40
int
index,velocity,beginTime,endTime;
41
index=
FindNote
(
int
(val));
42
if
(index==-1)
break
;
//I don't know why this happens but it does
43
velocity=(
int
)
mVelocities
[index];
44
beginTime=(
int
)
mBeginTimes
[index];
45
endTime=(
int
)
mTime
.
GetLastValue
();
46
DeleteNoteFromIndex
(index);
47
48
MIDINote
newNote;
49
newNote.SetKey(
int
(val));
//should be MidiNote!
50
newNote.SetVelocity(velocity);
//should be MidiVelocity
51
MediaTime
time;
52
time.AddBegin();
53
time.AddEnd();
54
time.RemoveDuration();
55
time.
UpdateData
();
56
time.SetBegin(beginTime);
57
time.SetEnd(endTime);
58
newNote.SetTime(time);
59
mOutput
.
GetData
().GetNoteArray().AddElem(newNote);
60
61
break
;
62
}
63
case
1:
//velocity for note off
64
{
65
//for the time being this will not be acknowledged
66
break
;
67
}
68
case
2:
//key for note on
69
{
70
//add note to member array with velocity 0 and modify mLastKey
71
AddNote
(
int
(val),0,
int
(
mTime
.
GetLastValue
()));
72
mLastKey
=
int
(val);
73
break
;
74
}
75
case
3:
//velocity for note on
76
{
77
//Modify velocity for mLastKey
78
ModifyVelocity
(
mLastKey
,
int
(val));
79
break
;
80
}
81
default
:
82
{
83
CLAM_ASSERT
(
false
,
"Not a valid MIDI control"
);
84
}
85
}
86
return
true
;
87
}
88
89
90
bool
MIDI2Melody::ConcreteConfigure
(
const
ProcessingConfig
& c)
91
{
92
//Ugly, ugly. Don't try this at home.
93
Control2DataConfig
&tmp=
const_cast<
Control2DataConfig
&
>
(
dynamic_cast<
const
Control2DataConfig
&
>
(c));
94
//We harcode this value as the concrete MIDI2Melody now will only work on 4 controls
95
tmp.SetNumControls(4);
96
Control2Data::ConcreteConfigure
(tmp);
97
return
true
;
98
}
99
100
int
MIDI2Melody::FindNote
(
int
key)
101
{
102
int
index=-1;
103
int
i;
104
for
(i=0;i<
mKeys
.
Size
();i++)
105
{
106
if
(
mKeys
[i]==key){
107
index=i;
108
break
;
109
}
110
}
111
return
index;
112
}
113
114
void
MIDI2Melody::AddNote
(
int
key,
int
velocity,
int
time)
115
{
116
mKeys
.
AddElem
(key);
117
mVelocities
.
AddElem
(velocity);
118
mBeginTimes
.
AddElem
(time);
119
}
120
121
void
MIDI2Melody::DeleteNote
(
int
key)
122
{
123
DeleteNoteFromIndex
(
FindNote
(key));
124
}
125
126
void
MIDI2Melody::DeleteNoteFromIndex
(
int
index)
127
{
128
mKeys
.
DeleteElem
(index);
129
mVelocities
.
DeleteElem
(index);
130
mBeginTimes
.
DeleteElem
(index);
131
}
132
133
void
MIDI2Melody::ModifyVelocity
(
int
key,
int
newVelocity)
134
{
135
int
index=
FindNote
(key);
136
mVelocities
[index]=newVelocity;
137
}
138
139
}
// namespace CLAM
140
Generated by
1.8.1