--- linuxsampler/trunk/src/drivers/midi/MidiInputPort.h 2004/08/20 17:25:19 221 +++ linuxsampler/trunk/src/drivers/midi/MidiInputPort.h 2005/05/17 18:16:54 551 @@ -3,6 +3,7 @@ * LinuxSampler - modular, streaming capable sampler * * * * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * + * Copyright (C) 2005 Christian Schoenebeck * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * @@ -24,10 +25,11 @@ #define __LS_MIDIINPUTPORT_H__ #include "../../common/global.h" +#include "../../common/Mutex.h" #include "../../common/LinuxSamplerException.h" #include "../DeviceParameter.h" #include "MidiInputDevice.h" -#include "../../engines/common/Engine.h" +#include "../../engines/common/EngineChannel.h" namespace LinuxSampler { @@ -44,23 +46,23 @@ * MIDI channels */ enum midi_chan_t { - midi_chan_all = 0, - midi_chan_1 = 1, - midi_chan_2 = 2, - midi_chan_3 = 3, - midi_chan_4 = 4, - midi_chan_5 = 5, - midi_chan_6 = 6, - midi_chan_7 = 7, - midi_chan_8 = 8, - midi_chan_9 = 9, - midi_chan_10 = 10, - midi_chan_11 = 11, - midi_chan_12 = 12, - midi_chan_13 = 13, - midi_chan_14 = 14, - midi_chan_15 = 15, - midi_chan_16 = 16 + midi_chan_1 = 0, + midi_chan_2 = 1, + midi_chan_3 = 2, + midi_chan_4 = 3, + midi_chan_5 = 4, + midi_chan_6 = 5, + midi_chan_7 = 6, + midi_chan_8 = 7, + midi_chan_9 = 8, + midi_chan_10 = 9, + midi_chan_11 = 10, + midi_chan_12 = 11, + midi_chan_13 = 12, + midi_chan_14 = 13, + midi_chan_15 = 14, + midi_chan_16 = 15, + midi_chan_all = 16 }; /** MIDI Port Parameter 'NAME' @@ -96,14 +98,16 @@ * @param MidiChannel - MIDI channel to connect to * @throws MidiInputException if MidiChannel argument invalid */ - void Connect(Engine* pEngine, midi_chan_t MidiChannel); + void Connect(EngineChannel* pEngineChannel, midi_chan_t MidiChannel); /** * Disconnect given sampler engine from this MIDI input device. + * If the given engine was not connected with this device, + * nothing happens. * * @param pEngine - sampler engine */ - void Disconnect(Engine* pEngine); + void Disconnect(EngineChannel* pEngineChannel); /** * Return MIDI device where this MIDI port belongs to. @@ -138,6 +142,7 @@ * @param Key - MIDI key number of the triggered key * @param Velocity - MIDI velocity of the triggered key * @param MidiChannel - MIDI channel on which event occured on + * (low level indexing, means 0..15) */ void DispatchNoteOn(uint8_t Key, uint8_t Velocity, uint MidiChannel); @@ -150,6 +155,7 @@ * @param Key - MIDI key number of the released key * @param Velocity - MIDI velocity of the released key * @param MidiChannel - MIDI channel on which event occured on + * (low level indexing, means 0..15) */ void DispatchNoteOff(uint8_t Key, uint8_t Velocity, uint MidiChannel); @@ -160,6 +166,7 @@ * * @param Pitch - MIDI pitch value * @param MidiChannel - MIDI channel on which event occured on + * (low level indexing, means 0..15) */ void DispatchPitchbend(int Pitch, uint MidiChannel); @@ -172,14 +179,49 @@ * @param Controller - MIDI controller number * @param Value - MIDI control change value * @param MidiChannel - MIDI channel on which event occured on + * (low level indexing, means 0..15) */ void DispatchControlChange(uint8_t Controller, uint8_t Value, uint MidiChannel); + /** + * Should be called by the implementing MIDI input device + * whenever a program change event arrived, this will cause the + * appropriate sampler channel to be connected with this MIDI + * device. + * + * For example consider a program change event on MIDI channel + * 3 for program number 18. This would cause this MIDI input + * device to be connected to sampler channel 18 and would cause + * sampler channel 18 to listen to MIDI channel 3. + * + * This is the current, general implementation of program + * change events. It might change in future, e.g to allow + * sampler engines to allow by themselfes how to act on a + * program change event. + * + * @param Program - sampler channel to connect to this MIDI + * input device + * @param MidiChannel - MIDI channel on which sampler channel + * \a Program should listen to + */ + void DispatchProgramChange(uint8_t Program, uint MidiChannel); + + /** + * Should be called by the implementing MIDI input device + * whenever a system exclusive message arrived, this will cause + * the message to be forwarded to all connected engines. + * + * @param pData - pointer to the sysex data + * @param Size - length of the sysex data (in bytes) + */ + void DispatchSysex(void* pData, uint Size); + protected: MidiInputDevice* pDevice; int portNumber; std::map Parameters; ///< All port parameters. - std::set MidiChannelMap[17]; ///< Contains the list of connected engines for each MIDI channel, where index 0 points to the list of engines which are connected to all MIDI channels. Usually it's not necessary for the descendant to use this map, instead it should just use the Dispatch* methods. + std::set MidiChannelMap[17]; ///< Contains the list of connected engines for each MIDI channel, where index 0 points to the list of engines which are connected to all MIDI channels. Usually it's not necessary for the descendant to use this map, instead it should just use the Dispatch* methods. + Mutex MidiChannelMapMutex; ///< Used to protect the MidiChannelMap from being used at the same time by different threads. /** * Constructor @@ -192,6 +234,9 @@ virtual ~MidiInputPort(); friend class MidiInputDevice; + + private: + EngineChannel* pPreviousProgramChangeEngineChannel; ///< Points to the engine channel which was connected by the previous DispatchProgramChange() call. }; } // namsepace LinuxSampler