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 * |
278 |
* @param Key - MIDI key number of the triggered key |
* @param Key - MIDI key number of the triggered key |
279 |
* @param Velocity - MIDI velocity value of the triggered key |
* @param Velocity - MIDI velocity value of the triggered key |
280 |
*/ |
*/ |
281 |
void AbstractEngineChannel::SendNoteOn(uint8_t Key, uint8_t Velocity) { |
void AbstractEngineChannel::SendNoteOn(uint8_t Key, uint8_t Velocity, uint8_t MidiChannel) { |
282 |
if (pEngine) { |
if (pEngine) { |
283 |
Event event = pEngine->pEventGenerator->CreateEvent(); |
Event event = pEngine->pEventGenerator->CreateEvent(); |
284 |
event.Type = Event::type_note_on; |
event.Type = Event::type_note_on; |
285 |
event.Param.Note.Key = Key; |
event.Param.Note.Key = Key; |
286 |
event.Param.Note.Velocity = Velocity; |
event.Param.Note.Velocity = Velocity; |
287 |
|
event.Param.Note.Channel = MidiChannel; |
288 |
event.pEngineChannel = this; |
event.pEngineChannel = this; |
289 |
if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event); |
if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event); |
290 |
else dmsg(1,("EngineChannel: Input event queue full!")); |
else dmsg(1,("EngineChannel: Input event queue full!")); |
312 |
* @param FragmentPos - sample point position in the current audio |
* @param FragmentPos - sample point position in the current audio |
313 |
* fragment to which this event belongs to |
* fragment to which this event belongs to |
314 |
*/ |
*/ |
315 |
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) { |
316 |
if (FragmentPos < 0) { |
if (FragmentPos < 0) { |
317 |
dmsg(1,("EngineChannel::SendNoteOn(): negative FragmentPos! Seems MIDI driver is buggy!")); |
dmsg(1,("EngineChannel::SendNoteOn(): negative FragmentPos! Seems MIDI driver is buggy!")); |
318 |
} |
} |
321 |
event.Type = Event::type_note_on; |
event.Type = Event::type_note_on; |
322 |
event.Param.Note.Key = Key; |
event.Param.Note.Key = Key; |
323 |
event.Param.Note.Velocity = Velocity; |
event.Param.Note.Velocity = Velocity; |
324 |
|
event.Param.Note.Channel = MidiChannel; |
325 |
event.pEngineChannel = this; |
event.pEngineChannel = this; |
326 |
if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event); |
if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event); |
327 |
else dmsg(1,("EngineChannel: Input event queue full!")); |
else dmsg(1,("EngineChannel: Input event queue full!")); |
347 |
* @param Key - MIDI key number of the released key |
* @param Key - MIDI key number of the released key |
348 |
* @param Velocity - MIDI release velocity value of the released key |
* @param Velocity - MIDI release velocity value of the released key |
349 |
*/ |
*/ |
350 |
void AbstractEngineChannel::SendNoteOff(uint8_t Key, uint8_t Velocity) { |
void AbstractEngineChannel::SendNoteOff(uint8_t Key, uint8_t Velocity, uint8_t MidiChannel) { |
351 |
if (pEngine) { |
if (pEngine) { |
352 |
Event event = pEngine->pEventGenerator->CreateEvent(); |
Event event = pEngine->pEventGenerator->CreateEvent(); |
353 |
event.Type = Event::type_note_off; |
event.Type = Event::type_note_off; |
354 |
event.Param.Note.Key = Key; |
event.Param.Note.Key = Key; |
355 |
event.Param.Note.Velocity = Velocity; |
event.Param.Note.Velocity = Velocity; |
356 |
|
event.Param.Note.Channel = MidiChannel; |
357 |
event.pEngineChannel = this; |
event.pEngineChannel = this; |
358 |
if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event); |
if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event); |
359 |
else dmsg(1,("EngineChannel: Input event queue full!")); |
else dmsg(1,("EngineChannel: Input event queue full!")); |
381 |
* @param FragmentPos - sample point position in the current audio |
* @param FragmentPos - sample point position in the current audio |
382 |
* fragment to which this event belongs to |
* fragment to which this event belongs to |
383 |
*/ |
*/ |
384 |
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) { |
385 |
if (FragmentPos < 0) { |
if (FragmentPos < 0) { |
386 |
dmsg(1,("EngineChannel::SendNoteOff(): negative FragmentPos! Seems MIDI driver is buggy!")); |
dmsg(1,("EngineChannel::SendNoteOff(): negative FragmentPos! Seems MIDI driver is buggy!")); |
387 |
} |
} |
390 |
event.Type = Event::type_note_off; |
event.Type = Event::type_note_off; |
391 |
event.Param.Note.Key = Key; |
event.Param.Note.Key = Key; |
392 |
event.Param.Note.Velocity = Velocity; |
event.Param.Note.Velocity = Velocity; |
393 |
|
event.Param.Note.Channel = MidiChannel; |
394 |
event.pEngineChannel = this; |
event.pEngineChannel = this; |
395 |
if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event); |
if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event); |
396 |
else dmsg(1,("EngineChannel: Input event queue full!")); |
else dmsg(1,("EngineChannel: Input event queue full!")); |
415 |
* |
* |
416 |
* @param Pitch - MIDI pitch value (-8192 ... +8191) |
* @param Pitch - MIDI pitch value (-8192 ... +8191) |
417 |
*/ |
*/ |
418 |
void AbstractEngineChannel::SendPitchbend(int Pitch) { |
void AbstractEngineChannel::SendPitchbend(int Pitch, uint8_t MidiChannel) { |
419 |
if (pEngine) { |
if (pEngine) { |
420 |
Event event = pEngine->pEventGenerator->CreateEvent(); |
Event event = pEngine->pEventGenerator->CreateEvent(); |
421 |
event.Type = Event::type_pitchbend; |
event.Type = Event::type_pitchbend; |
422 |
event.Param.Pitch.Pitch = Pitch; |
event.Param.Pitch.Pitch = Pitch; |
423 |
|
event.Param.Pitch.Channel = MidiChannel; |
424 |
event.pEngineChannel = this; |
event.pEngineChannel = this; |
425 |
if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event); |
if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event); |
426 |
else dmsg(1,("EngineChannel: Input event queue full!")); |
else dmsg(1,("EngineChannel: Input event queue full!")); |
437 |
* @param FragmentPos - sample point position in the current audio |
* @param FragmentPos - sample point position in the current audio |
438 |
* fragment to which this event belongs to |
* fragment to which this event belongs to |
439 |
*/ |
*/ |
440 |
void AbstractEngineChannel::SendPitchbend(int Pitch, int32_t FragmentPos) { |
void AbstractEngineChannel::SendPitchbend(int Pitch, uint8_t MidiChannel, int32_t FragmentPos) { |
441 |
if (FragmentPos < 0) { |
if (FragmentPos < 0) { |
442 |
dmsg(1,("AbstractEngineChannel::SendPitchBend(): negative FragmentPos! Seems MIDI driver is buggy!")); |
dmsg(1,("AbstractEngineChannel::SendPitchBend(): negative FragmentPos! Seems MIDI driver is buggy!")); |
443 |
} |
} |
445 |
Event event = pEngine->pEventGenerator->CreateEvent(FragmentPos); |
Event event = pEngine->pEventGenerator->CreateEvent(FragmentPos); |
446 |
event.Type = Event::type_pitchbend; |
event.Type = Event::type_pitchbend; |
447 |
event.Param.Pitch.Pitch = Pitch; |
event.Param.Pitch.Pitch = Pitch; |
448 |
|
event.Param.Pitch.Channel = MidiChannel; |
449 |
event.pEngineChannel = this; |
event.pEngineChannel = this; |
450 |
if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event); |
if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event); |
451 |
else dmsg(1,("AbstractEngineChannel: Input event queue full!")); |
else dmsg(1,("AbstractEngineChannel: Input event queue full!")); |
461 |
* @param Controller - MIDI controller number of the occured control change |
* @param Controller - MIDI controller number of the occured control change |
462 |
* @param Value - value of the control change |
* @param Value - value of the control change |
463 |
*/ |
*/ |
464 |
void AbstractEngineChannel::SendControlChange(uint8_t Controller, uint8_t Value) { |
void AbstractEngineChannel::SendControlChange(uint8_t Controller, uint8_t Value, uint8_t MidiChannel) { |
465 |
if (pEngine) { |
if (pEngine) { |
466 |
Event event = pEngine->pEventGenerator->CreateEvent(); |
Event event = pEngine->pEventGenerator->CreateEvent(); |
467 |
event.Type = Event::type_control_change; |
event.Type = Event::type_control_change; |
468 |
event.Param.CC.Controller = Controller; |
event.Param.CC.Controller = Controller; |
469 |
event.Param.CC.Value = Value; |
event.Param.CC.Value = Value; |
470 |
|
event.Param.CC.Channel = MidiChannel; |
471 |
event.pEngineChannel = this; |
event.pEngineChannel = this; |
472 |
if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event); |
if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event); |
473 |
else dmsg(1,("AbstractEngineChannel: Input event queue full!")); |
else dmsg(1,("AbstractEngineChannel: Input event queue full!")); |
485 |
* @param FragmentPos - sample point position in the current audio |
* @param FragmentPos - sample point position in the current audio |
486 |
* fragment to which this event belongs to |
* fragment to which this event belongs to |
487 |
*/ |
*/ |
488 |
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) { |
489 |
if (FragmentPos < 0) { |
if (FragmentPos < 0) { |
490 |
dmsg(1,("AbstractEngineChannel::SendControlChange(): negative FragmentPos! Seems MIDI driver is buggy!")); |
dmsg(1,("AbstractEngineChannel::SendControlChange(): negative FragmentPos! Seems MIDI driver is buggy!")); |
491 |
} |
} |
494 |
event.Type = Event::type_control_change; |
event.Type = Event::type_control_change; |
495 |
event.Param.CC.Controller = Controller; |
event.Param.CC.Controller = Controller; |
496 |
event.Param.CC.Value = Value; |
event.Param.CC.Value = Value; |
497 |
|
event.Param.CC.Channel = MidiChannel; |
498 |
event.pEngineChannel = this; |
event.pEngineChannel = this; |
499 |
if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event); |
if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event); |
500 |
else dmsg(1,("AbstractEngineChannel: Input event queue full!")); |
else dmsg(1,("AbstractEngineChannel: Input event queue full!")); |
518 |
// import events from pure software MIDI "devices" |
// import events from pure software MIDI "devices" |
519 |
// (e.g. virtual keyboard in instrument editor) |
// (e.g. virtual keyboard in instrument editor) |
520 |
{ |
{ |
521 |
|
const uint8_t channel = MidiChannel() == midi_chan_all ? 0 : MidiChannel(); |
522 |
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 |
523 |
Event event = pEngine->pEventGenerator->CreateEvent(FragmentPos); |
Event event = pEngine->pEventGenerator->CreateEvent(FragmentPos); |
524 |
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 |
536 |
event.Type = Event::type_note_on; |
event.Type = Event::type_note_on; |
537 |
event.Param.Note.Key = devEvent.Arg1; |
event.Param.Note.Key = devEvent.Arg1; |
538 |
event.Param.Note.Velocity = devEvent.Arg2; |
event.Param.Note.Velocity = devEvent.Arg2; |
539 |
|
event.Param.Note.Channel = channel; |
540 |
break; |
break; |
541 |
case VirtualMidiDevice::EVENT_TYPE_NOTEOFF: |
case VirtualMidiDevice::EVENT_TYPE_NOTEOFF: |
542 |
event.Type = Event::type_note_off; |
event.Type = Event::type_note_off; |
543 |
event.Param.Note.Key = devEvent.Arg1; |
event.Param.Note.Key = devEvent.Arg1; |
544 |
event.Param.Note.Velocity = devEvent.Arg2; |
event.Param.Note.Velocity = devEvent.Arg2; |
545 |
|
event.Param.Note.Channel = channel; |
546 |
break; |
break; |
547 |
case VirtualMidiDevice::EVENT_TYPE_CC: |
case VirtualMidiDevice::EVENT_TYPE_CC: |
548 |
event.Type = Event::type_control_change; |
event.Type = Event::type_control_change; |
549 |
event.Param.CC.Controller = devEvent.Arg1; |
event.Param.CC.Controller = devEvent.Arg1; |
550 |
event.Param.CC.Value = devEvent.Arg2; |
event.Param.CC.Value = devEvent.Arg2; |
551 |
|
event.Param.CC.Channel = channel; |
552 |
break; |
break; |
553 |
default: |
default: |
554 |
std::cerr << "AbstractEngineChannel::ImportEvents() ERROR: unknown event type (" |
std::cerr << "AbstractEngineChannel::ImportEvents() ERROR: unknown event type (" |