3 |
* LinuxSampler - modular, streaming capable sampler * |
* LinuxSampler - modular, streaming capable sampler * |
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 - 2007 Christian Schoenebeck * |
* Copyright (C) 2005 - 2008 Christian Schoenebeck * |
7 |
* * |
* * |
8 |
* This program is free software; you can redistribute it and/or modify * |
* This program is free software; you can redistribute it and/or modify * |
9 |
* 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 * |
27 |
#include "MidiInstrumentMapper.h" |
#include "MidiInstrumentMapper.h" |
28 |
#include "../../Sampler.h" |
#include "../../Sampler.h" |
29 |
#include "../../engines/EngineFactory.h" |
#include "../../engines/EngineFactory.h" |
30 |
|
#include "VirtualMidiDevice.h" |
31 |
|
|
32 |
|
#include <algorithm> |
33 |
|
|
34 |
namespace LinuxSampler { |
namespace LinuxSampler { |
35 |
|
|
76 |
|
|
77 |
MidiInputPort::MidiInputPort(MidiInputDevice* pDevice, int portNumber) |
MidiInputPort::MidiInputPort(MidiInputDevice* pDevice, int portNumber) |
78 |
: MidiChannelMapReader(MidiChannelMap), |
: MidiChannelMapReader(MidiChannelMap), |
79 |
SysexListenersReader(SysexListeners) { |
SysexListenersReader(SysexListeners), |
80 |
|
virtualMidiDevicesReader(virtualMidiDevices) { |
81 |
this->pDevice = pDevice; |
this->pDevice = pDevice; |
82 |
this->portNumber = portNumber; |
this->portNumber = portNumber; |
83 |
Parameters["NAME"] = new ParameterName(this); |
Parameters["NAME"] = new ParameterName(this); |
111 |
for (; engineiter != end; engineiter++) (*engineiter)->SendNoteOn(Key, Velocity); |
for (; engineiter != end; engineiter++) (*engineiter)->SendNoteOn(Key, Velocity); |
112 |
} |
} |
113 |
MidiChannelMapReader.Unlock(); |
MidiChannelMapReader.Unlock(); |
114 |
|
|
115 |
|
// dispatch event to all low priority MIDI listeners |
116 |
|
const std::vector<VirtualMidiDevice*>& listeners = |
117 |
|
virtualMidiDevicesReader.Lock(); |
118 |
|
for (int i = 0; i < listeners.size(); ++i) |
119 |
|
listeners[i]->SendNoteOnToDevice(Key, Velocity); |
120 |
|
virtualMidiDevicesReader.Unlock(); |
121 |
} |
} |
122 |
|
|
123 |
void MidiInputPort::DispatchNoteOn(uint8_t Key, uint8_t Velocity, uint MidiChannel, int32_t FragmentPos) { |
void MidiInputPort::DispatchNoteOn(uint8_t Key, uint8_t Velocity, uint MidiChannel, int32_t FragmentPos) { |
136 |
for (; engineiter != end; engineiter++) (*engineiter)->SendNoteOn(Key, Velocity, FragmentPos); |
for (; engineiter != end; engineiter++) (*engineiter)->SendNoteOn(Key, Velocity, FragmentPos); |
137 |
} |
} |
138 |
MidiChannelMapReader.Unlock(); |
MidiChannelMapReader.Unlock(); |
139 |
|
|
140 |
|
// dispatch event to all low priority MIDI listeners |
141 |
|
const std::vector<VirtualMidiDevice*>& listeners = |
142 |
|
virtualMidiDevicesReader.Lock(); |
143 |
|
for (int i = 0; i < listeners.size(); ++i) |
144 |
|
listeners[i]->SendNoteOnToDevice(Key, Velocity); |
145 |
|
virtualMidiDevicesReader.Unlock(); |
146 |
} |
} |
147 |
|
|
148 |
void MidiInputPort::DispatchNoteOff(uint8_t Key, uint8_t Velocity, uint MidiChannel) { |
void MidiInputPort::DispatchNoteOff(uint8_t Key, uint8_t Velocity, uint MidiChannel) { |
161 |
for (; engineiter != end; engineiter++) (*engineiter)->SendNoteOff(Key, Velocity); |
for (; engineiter != end; engineiter++) (*engineiter)->SendNoteOff(Key, Velocity); |
162 |
} |
} |
163 |
MidiChannelMapReader.Unlock(); |
MidiChannelMapReader.Unlock(); |
164 |
|
|
165 |
|
// dispatch event to all low priority MIDI listeners |
166 |
|
const std::vector<VirtualMidiDevice*>& listeners = |
167 |
|
virtualMidiDevicesReader.Lock(); |
168 |
|
for (int i = 0; i < listeners.size(); ++i) |
169 |
|
listeners[i]->SendNoteOffToDevice(Key, Velocity); |
170 |
|
virtualMidiDevicesReader.Unlock(); |
171 |
} |
} |
172 |
|
|
173 |
void MidiInputPort::DispatchNoteOff(uint8_t Key, uint8_t Velocity, uint MidiChannel, int32_t FragmentPos) { |
void MidiInputPort::DispatchNoteOff(uint8_t Key, uint8_t Velocity, uint MidiChannel, int32_t FragmentPos) { |
186 |
for (; engineiter != end; engineiter++) (*engineiter)->SendNoteOff(Key, Velocity, FragmentPos); |
for (; engineiter != end; engineiter++) (*engineiter)->SendNoteOff(Key, Velocity, FragmentPos); |
187 |
} |
} |
188 |
MidiChannelMapReader.Unlock(); |
MidiChannelMapReader.Unlock(); |
189 |
|
|
190 |
|
// dispatch event to all low priority MIDI listeners |
191 |
|
const std::vector<VirtualMidiDevice*>& listeners = |
192 |
|
virtualMidiDevicesReader.Lock(); |
193 |
|
for (int i = 0; i < listeners.size(); ++i) |
194 |
|
listeners[i]->SendNoteOffToDevice(Key, Velocity); |
195 |
|
virtualMidiDevicesReader.Unlock(); |
196 |
} |
} |
197 |
|
|
198 |
void MidiInputPort::DispatchPitchbend(int Pitch, uint MidiChannel) { |
void MidiInputPort::DispatchPitchbend(int Pitch, uint MidiChannel) { |
471 |
return count; |
return count; |
472 |
} |
} |
473 |
|
|
474 |
|
void MidiInputPort::Connect(VirtualMidiDevice* pDevice) { |
475 |
|
virtualMidiDevicesMutex.Lock(); |
476 |
|
// double buffer ... double work ... |
477 |
|
{ |
478 |
|
std::vector<VirtualMidiDevice*>& devices = |
479 |
|
virtualMidiDevices.GetConfigForUpdate(); |
480 |
|
devices.push_back(pDevice); |
481 |
|
} |
482 |
|
{ |
483 |
|
std::vector<VirtualMidiDevice*>& devices = |
484 |
|
virtualMidiDevices.SwitchConfig(); |
485 |
|
devices.push_back(pDevice); |
486 |
|
} |
487 |
|
virtualMidiDevicesMutex.Unlock(); |
488 |
|
} |
489 |
|
|
490 |
|
void MidiInputPort::Disconnect(VirtualMidiDevice* pDevice) { |
491 |
|
virtualMidiDevicesMutex.Lock(); |
492 |
|
// double buffer ... double work ... |
493 |
|
{ |
494 |
|
std::vector<VirtualMidiDevice*>& devices = |
495 |
|
virtualMidiDevices.GetConfigForUpdate(); |
496 |
|
devices.erase(std::find(devices.begin(), devices.end(), pDevice)); |
497 |
|
} |
498 |
|
{ |
499 |
|
std::vector<VirtualMidiDevice*>& devices = |
500 |
|
virtualMidiDevices.SwitchConfig(); |
501 |
|
devices.erase(std::find(devices.begin(), devices.end(), pDevice)); |
502 |
|
} |
503 |
|
virtualMidiDevicesMutex.Unlock(); |
504 |
|
} |
505 |
|
|
506 |
} // namespace LinuxSampler |
} // namespace LinuxSampler |