/[svn]/linuxsampler/trunk/src/engines/EngineChannel.cpp
ViewVC logotype

Diff of /linuxsampler/trunk/src/engines/EngineChannel.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 947 by schoenebeck, Mon Nov 27 21:34:55 2006 UTC revision 1044 by schoenebeck, Wed Feb 7 21:51:19 2007 UTC
# Line 3  Line 3 
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, 2006 Christian Schoenebeck                        *   *   Copyright (C) 2005 - 2007 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  *
# Line 23  Line 23 
23    
24  #include "EngineChannel.h"  #include "EngineChannel.h"
25    
26    #include <algorithm>
27    
28    #include "../drivers/midi/MidiInstrumentMapper.h"
29    
30    #define NO_MIDI_INSTRUMENT_MAP          -1
31    #define DEFAULT_MIDI_INSTRUMENT_MAP     -2
32    
33  namespace LinuxSampler {  namespace LinuxSampler {
34    
35      EngineChannel::EngineChannel() {      EngineChannel::EngineChannel() {
# Line 31  namespace LinuxSampler { Line 38  namespace LinuxSampler {
38          uiMidiBankMsb = 0;          uiMidiBankMsb = 0;
39          uiMidiBankLsb = 0;          uiMidiBankLsb = 0;
40          uiMidiProgram = 0;          uiMidiProgram = 0;
41            bProgramChangeReceived = bMidiBankMsbReceived = bMidiBankLsbReceived = false;
42            iMidiInstrumentMap = NO_MIDI_INSTRUMENT_MAP;
43            ResetMidiRpnController();
44      }      }
45    
46      void EngineChannel::SetMute(int state) throw (Exception) {      void EngineChannel::SetMute(int state) throw (Exception) {
# Line 57  namespace LinuxSampler { Line 67  namespace LinuxSampler {
67          return bSolo;          return bSolo;
68      }      }
69    
70        /*
71           We use a workaround for MIDI devices (i.e. old keyboards) which either
72           only send bank select MSB or only bank select LSB messages. Bank
73           selects will be modified according to the following table:
74    
75           MIDI Sequence received:            -> GetMidiBankMsb()= | GetMidiBankLsb()=
76           ---------------------------------------------------------------------------
77           program change                     ->        0          |        0
78           bank LSB, program change           ->        0          |     LSB value
79           bank MSB, program change           ->        0          |     MSB value
80           bank LSB, bank MSB, program change ->     MSB value     |     LSB value
81           bank MSB, bank LSB, program change ->     MSB value     |     LSB value
82           ---------------------------------------------------------------------------
83    
84           That way we ensure those limited devices always to switch between the
85           following set of MIDI instrument banks:  { 0, 1, 2, ..., 127 }
86        */
87    
88      uint8_t EngineChannel::GetMidiProgram() {      uint8_t EngineChannel::GetMidiProgram() {
89          return uiMidiProgram; // AFAIK atomic on all systems          return uiMidiProgram; // AFAIK atomic on all systems
90      }      }
91    
92      void EngineChannel::SetMidiProgram(uint8_t Program) {      void EngineChannel::SetMidiProgram(uint8_t Program) {
93            bProgramChangeReceived = true;
94          uiMidiProgram = Program; // AFAIK atomic on all systems          uiMidiProgram = Program; // AFAIK atomic on all systems
95      }      }
96    
97      uint8_t EngineChannel::GetMidiBankMsb() {      uint8_t EngineChannel::GetMidiBankMsb() {
98          return uiMidiBankMsb; // AFAIK atomic on all systems          return (bMidiBankMsbReceived && bMidiBankLsbReceived) ? uiMidiBankMsb : 0;
99      }      }
100    
101      void EngineChannel::SetMidiBankMsb(uint8_t BankMSB) {      void EngineChannel::SetMidiBankMsb(uint8_t BankMSB) {
102            if (bProgramChangeReceived)
103                bProgramChangeReceived = bMidiBankLsbReceived = false;
104            bMidiBankMsbReceived = true;
105          uiMidiBankMsb = BankMSB; // AFAIK atomic on all systems          uiMidiBankMsb = BankMSB; // AFAIK atomic on all systems
106      }      }
107    
108      uint8_t EngineChannel::GetMidiBankLsb() {      uint8_t EngineChannel::GetMidiBankLsb() {
109          return uiMidiBankLsb; // AFAIK atomic on all systems          return (!bMidiBankMsbReceived && !bMidiBankLsbReceived)
110                       ? 0
111                       : (bMidiBankMsbReceived && !bMidiBankLsbReceived)
112                             ? uiMidiBankMsb
113                             : uiMidiBankLsb;
114      }      }
115    
116      void EngineChannel::SetMidiBankLsb(uint8_t BankLSB) {      void EngineChannel::SetMidiBankLsb(uint8_t BankLSB) {
117            if (bProgramChangeReceived)
118                bProgramChangeReceived = bMidiBankMsbReceived = false;
119            bMidiBankLsbReceived = true;
120          uiMidiBankLsb = BankLSB; // AFAIK atomic on all systems          uiMidiBankLsb = BankLSB; // AFAIK atomic on all systems
121      }      }
122    
123        bool EngineChannel::UsesNoMidiInstrumentMap() {
124            return (iMidiInstrumentMap == NO_MIDI_INSTRUMENT_MAP);
125        }
126    
127        bool EngineChannel::UsesDefaultMidiInstrumentMap() {
128            return (iMidiInstrumentMap == DEFAULT_MIDI_INSTRUMENT_MAP);
129        }
130    
131        int EngineChannel::GetMidiInstrumentMap() throw (Exception) {
132            if (UsesNoMidiInstrumentMap())
133                throw Exception("EngineChannel is using no MIDI instrument map");
134            if (UsesDefaultMidiInstrumentMap())
135                throw Exception("EngineChannel is using default MIDI instrument map");
136            // check if the stored map still exists in the MIDI instrument mapper
137            std::vector<int> maps = MidiInstrumentMapper::Maps();
138            if (find(maps.begin(), maps.end(), iMidiInstrumentMap) == maps.end()) {
139                // it doesn't exist anymore, so fall back to NONE and throw an exception
140                iMidiInstrumentMap = NO_MIDI_INSTRUMENT_MAP;
141                throw Exception("Assigned MIDI instrument map doesn't exist anymore, falling back to NONE");
142            }
143            return iMidiInstrumentMap;
144        }
145    
146        void EngineChannel::SetMidiInstrumentMapToNone() {
147            iMidiInstrumentMap = NO_MIDI_INSTRUMENT_MAP;
148        }
149    
150        void EngineChannel::SetMidiInstrumentMapToDefault() {
151            iMidiInstrumentMap = DEFAULT_MIDI_INSTRUMENT_MAP;
152        }
153    
154        void EngineChannel::SetMidiInstrumentMap(int MidiMap) throw (Exception) {
155            // check if given map actually exists in the MIDI instrument mapper
156            std::vector<int> maps = MidiInstrumentMapper::Maps();
157            if (find(maps.begin(), maps.end(), MidiMap) == maps.end())
158                throw Exception("MIDI instrument map doesn't exist");
159            iMidiInstrumentMap = MidiMap; // assign the new map ID
160        }
161    
162        void EngineChannel::SetMidiRpnControllerMsb(uint8_t CtrlMSB) {
163            uiMidiRpnMsb = CtrlMSB;
164            bMidiRpnReceived = true;
165        }
166    
167        void EngineChannel::SetMidiRpnControllerLsb(uint8_t CtrlLSB) {
168            uiMidiRpnLsb = CtrlLSB;
169            bMidiRpnReceived = true;
170        }
171    
172        void EngineChannel::ResetMidiRpnController() {
173            uiMidiRpnMsb = uiMidiRpnLsb = 0;
174            bMidiRpnReceived = false;
175        }
176    
177        int EngineChannel::GetMidiRpnController() {
178            return (bMidiRpnReceived) ? (uiMidiRpnMsb << 8) | uiMidiRpnLsb : -1;
179        }
180    
181  } // namespace LinuxSampler  } // namespace LinuxSampler

Legend:
Removed from v.947  
changed lines
  Added in v.1044

  ViewVC Help
Powered by ViewVC