41 |
) { |
) { |
42 |
dmsg(4,("Engine::ContinuousController cc=%d v=%d\n", itControlChangeEvent->Param.CC.Controller, itControlChangeEvent->Param.CC.Value)); |
dmsg(4,("Engine::ContinuousController cc=%d v=%d\n", itControlChangeEvent->Param.CC.Controller, itControlChangeEvent->Param.CC.Value)); |
43 |
|
|
44 |
EngineChannel* pChannel = dynamic_cast<EngineChannel*>(pEngineChannel); |
EngineChannel* pChannel = static_cast<EngineChannel*>(pEngineChannel); |
45 |
// handle the "control triggered" MIDI rule: a control change |
// handle the "control triggered" MIDI rule: a control change |
46 |
// event can trigger a new note on or note off event |
// event can trigger a new note on or note off event |
47 |
if (pChannel->pInstrument) { |
if (pChannel->pInstrument) { |
72 |
bool HandleKeyGroupConflicts |
bool HandleKeyGroupConflicts |
73 |
) { |
) { |
74 |
EngineChannel* pChannel = static_cast<EngineChannel*>(pEngineChannel); |
EngineChannel* pChannel = static_cast<EngineChannel*>(pEngineChannel); |
75 |
|
::sfz::Query q; |
76 |
uint8_t chan = pChannel->MidiChannel(); |
q.chan = pChannel->MidiChannel(); |
77 |
int key = itNoteOnEvent->Param.Note.Key; |
q.key = itNoteOnEvent->Param.Note.Key; |
78 |
uint8_t vel = itNoteOnEvent->Param.Note.Velocity; |
q.vel = itNoteOnEvent->Param.Note.Velocity; |
79 |
int bend = pChannel->Pitch; |
q.bend = pChannel->Pitch; |
80 |
uint8_t chanaft = pChannel->ControllerTable[128]; |
q.bpm = 0; |
81 |
uint8_t* cc = pChannel->ControllerTable; |
q.chanaft = pChannel->ControllerTable[128]; |
82 |
::sfz::trigger_t trig = TRIGGER_ATTACK | |
q.polyaft = 0; |
83 |
((pChannel->LastKey != -1 && |
q.prog = 0; |
84 |
pChannel->PressedKeys[pChannel->LastKey] && |
q.rand = Random(); |
85 |
pChannel->LastKey != key) ? |
q.cc = pChannel->ControllerTable; |
86 |
TRIGGER_LEGATO : TRIGGER_FIRST); |
q.timer = 0; |
87 |
|
q.sw = pChannel->PressedKeys; |
88 |
pChannel->regionsTemp = pChannel->pInstrument->GetRegionsOnKey ( |
q.last_sw_key = pChannel->LastKeySwitch; |
89 |
chan, key, vel, bend, 0, chanaft, 0, 0, Random(), trig, cc, |
q.prev_sw_key = pChannel->LastKey; |
90 |
0.0f, pChannel->PressedKeys, pChannel->LastKeySwitch, pChannel->LastKey |
q.trig = TRIGGER_ATTACK | |
91 |
); |
((pChannel->LastKey != -1 && |
92 |
|
pChannel->PressedKeys[pChannel->LastKey] && |
93 |
for (int i = 0; i < pChannel->regionsTemp.size(); i++) { |
pChannel->LastKey != q.key) ? |
94 |
if (!RegionSuspended(pChannel->regionsTemp[i])) { |
TRIGGER_LEGATO : TRIGGER_FIRST); |
95 |
|
|
96 |
|
q.search(pChannel->pInstrument); |
97 |
|
|
98 |
|
int i = 0; |
99 |
|
while (::sfz::Region* region = q.next()) { |
100 |
|
if (!RegionSuspended(region)) { |
101 |
|
itNoteOnEvent->Param.Note.pRegion = region; |
102 |
LaunchVoice(pChannel, itNoteOnEvent, i, false, true, HandleKeyGroupConflicts); |
LaunchVoice(pChannel, itNoteOnEvent, i, false, true, HandleKeyGroupConflicts); |
103 |
} |
} |
104 |
|
i++; |
105 |
} |
} |
106 |
} |
} |
107 |
|
|
110 |
RTList<Event>::Iterator& itNoteOffEvent |
RTList<Event>::Iterator& itNoteOffEvent |
111 |
) { |
) { |
112 |
EngineChannel* pChannel = static_cast<EngineChannel*>(pEngineChannel); |
EngineChannel* pChannel = static_cast<EngineChannel*>(pEngineChannel); |
113 |
uint8_t chan = pChannel->MidiChannel(); |
::sfz::Query q; |
114 |
int key = itNoteOffEvent->Param.Note.Key; |
q.chan = pChannel->MidiChannel(); |
115 |
|
q.key = itNoteOffEvent->Param.Note.Key; |
116 |
|
|
117 |
// MIDI note-on velocity is used instead of note-off velocity |
// MIDI note-on velocity is used instead of note-off velocity |
118 |
uint8_t vel = pChannel->pMIDIKeyInfo[key].Velocity; |
q.vel = pChannel->pMIDIKeyInfo[q.key].Velocity; |
119 |
itNoteOffEvent->Param.Note.Velocity = vel; |
itNoteOffEvent->Param.Note.Velocity = q.vel; |
120 |
|
|
121 |
int bend = pChannel->Pitch; |
q.bend = pChannel->Pitch; |
122 |
uint8_t chanaft = pChannel->ControllerTable[128]; |
q.bpm = 0; |
123 |
uint8_t* cc = pChannel->ControllerTable; |
q.chanaft = pChannel->ControllerTable[128]; |
124 |
::sfz::trigger_t trig = TRIGGER_RELEASE; |
q.polyaft = 0; |
125 |
|
q.prog = 0; |
126 |
pChannel->regionsTemp = pChannel->pInstrument->GetRegionsOnKey ( |
q.rand = Random(); |
127 |
chan, key, vel, bend, 0, chanaft, 0, 0, Random(), trig, cc, |
q.cc = pChannel->ControllerTable; |
128 |
0.0f, pChannel->PressedKeys, pChannel->LastKeySwitch, pChannel->LastKey |
q.timer = 0; |
129 |
); |
q.sw = pChannel->PressedKeys; |
130 |
|
q.last_sw_key = pChannel->LastKeySwitch; |
131 |
|
q.prev_sw_key = pChannel->LastKey; |
132 |
|
q.trig = TRIGGER_RELEASE; |
133 |
|
|
134 |
|
q.search(pChannel->pInstrument); |
135 |
|
|
136 |
// now launch the required amount of voices |
// now launch the required amount of voices |
137 |
for (int i = 0; i < pChannel->regionsTemp.size(); i++) { |
int i = 0; |
138 |
LaunchVoice(pChannel, itNoteOffEvent, i, true, false, false); //FIXME: for the moment we don't perform voice stealing for release triggered samples |
while (::sfz::Region* region = q.next()) { |
139 |
|
itNoteOffEvent->Param.Note.pRegion = region; |
140 |
|
LaunchVoice(pChannel, itNoteOffEvent, i, true, false, true); //FIXME: for the moment we don't perform voice stealing for release triggered samples |
141 |
|
i++; |
142 |
} |
} |
143 |
} |
} |
144 |
|
|
156 |
Voice::type_t VoiceType = (ReleaseTriggerVoice) ? Voice::type_release_trigger : (!iLayer) ? Voice::type_release_trigger_required : Voice::type_normal; |
Voice::type_t VoiceType = (ReleaseTriggerVoice) ? Voice::type_release_trigger : (!iLayer) ? Voice::type_release_trigger_required : Voice::type_normal; |
157 |
|
|
158 |
Pool<Voice>::Iterator itNewVoice; |
Pool<Voice>::Iterator itNewVoice; |
159 |
::sfz::Region* pRgn = pChannel->regionsTemp[iLayer]; |
::sfz::Region* pRgn = static_cast< ::sfz::Region*>(itNoteOnEvent->Param.Note.pRegion); |
160 |
|
|
161 |
// no need to process if sample is silent |
// no need to process if sample is silent |
162 |
if (!pRgn->GetSample() || !pRgn->GetSample()->GetTotalFrameCount()) return Pool<Voice>::Iterator(); |
if (!pRgn->GetSample() || !pRgn->GetSample()->GetTotalFrameCount()) return Pool<Voice>::Iterator(); |
163 |
|
|
164 |
// only mark the first voice of a layered voice (group) to be in a |
if (HandleKeyGroupConflicts) pChannel->HandleKeyGroupConflicts(pRgn->group, itNoteOnEvent); |
|
// key group, so the layered voices won't kill each other |
|
|
int iKeyGroup = (iLayer == 0 && !ReleaseTriggerVoice) ? pRgn->group : 0; |
|
|
if (HandleKeyGroupConflicts) pChannel->HandleKeyGroupConflicts(iKeyGroup, itNoteOnEvent, pRgn->off_mode == ::sfz::OFF_NORMAL); |
|
165 |
|
|
166 |
// allocate a new voice for the key |
// allocate a new voice for the key |
167 |
itNewVoice = pKey->pActiveVoices->allocAppend(); |
itNewVoice = pKey->pActiveVoices->allocAppend(); |
168 |
int res = InitNewVoice ( |
int res = InitNewVoice ( |
169 |
pChannel, pRgn, itNoteOnEvent, VoiceType, iLayer, |
pChannel, pRgn, itNoteOnEvent, VoiceType, iLayer, |
170 |
iKeyGroup, ReleaseTriggerVoice, VoiceStealing, itNewVoice |
pRgn->off_by, ReleaseTriggerVoice, VoiceStealing, itNewVoice |
171 |
); |
); |
172 |
if (!res) return itNewVoice; |
if (!res) return itNewVoice; |
173 |
|
|
188 |
} |
} |
189 |
|
|
190 |
String Engine::Version() { |
String Engine::Version() { |
191 |
String s = "$Revision: 1.7 $"; |
String s = "$Revision: 1.10 $"; |
192 |
return s.substr(11, s.size() - 13); // cut dollar signs, spaces and CVS macro keyword |
return s.substr(11, s.size() - 13); // cut dollar signs, spaces and CVS macro keyword |
193 |
} |
} |
194 |
|
|