1 /* 2 * Copyright (c) 2002-2004 Matthijs Hollemans 3 * Copyright (c) 2003 Jerome Leveque 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining a 6 * copy of this software and associated documentation files (the "Software"), 7 * to deal in the Software without restriction, including without limitation 8 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 * and/or sell copies of the Software, and to permit persons to whom the 10 * Software is furnished to do so, subject to the following conditions: 11 * 12 * The above copyright notice and this permission notice shall be included in 13 * all copies or substantial portions of the Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21 * DEALINGS IN THE SOFTWARE. 22 */ 23 24 #include <MidiSynth.h> 25 26 #include "debug.h" 27 #include "SoftSynth.h" 28 29 using namespace BPrivate; 30 31 //------------------------------------------------------------------------------ 32 33 BMidiSynth::BMidiSynth() 34 { 35 if (be_synth == NULL) 36 { 37 new BSynth(); 38 } 39 40 be_synth->clientCount++; 41 42 inputEnabled = false; 43 transpose = 0; 44 creationTime = system_time(); 45 } 46 47 //------------------------------------------------------------------------------ 48 49 BMidiSynth::~BMidiSynth() 50 { 51 be_synth->clientCount--; 52 } 53 54 //------------------------------------------------------------------------------ 55 56 status_t BMidiSynth::EnableInput(bool enable, bool loadInstruments) 57 { 58 status_t err = B_OK; 59 inputEnabled = enable; 60 61 if (loadInstruments) 62 { 63 err = be_synth->synth->LoadAllInstruments(); 64 } 65 66 return err; 67 } 68 69 //------------------------------------------------------------------------------ 70 71 bool BMidiSynth::IsInputEnabled(void) const 72 { 73 return inputEnabled; 74 } 75 76 //------------------------------------------------------------------------------ 77 78 void BMidiSynth::SetVolume(double volume) 79 { 80 be_synth->synth->SetVolume(volume); 81 } 82 83 //------------------------------------------------------------------------------ 84 85 double BMidiSynth::Volume(void) const 86 { 87 return be_synth->synth->Volume(); 88 } 89 90 //------------------------------------------------------------------------------ 91 92 void BMidiSynth::SetTransposition(int16 offset) 93 { 94 transpose = offset; 95 } 96 97 //------------------------------------------------------------------------------ 98 99 int16 BMidiSynth::Transposition(void) const 100 { 101 return transpose; 102 } 103 104 //------------------------------------------------------------------------------ 105 106 void BMidiSynth::MuteChannel(int16 channel, bool do_mute) 107 { 108 fprintf(stderr, "[midi] MuteChannel is broken; don't use it\n"); 109 } 110 111 //------------------------------------------------------------------------------ 112 113 void BMidiSynth::GetMuteMap(char* pChannels) const 114 { 115 fprintf(stderr, "[midi] GetMuteMap is broken; don't use it\n"); 116 } 117 118 //------------------------------------------------------------------------------ 119 120 void BMidiSynth::SoloChannel(int16 channel, bool do_solo) 121 { 122 fprintf(stderr, "[midi] SoloChannel is broken; don't use it\n"); 123 } 124 125 //------------------------------------------------------------------------------ 126 127 void BMidiSynth::GetSoloMap(char* pChannels) const 128 { 129 fprintf(stderr, "[midi] GetSoloMap is broken; don't use it\n"); 130 } 131 132 //------------------------------------------------------------------------------ 133 134 status_t BMidiSynth::LoadInstrument(int16 instrument) 135 { 136 return be_synth->synth->LoadInstrument(instrument); 137 } 138 139 //------------------------------------------------------------------------------ 140 141 status_t BMidiSynth::UnloadInstrument(int16 instrument) 142 { 143 return be_synth->synth->UnloadInstrument(instrument); 144 } 145 146 //------------------------------------------------------------------------------ 147 148 status_t BMidiSynth::RemapInstrument(int16 from, int16 to) 149 { 150 return be_synth->synth->RemapInstrument(from, to); 151 } 152 153 //------------------------------------------------------------------------------ 154 155 void BMidiSynth::FlushInstrumentCache(bool startStopCache) 156 { 157 be_synth->synth->FlushInstrumentCache(startStopCache); 158 } 159 160 //------------------------------------------------------------------------------ 161 162 uint32 BMidiSynth::Tick(void) const 163 { 164 return (uint32) (system_time() - creationTime); 165 } 166 167 //------------------------------------------------------------------------------ 168 169 void BMidiSynth::NoteOff( 170 uchar channel, uchar note, uchar velocity, uint32 time) 171 { 172 if (inputEnabled) 173 { 174 be_synth->synth->NoteOff(channel, note + transpose, velocity, time); 175 } 176 } 177 178 //------------------------------------------------------------------------------ 179 180 void BMidiSynth::NoteOn( 181 uchar channel, uchar note, uchar velocity, uint32 time) 182 { 183 if (inputEnabled) 184 { 185 be_synth->synth->NoteOn(channel, note + transpose, velocity, time); 186 } 187 } 188 189 //------------------------------------------------------------------------------ 190 191 void BMidiSynth::KeyPressure( 192 uchar channel, uchar note, uchar pressure, uint32 time) 193 { 194 if (inputEnabled) 195 { 196 be_synth->synth->KeyPressure( 197 channel, note + transpose, pressure, time); 198 } 199 } 200 201 //------------------------------------------------------------------------------ 202 203 void BMidiSynth::ControlChange( 204 uchar channel, uchar controlNumber, uchar controlValue, uint32 time) 205 { 206 if (inputEnabled) 207 { 208 be_synth->synth->ControlChange( 209 channel, controlNumber, controlValue, time); 210 } 211 } 212 213 //------------------------------------------------------------------------------ 214 215 void BMidiSynth::ProgramChange( 216 uchar channel, uchar programNumber, uint32 time) 217 { 218 if (inputEnabled) 219 { 220 be_synth->synth->ProgramChange(channel, programNumber, time); 221 } 222 } 223 224 //------------------------------------------------------------------------------ 225 226 void BMidiSynth::ChannelPressure(uchar channel, uchar pressure, uint32 time) 227 { 228 if (inputEnabled) 229 { 230 be_synth->synth->ChannelPressure(channel, pressure, time); 231 } 232 } 233 234 //------------------------------------------------------------------------------ 235 236 void BMidiSynth::PitchBend(uchar channel, uchar lsb, uchar msb, uint32 time) 237 { 238 if (inputEnabled) 239 { 240 be_synth->synth->PitchBend(channel, lsb, msb, time); 241 } 242 } 243 244 //------------------------------------------------------------------------------ 245 246 void BMidiSynth::AllNotesOff(bool justChannel, uint32 time) 247 { 248 if (inputEnabled) 249 { 250 be_synth->synth->AllNotesOff(justChannel, time); 251 } 252 } 253 254 //------------------------------------------------------------------------------ 255 256 void BMidiSynth::_ReservedMidiSynth1() { } 257 void BMidiSynth::_ReservedMidiSynth2() { } 258 void BMidiSynth::_ReservedMidiSynth3() { } 259 void BMidiSynth::_ReservedMidiSynth4() { } 260 261 //------------------------------------------------------------------------------ 262 263 void BMidiSynth::Run() 264 { 265 // do nothing 266 } 267 268 //------------------------------------------------------------------------------ 269