4 |
* * |
* * |
5 |
* Copyright (C) 2003,2004 by Benno Senoner and Christian Schoenebeck * |
* Copyright (C) 2003,2004 by Benno Senoner and Christian Schoenebeck * |
6 |
* Copyright (C) 2005-2008 Christian Schoenebeck * |
* Copyright (C) 2005-2008 Christian Schoenebeck * |
7 |
* Copyright (C) 2009-2010 Christian Schoenebeck and Grigor Iliev * |
* Copyright (C) 2009-2012 Christian Schoenebeck and Grigor Iliev * |
8 |
* * |
* * |
9 |
* This program is free software; you can redistribute it and/or modify * |
* This program is free software; you can redistribute it and/or modify * |
10 |
* it under the terms of the GNU General Public License as published by * |
* it under the terms of the GNU General Public License as published by * |
112 |
Pitch = 0; |
Pitch = 0; |
113 |
GlobalVolume = 1.0f; |
GlobalVolume = 1.0f; |
114 |
MidiVolume = 1.0; |
MidiVolume = 1.0; |
|
GlobalPanLeft = 1.0f; |
|
|
GlobalPanRight = 1.0f; |
|
115 |
iLastPanRequest = 64; |
iLastPanRequest = 64; |
116 |
GlobalTranspose = 0; |
GlobalTranspose = 0; |
117 |
// set all MIDI controller values to zero |
// set all MIDI controller values to zero |
180 |
int iMidiPan = int(f * 64.0f) + 64; |
int iMidiPan = int(f * 64.0f) + 64; |
181 |
if (iMidiPan > 127) iMidiPan = 127; |
if (iMidiPan > 127) iMidiPan = 127; |
182 |
else if (iMidiPan < 0) iMidiPan = 0; |
else if (iMidiPan < 0) iMidiPan = 0; |
|
GlobalPanLeft = AbstractEngine::PanCurve[128 - iMidiPan]; |
|
|
GlobalPanRight = AbstractEngine::PanCurve[iMidiPan]; |
|
183 |
iLastPanRequest = iMidiPan; |
iLastPanRequest = iMidiPan; |
184 |
} |
} |
185 |
|
|
187 |
return (pEngine) ? pEngine->pAudioOutputDevice : NULL; |
return (pEngine) ? pEngine->pAudioOutputDevice : NULL; |
188 |
} |
} |
189 |
|
|
190 |
|
/** |
191 |
|
* Gets thread safe access to the currently connected audio output |
192 |
|
* device from other threads than the lscp thread. |
193 |
|
*/ |
194 |
|
AudioOutputDevice* AbstractEngineChannel::GetAudioOutputDeviceSafe() { |
195 |
|
EngineMutex.Lock(); |
196 |
|
AudioOutputDevice* res = GetAudioOutputDevice(); |
197 |
|
EngineMutex.Unlock(); |
198 |
|
return res; |
199 |
|
} |
200 |
|
|
201 |
void AbstractEngineChannel::SetOutputChannel(uint EngineAudioChannel, uint AudioDeviceChannel) { |
void AbstractEngineChannel::SetOutputChannel(uint EngineAudioChannel, uint AudioDeviceChannel) { |
202 |
if (!pEngine || !pEngine->pAudioOutputDevice) throw AudioOutputException("No audio output device connected yet."); |
if (!pEngine || !pEngine->pAudioOutputDevice) throw AudioOutputException("No audio output device connected yet."); |
203 |
|
|
285 |
* @param Key - MIDI key number of the triggered key |
* @param Key - MIDI key number of the triggered key |
286 |
* @param Velocity - MIDI velocity value of the triggered key |
* @param Velocity - MIDI velocity value of the triggered key |
287 |
*/ |
*/ |
288 |
void AbstractEngineChannel::SendNoteOn(uint8_t Key, uint8_t Velocity) { |
void AbstractEngineChannel::SendNoteOn(uint8_t Key, uint8_t Velocity, uint8_t MidiChannel) { |
289 |
if (pEngine) { |
if (pEngine) { |
290 |
Event event = pEngine->pEventGenerator->CreateEvent(); |
Event event = pEngine->pEventGenerator->CreateEvent(); |
291 |
event.Type = Event::type_note_on; |
event.Type = Event::type_note_on; |
292 |
event.Param.Note.Key = Key; |
event.Param.Note.Key = Key; |
293 |
event.Param.Note.Velocity = Velocity; |
event.Param.Note.Velocity = Velocity; |
294 |
|
event.Param.Note.Channel = MidiChannel; |
295 |
event.pEngineChannel = this; |
event.pEngineChannel = this; |
296 |
if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event); |
if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event); |
297 |
else dmsg(1,("EngineChannel: Input event queue full!")); |
else dmsg(1,("EngineChannel: Input event queue full!")); |
319 |
* @param FragmentPos - sample point position in the current audio |
* @param FragmentPos - sample point position in the current audio |
320 |
* fragment to which this event belongs to |
* fragment to which this event belongs to |
321 |
*/ |
*/ |
322 |
void AbstractEngineChannel::SendNoteOn(uint8_t Key, uint8_t Velocity, int32_t FragmentPos) { |
void AbstractEngineChannel::SendNoteOn(uint8_t Key, uint8_t Velocity, uint8_t MidiChannel, int32_t FragmentPos) { |
323 |
if (FragmentPos < 0) { |
if (FragmentPos < 0) { |
324 |
dmsg(1,("EngineChannel::SendNoteOn(): negative FragmentPos! Seems MIDI driver is buggy!")); |
dmsg(1,("EngineChannel::SendNoteOn(): negative FragmentPos! Seems MIDI driver is buggy!")); |
325 |
} |
} |
328 |
event.Type = Event::type_note_on; |
event.Type = Event::type_note_on; |
329 |
event.Param.Note.Key = Key; |
event.Param.Note.Key = Key; |
330 |
event.Param.Note.Velocity = Velocity; |
event.Param.Note.Velocity = Velocity; |
331 |
|
event.Param.Note.Channel = MidiChannel; |
332 |
event.pEngineChannel = this; |
event.pEngineChannel = this; |
333 |
if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event); |
if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event); |
334 |
else dmsg(1,("EngineChannel: Input event queue full!")); |
else dmsg(1,("EngineChannel: Input event queue full!")); |
354 |
* @param Key - MIDI key number of the released key |
* @param Key - MIDI key number of the released key |
355 |
* @param Velocity - MIDI release velocity value of the released key |
* @param Velocity - MIDI release velocity value of the released key |
356 |
*/ |
*/ |
357 |
void AbstractEngineChannel::SendNoteOff(uint8_t Key, uint8_t Velocity) { |
void AbstractEngineChannel::SendNoteOff(uint8_t Key, uint8_t Velocity, uint8_t MidiChannel) { |
358 |
if (pEngine) { |
if (pEngine) { |
359 |
Event event = pEngine->pEventGenerator->CreateEvent(); |
Event event = pEngine->pEventGenerator->CreateEvent(); |
360 |
event.Type = Event::type_note_off; |
event.Type = Event::type_note_off; |
361 |
event.Param.Note.Key = Key; |
event.Param.Note.Key = Key; |
362 |
event.Param.Note.Velocity = Velocity; |
event.Param.Note.Velocity = Velocity; |
363 |
|
event.Param.Note.Channel = MidiChannel; |
364 |
event.pEngineChannel = this; |
event.pEngineChannel = this; |
365 |
if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event); |
if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event); |
366 |
else dmsg(1,("EngineChannel: Input event queue full!")); |
else dmsg(1,("EngineChannel: Input event queue full!")); |
388 |
* @param FragmentPos - sample point position in the current audio |
* @param FragmentPos - sample point position in the current audio |
389 |
* fragment to which this event belongs to |
* fragment to which this event belongs to |
390 |
*/ |
*/ |
391 |
void AbstractEngineChannel::SendNoteOff(uint8_t Key, uint8_t Velocity, int32_t FragmentPos) { |
void AbstractEngineChannel::SendNoteOff(uint8_t Key, uint8_t Velocity, uint8_t MidiChannel, int32_t FragmentPos) { |
392 |
if (FragmentPos < 0) { |
if (FragmentPos < 0) { |
393 |
dmsg(1,("EngineChannel::SendNoteOff(): negative FragmentPos! Seems MIDI driver is buggy!")); |
dmsg(1,("EngineChannel::SendNoteOff(): negative FragmentPos! Seems MIDI driver is buggy!")); |
394 |
} |
} |
397 |
event.Type = Event::type_note_off; |
event.Type = Event::type_note_off; |
398 |
event.Param.Note.Key = Key; |
event.Param.Note.Key = Key; |
399 |
event.Param.Note.Velocity = Velocity; |
event.Param.Note.Velocity = Velocity; |
400 |
|
event.Param.Note.Channel = MidiChannel; |
401 |
event.pEngineChannel = this; |
event.pEngineChannel = this; |
402 |
if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event); |
if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event); |
403 |
else dmsg(1,("EngineChannel: Input event queue full!")); |
else dmsg(1,("EngineChannel: Input event queue full!")); |
422 |
* |
* |
423 |
* @param Pitch - MIDI pitch value (-8192 ... +8191) |
* @param Pitch - MIDI pitch value (-8192 ... +8191) |
424 |
*/ |
*/ |
425 |
void AbstractEngineChannel::SendPitchbend(int Pitch) { |
void AbstractEngineChannel::SendPitchbend(int Pitch, uint8_t MidiChannel) { |
426 |
if (pEngine) { |
if (pEngine) { |
427 |
Event event = pEngine->pEventGenerator->CreateEvent(); |
Event event = pEngine->pEventGenerator->CreateEvent(); |
428 |
event.Type = Event::type_pitchbend; |
event.Type = Event::type_pitchbend; |
429 |
event.Param.Pitch.Pitch = Pitch; |
event.Param.Pitch.Pitch = Pitch; |
430 |
|
event.Param.Pitch.Channel = MidiChannel; |
431 |
event.pEngineChannel = this; |
event.pEngineChannel = this; |
432 |
if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event); |
if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event); |
433 |
else dmsg(1,("EngineChannel: Input event queue full!")); |
else dmsg(1,("EngineChannel: Input event queue full!")); |
444 |
* @param FragmentPos - sample point position in the current audio |
* @param FragmentPos - sample point position in the current audio |
445 |
* fragment to which this event belongs to |
* fragment to which this event belongs to |
446 |
*/ |
*/ |
447 |
void AbstractEngineChannel::SendPitchbend(int Pitch, int32_t FragmentPos) { |
void AbstractEngineChannel::SendPitchbend(int Pitch, uint8_t MidiChannel, int32_t FragmentPos) { |
448 |
if (FragmentPos < 0) { |
if (FragmentPos < 0) { |
449 |
dmsg(1,("AbstractEngineChannel::SendPitchBend(): negative FragmentPos! Seems MIDI driver is buggy!")); |
dmsg(1,("AbstractEngineChannel::SendPitchBend(): negative FragmentPos! Seems MIDI driver is buggy!")); |
450 |
} |
} |
452 |
Event event = pEngine->pEventGenerator->CreateEvent(FragmentPos); |
Event event = pEngine->pEventGenerator->CreateEvent(FragmentPos); |
453 |
event.Type = Event::type_pitchbend; |
event.Type = Event::type_pitchbend; |
454 |
event.Param.Pitch.Pitch = Pitch; |
event.Param.Pitch.Pitch = Pitch; |
455 |
|
event.Param.Pitch.Channel = MidiChannel; |
456 |
event.pEngineChannel = this; |
event.pEngineChannel = this; |
457 |
if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event); |
if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event); |
458 |
else dmsg(1,("AbstractEngineChannel: Input event queue full!")); |
else dmsg(1,("AbstractEngineChannel: Input event queue full!")); |
468 |
* @param Controller - MIDI controller number of the occured control change |
* @param Controller - MIDI controller number of the occured control change |
469 |
* @param Value - value of the control change |
* @param Value - value of the control change |
470 |
*/ |
*/ |
471 |
void AbstractEngineChannel::SendControlChange(uint8_t Controller, uint8_t Value) { |
void AbstractEngineChannel::SendControlChange(uint8_t Controller, uint8_t Value, uint8_t MidiChannel) { |
472 |
if (pEngine) { |
if (pEngine) { |
473 |
Event event = pEngine->pEventGenerator->CreateEvent(); |
Event event = pEngine->pEventGenerator->CreateEvent(); |
474 |
event.Type = Event::type_control_change; |
event.Type = Event::type_control_change; |
475 |
event.Param.CC.Controller = Controller; |
event.Param.CC.Controller = Controller; |
476 |
event.Param.CC.Value = Value; |
event.Param.CC.Value = Value; |
477 |
|
event.Param.CC.Channel = MidiChannel; |
478 |
event.pEngineChannel = this; |
event.pEngineChannel = this; |
479 |
if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event); |
if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event); |
480 |
else dmsg(1,("AbstractEngineChannel: Input event queue full!")); |
else dmsg(1,("AbstractEngineChannel: Input event queue full!")); |
492 |
* @param FragmentPos - sample point position in the current audio |
* @param FragmentPos - sample point position in the current audio |
493 |
* fragment to which this event belongs to |
* fragment to which this event belongs to |
494 |
*/ |
*/ |
495 |
void AbstractEngineChannel::SendControlChange(uint8_t Controller, uint8_t Value, int32_t FragmentPos) { |
void AbstractEngineChannel::SendControlChange(uint8_t Controller, uint8_t Value, uint8_t MidiChannel, int32_t FragmentPos) { |
496 |
if (FragmentPos < 0) { |
if (FragmentPos < 0) { |
497 |
dmsg(1,("AbstractEngineChannel::SendControlChange(): negative FragmentPos! Seems MIDI driver is buggy!")); |
dmsg(1,("AbstractEngineChannel::SendControlChange(): negative FragmentPos! Seems MIDI driver is buggy!")); |
498 |
} |
} |
501 |
event.Type = Event::type_control_change; |
event.Type = Event::type_control_change; |
502 |
event.Param.CC.Controller = Controller; |
event.Param.CC.Controller = Controller; |
503 |
event.Param.CC.Value = Value; |
event.Param.CC.Value = Value; |
504 |
|
event.Param.CC.Channel = MidiChannel; |
505 |
event.pEngineChannel = this; |
event.pEngineChannel = this; |
506 |
if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event); |
if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event); |
507 |
else dmsg(1,("AbstractEngineChannel: Input event queue full!")); |
else dmsg(1,("AbstractEngineChannel: Input event queue full!")); |
525 |
// import events from pure software MIDI "devices" |
// import events from pure software MIDI "devices" |
526 |
// (e.g. virtual keyboard in instrument editor) |
// (e.g. virtual keyboard in instrument editor) |
527 |
{ |
{ |
528 |
|
const uint8_t channel = MidiChannel() == midi_chan_all ? 0 : MidiChannel(); |
529 |
const int FragmentPos = 0; // randomly chosen, we don't care about jitter for virtual MIDI devices |
const int FragmentPos = 0; // randomly chosen, we don't care about jitter for virtual MIDI devices |
530 |
Event event = pEngine->pEventGenerator->CreateEvent(FragmentPos); |
Event event = pEngine->pEventGenerator->CreateEvent(FragmentPos); |
531 |
VirtualMidiDevice::event_t devEvent; // the event format we get from the virtual MIDI device |
VirtualMidiDevice::event_t devEvent; // the event format we get from the virtual MIDI device |
543 |
event.Type = Event::type_note_on; |
event.Type = Event::type_note_on; |
544 |
event.Param.Note.Key = devEvent.Arg1; |
event.Param.Note.Key = devEvent.Arg1; |
545 |
event.Param.Note.Velocity = devEvent.Arg2; |
event.Param.Note.Velocity = devEvent.Arg2; |
546 |
|
event.Param.Note.Channel = channel; |
547 |
break; |
break; |
548 |
case VirtualMidiDevice::EVENT_TYPE_NOTEOFF: |
case VirtualMidiDevice::EVENT_TYPE_NOTEOFF: |
549 |
event.Type = Event::type_note_off; |
event.Type = Event::type_note_off; |
550 |
event.Param.Note.Key = devEvent.Arg1; |
event.Param.Note.Key = devEvent.Arg1; |
551 |
event.Param.Note.Velocity = devEvent.Arg2; |
event.Param.Note.Velocity = devEvent.Arg2; |
552 |
|
event.Param.Note.Channel = channel; |
553 |
break; |
break; |
554 |
case VirtualMidiDevice::EVENT_TYPE_CC: |
case VirtualMidiDevice::EVENT_TYPE_CC: |
555 |
event.Type = Event::type_control_change; |
event.Type = Event::type_control_change; |
556 |
event.Param.CC.Controller = devEvent.Arg1; |
event.Param.CC.Controller = devEvent.Arg1; |
557 |
event.Param.CC.Value = devEvent.Arg2; |
event.Param.CC.Value = devEvent.Arg2; |
558 |
|
event.Param.CC.Channel = channel; |
559 |
break; |
break; |
560 |
default: |
default: |
561 |
std::cerr << "AbstractEngineChannel::ImportEvents() ERROR: unknown event type (" |
std::cerr << "AbstractEngineChannel::ImportEvents() ERROR: unknown event type (" |