34 |
#endif |
#endif |
35 |
|
|
36 |
#include "PluginVst.h" |
#include "PluginVst.h" |
37 |
|
#include "../../drivers/midi/MidiInstrumentMapper.h" |
38 |
|
|
39 |
#ifndef CHANNELS |
#ifndef CHANNELS |
40 |
#define CHANNELS 32 |
#define CHANNELS 32 |
41 |
#endif |
#endif |
42 |
|
|
43 |
|
// the sampler can actually hold up a very huge amount of programs |
44 |
|
// (2^32 [maps] * 2^16 [banks MSB + LSB] * 2^8 [programs per bank] = 2^56 [total programs] ) |
45 |
|
// however I am not sure if we might crash some VST host with a number |
46 |
|
// here that is too huge, however this should be enough in most cases ... |
47 |
|
#define MAX_VST_PROGRAMS (128*128) |
48 |
|
|
49 |
|
using namespace LinuxSampler; |
50 |
|
|
51 |
namespace { |
namespace { |
52 |
|
|
53 |
#if defined(WIN32) && CONFIG_DEBUG_LEVEL >= 2 |
#if defined(WIN32) && CONFIG_DEBUG_LEVEL >= 2 |
72 |
#endif |
#endif |
73 |
|
|
74 |
|
|
|
// *************** LinuxSamplerVstProgram *************** |
|
|
// * |
|
|
|
|
|
LinuxSamplerVstProgram::LinuxSamplerVstProgram() { |
|
|
vst_strncpy(name, "Basic", kVstMaxProgNameLen); |
|
|
} |
|
|
|
|
|
|
|
75 |
// *************** LinuxSamplerEditor *************** |
// *************** LinuxSamplerEditor *************** |
76 |
// * |
// * |
77 |
|
|
256 |
// * |
// * |
257 |
|
|
258 |
LinuxSamplerVst::LinuxSamplerVst(audioMasterCallback audioMaster) : |
LinuxSamplerVst::LinuxSamplerVst(audioMasterCallback audioMaster) : |
259 |
AudioEffectX(audioMaster, NbPrograms, 0), |
AudioEffectX(audioMaster, MAX_VST_PROGRAMS, 0), |
260 |
StateBuf(0) |
StateBuf(0) |
261 |
{ |
{ |
262 |
dmsg(2, ("-->constructor\n")); |
dmsg(2, ("-->constructor\n")); |
263 |
|
|
|
Programs = new LinuxSamplerVstProgram[NbPrograms]; |
|
264 |
setProgram(0); |
setProgram(0); |
265 |
setNumInputs(0); |
setNumInputs(0); |
266 |
setNumOutputs(CHANNELS); |
setNumOutputs(CHANNELS); |
300 |
|
|
301 |
LinuxSamplerVst::~LinuxSamplerVst() { |
LinuxSamplerVst::~LinuxSamplerVst() { |
302 |
dmsg(2, ("-->destructor\n")); |
dmsg(2, ("-->destructor\n")); |
|
delete[] Programs; |
|
303 |
if (StateBuf) free(StateBuf); |
if (StateBuf) free(StateBuf); |
304 |
dmsg(2, ("<--destructor\n")); |
dmsg(2, ("<--destructor\n")); |
305 |
} |
} |
306 |
|
|
307 |
|
|
308 |
void LinuxSamplerVst::setProgram(VstInt32 program) { |
void LinuxSamplerVst::setProgram(VstInt32 program) { |
309 |
if (program < 0 || program >= NbPrograms) return; |
if (program < 0 || program >= MAX_VST_PROGRAMS || |
310 |
|
!pMidiDevice || !pMidiDevice->Port()) return; |
311 |
curProgram = program; |
|
312 |
|
int i = 0; |
313 |
|
const std::vector<int> maps = MidiInstrumentMapper::Maps(); |
314 |
|
for (int iMap = 0; iMap < maps.size(); ++iMap) { |
315 |
|
const int mapID = maps[iMap]; |
316 |
|
const std::map<midi_prog_index_t, MidiInstrumentMapper::entry_t> mappings = |
317 |
|
MidiInstrumentMapper::Entries(maps[mapID]); |
318 |
|
for (std::map<midi_prog_index_t, MidiInstrumentMapper::entry_t>::const_iterator iter = mappings.begin(); |
319 |
|
iter != mappings.end(); ++iter, ++i) |
320 |
|
{ |
321 |
|
if (i == program) { |
322 |
|
//TODO: switch MIDI instrument map before sending bank select and program change |
323 |
|
|
324 |
|
const uint iMIDIChannel = 0; |
325 |
|
pMidiDevice->Port()->DispatchBankSelectMsb(iter->first.midi_bank_msb, iMIDIChannel); |
326 |
|
pMidiDevice->Port()->DispatchBankSelectLsb(iter->first.midi_bank_lsb, iMIDIChannel); |
327 |
|
pMidiDevice->Port()->DispatchProgramChange(iter->first.midi_prog, iMIDIChannel); |
328 |
|
|
329 |
|
curProgram = program; |
330 |
|
|
331 |
|
return; |
332 |
|
} |
333 |
|
} |
334 |
|
} |
335 |
} |
} |
336 |
|
|
|
|
|
337 |
void LinuxSamplerVst::setProgramName(char* name) { |
void LinuxSamplerVst::setProgramName(char* name) { |
338 |
vst_strncpy(Programs[curProgram].name, name, kVstMaxProgNameLen); |
int i = 0; |
339 |
|
const std::vector<int> maps = MidiInstrumentMapper::Maps(); |
340 |
|
for (int iMap = 0; iMap < maps.size(); ++iMap) { |
341 |
|
const int mapID = maps[iMap]; |
342 |
|
const std::map<midi_prog_index_t, MidiInstrumentMapper::entry_t> mappings = |
343 |
|
MidiInstrumentMapper::Entries(maps[mapID]); |
344 |
|
for (std::map<midi_prog_index_t, MidiInstrumentMapper::entry_t>::const_iterator iter = mappings.begin(); |
345 |
|
iter != mappings.end(); ++iter, ++i) |
346 |
|
{ |
347 |
|
if (i == curProgram) { |
348 |
|
char buf[kVstMaxProgNameLen + 1] = {}; |
349 |
|
vst_strncpy(buf, name, kVstMaxProgNameLen); |
350 |
|
MidiInstrumentMapper::entry_t entry = iter->second; |
351 |
|
entry.Name = buf; |
352 |
|
try { |
353 |
|
MidiInstrumentMapper::AddOrReplaceEntry( |
354 |
|
mapID, iter->first, entry, false/*bInBackground*/ |
355 |
|
); |
356 |
|
} catch (Exception e) { |
357 |
|
e.PrintMessage(); |
358 |
|
} |
359 |
|
return; |
360 |
|
} |
361 |
|
} |
362 |
|
} |
363 |
} |
} |
364 |
|
|
|
|
|
365 |
void LinuxSamplerVst::getProgramName(char* name) { |
void LinuxSamplerVst::getProgramName(char* name) { |
366 |
vst_strncpy(name, Programs[curProgram].name, kVstMaxProgNameLen); |
if (!getProgramNameIndexed(0 /*dont care*/, curProgram, name)) { |
367 |
|
vst_strncpy(name, "unknown", kVstMaxProgNameLen); |
368 |
|
} |
369 |
|
} |
370 |
|
|
371 |
|
bool LinuxSamplerVst::getProgramNameIndexed(VstInt32 /*category*/, VstInt32 index, |
372 |
|
char* text) |
373 |
|
{ |
374 |
|
//NOTE: parameter 'category' is unused in VST 2.4 |
375 |
|
|
376 |
|
int i = 0; |
377 |
|
const std::vector<int> maps = MidiInstrumentMapper::Maps(); |
378 |
|
for (int iMap = 0; iMap < maps.size(); ++iMap) { |
379 |
|
const int mapID = maps[iMap]; |
380 |
|
const std::map<midi_prog_index_t, MidiInstrumentMapper::entry_t> mappings = |
381 |
|
MidiInstrumentMapper::Entries(maps[mapID]); |
382 |
|
for (std::map<midi_prog_index_t, MidiInstrumentMapper::entry_t>::const_iterator iter = mappings.begin(); |
383 |
|
iter != mappings.end(); ++iter, ++i) |
384 |
|
{ |
385 |
|
if (i == index) { |
386 |
|
vst_strncpy(text, iter->second.Name.c_str(), kVstMaxProgNameLen); |
387 |
|
return true; |
388 |
|
} |
389 |
|
} |
390 |
|
} |
391 |
|
return false; |
392 |
} |
} |
393 |
|
|
394 |
|
|
403 |
} |
} |
404 |
|
|
405 |
|
|
|
bool LinuxSamplerVst::getProgramNameIndexed(VstInt32 category, VstInt32 index, |
|
|
char* text) { |
|
|
if (index < NbPrograms) { |
|
|
vst_strncpy(text, Programs[index].name, kVstMaxProgNameLen); |
|
|
return true; |
|
|
} |
|
|
return false; |
|
|
} |
|
|
|
|
|
|
|
406 |
bool LinuxSamplerVst::getEffectName(char* name) { |
bool LinuxSamplerVst::getEffectName(char* name) { |
407 |
vst_strncpy(name, "LinuxSampler", kVstMaxEffectNameLen); |
vst_strncpy(name, "LinuxSampler", kVstMaxEffectNameLen); |
408 |
return true; |
return true; |
428 |
|
|
429 |
VstInt32 LinuxSamplerVst::canDo(char* text) { |
VstInt32 LinuxSamplerVst::canDo(char* text) { |
430 |
dmsg(2, ("canDo %s\n", text)); |
dmsg(2, ("canDo %s\n", text)); |
431 |
|
|
432 |
|
// supported features |
433 |
if (strcmp(text, "receiveVstEvents") == 0 || |
if (strcmp(text, "receiveVstEvents") == 0 || |
434 |
strcmp(text, "receiveVstMidiEvent") == 0) return 1; |
strcmp(text, "receiveVstMidiEvent") == 0 || |
435 |
return -1; |
strcmp(text, "midiProgramNames") == 0) return 1; |
436 |
|
|
437 |
|
// not supported features |
438 |
|
if (strcmp(text, "sendVstEvents") == 0 || |
439 |
|
strcmp(text, "sendVstMidiEvent") == 0 || |
440 |
|
strcmp(text, "receiveVstTimeInfo") == 0 || |
441 |
|
strcmp(text, "offline") == 0 || |
442 |
|
strcmp(text, "bypass") == 0) return -1; |
443 |
|
|
444 |
|
return 0; // "don't know", never heard of this feature |
445 |
} |
} |
446 |
|
|
447 |
void LinuxSamplerVst::setSampleRate(float sampleRate) { |
void LinuxSamplerVst::setSampleRate(float sampleRate) { |