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-2008 Christian Schoenebeck * |
* Copyright (C) 2005-2008 Christian Schoenebeck * |
7 |
* Copyright (C) 2009-2010 Christian Schoenebeck and Grigor Iliev * |
* Copyright (C) 2009-2012 Christian Schoenebeck and Grigor Iliev * |
8 |
|
* Copyright (C) 2013-2014 Christian Schoenebeck and Andreas Persson * |
9 |
* * |
* * |
10 |
* This program is free software; you can redistribute it and/or modify * |
* This program is free software; you can redistribute it and/or modify * |
11 |
* 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 "AbstractEngineChannel.h" |
#include "AbstractEngineChannel.h" |
28 |
#include "EngineFactory.h" |
#include "EngineFactory.h" |
29 |
#include "../common/global_private.h" |
#include "../common/global_private.h" |
30 |
|
#include "../effects/EffectFactory.h" |
31 |
|
|
32 |
namespace LinuxSampler { |
namespace LinuxSampler { |
33 |
|
|
35 |
|
|
36 |
std::map<AbstractEngine::Format, std::map<AudioOutputDevice*,AbstractEngine*> > AbstractEngine::engines; |
std::map<AbstractEngine::Format, std::map<AudioOutputDevice*,AbstractEngine*> > AbstractEngine::engines; |
37 |
|
|
38 |
|
VMParserContext* AbstractEngine::ScriptResourceManager::Create(String Key, ScriptConsumer* pConsumer, void*& pArg) { |
39 |
|
return parent->pScriptVM->loadScript(Key); |
40 |
|
} |
41 |
|
|
42 |
|
void AbstractEngine::ScriptResourceManager::Destroy(VMParserContext* pResource, void* pArg) { |
43 |
|
delete pResource; |
44 |
|
} |
45 |
|
|
46 |
/** |
/** |
47 |
* Get an AbstractEngine object for the given AbstractEngineChannel and the |
* Get an AbstractEngine object for the given AbstractEngineChannel and the |
48 |
* given AudioOutputDevice. All engine channels which are connected to |
* given AudioOutputDevice. All engine channels which are connected to |
80 |
return pEngine; |
return pEngine; |
81 |
} |
} |
82 |
|
|
83 |
AbstractEngine::AbstractEngine() { |
AbstractEngine::AbstractEngine() : scripts(this) { |
84 |
pAudioOutputDevice = NULL; |
pAudioOutputDevice = NULL; |
85 |
pEventGenerator = NULL; |
pEventGenerator = NULL; |
86 |
pSysexBuffer = new RingBuffer<uint8_t,false>(CONFIG_SYSEX_BUFFER_SIZE, 0); |
pSysexBuffer = new RingBuffer<uint8_t,false>(CONFIG_SYSEX_BUFFER_SIZE, 0); |
90 |
FrameTime = 0; |
FrameTime = 0; |
91 |
RandomSeed = 0; |
RandomSeed = 0; |
92 |
pDedicatedVoiceChannelLeft = pDedicatedVoiceChannelRight = NULL; |
pDedicatedVoiceChannelLeft = pDedicatedVoiceChannelRight = NULL; |
93 |
|
pScriptVM = new InstrumentScriptVM; |
94 |
} |
} |
95 |
|
|
96 |
AbstractEngine::~AbstractEngine() { |
AbstractEngine::~AbstractEngine() { |
101 |
if (pSysexBuffer) delete pSysexBuffer; |
if (pSysexBuffer) delete pSysexBuffer; |
102 |
if (pDedicatedVoiceChannelLeft) delete pDedicatedVoiceChannelLeft; |
if (pDedicatedVoiceChannelLeft) delete pDedicatedVoiceChannelLeft; |
103 |
if (pDedicatedVoiceChannelRight) delete pDedicatedVoiceChannelRight; |
if (pDedicatedVoiceChannelRight) delete pDedicatedVoiceChannelRight; |
104 |
|
if (pScriptVM) delete pScriptVM; |
105 |
Unregister(); |
Unregister(); |
106 |
} |
} |
107 |
|
|
176 |
*/ |
*/ |
177 |
void AbstractEngine::ResetScaleTuning() { |
void AbstractEngine::ResetScaleTuning() { |
178 |
memset(&ScaleTuning[0], 0x00, 12); |
memset(&ScaleTuning[0], 0x00, 12); |
179 |
|
ScaleTuningChanged.raise(); |
180 |
} |
} |
181 |
|
|
182 |
/** |
/** |
358 |
*/ |
*/ |
359 |
uint8_t AbstractEngine::GSCheckSum(const RingBuffer<uint8_t,false>::NonVolatileReader AddrReader, uint DataSize) { |
uint8_t AbstractEngine::GSCheckSum(const RingBuffer<uint8_t,false>::NonVolatileReader AddrReader, uint DataSize) { |
360 |
RingBuffer<uint8_t,false>::NonVolatileReader reader = AddrReader; |
RingBuffer<uint8_t,false>::NonVolatileReader reader = AddrReader; |
361 |
uint bytes = 3 /*addr*/ + DataSize; |
uint bytes = 3 /*addr*/ + DataSize; |
|
uint8_t addr_and_data[bytes]; |
|
|
reader.read(&addr_and_data[0], bytes); |
|
362 |
uint8_t sum = 0; |
uint8_t sum = 0; |
363 |
for (uint i = 0; i < bytes; i++) sum += addr_and_data[i]; |
uint8_t c; |
364 |
|
for (uint i = 0; i < bytes; ++i) { |
365 |
|
if (!reader.pop(&c)) break; |
366 |
|
sum += c; |
367 |
|
} |
368 |
return 128 - sum % 128; |
return 128 - sum % 128; |
369 |
} |
} |
370 |
|
|
373 |
* |
* |
374 |
* @param ScaleTunes - detuning of all twelve semitones (in cents) |
* @param ScaleTunes - detuning of all twelve semitones (in cents) |
375 |
*/ |
*/ |
376 |
void AbstractEngine::AdjustScale(int8_t ScaleTunes[12]) { |
void AbstractEngine::AdjustScaleTuning(const int8_t ScaleTunes[12]) { |
377 |
memcpy(&this->ScaleTuning[0], &ScaleTunes[0], 12); //TODO: currently not sample accurate |
memcpy(&this->ScaleTuning[0], &ScaleTunes[0], 12); |
378 |
|
ScaleTuningChanged.raise(); |
379 |
|
} |
380 |
|
|
381 |
|
void AbstractEngine::GetScaleTuning(int8_t* pScaleTunes) { |
382 |
|
memcpy(pScaleTunes, &this->ScaleTuning[0], 12); |
383 |
} |
} |
384 |
|
|
385 |
uint AbstractEngine::VoiceCount() { |
uint AbstractEngine::VoiceCount() { |
395 |
} |
} |
396 |
|
|
397 |
/** |
/** |
398 |
* Moves pitchbend event from the general (input) event list to the engine |
* Stores the latest pitchbend event as current pitchbend scalar value. |
|
* channel's event list. It will actually processed later by the |
|
|
* respective voice. |
|
399 |
* |
* |
400 |
* @param pEngineChannel - engine channel on which this event occured on |
* @param pEngineChannel - engine channel on which this event occured on |
401 |
* @param itPitchbendEvent - absolute pitch value and time stamp of the event |
* @param itPitchbendEvent - absolute pitch value and time stamp of the event |
524 |
for (int i = 0; i < engineChannels.size(); ++i) { |
for (int i = 0; i < engineChannels.size(); ++i) { |
525 |
AbstractEngineChannel* pEngineChannel |
AbstractEngineChannel* pEngineChannel |
526 |
= static_cast<AbstractEngineChannel*>(engineChannels[i]); |
= static_cast<AbstractEngineChannel*>(engineChannels[i]); |
527 |
if (pEngineChannel->GetMidiInputPort() == itSysexEvent->pMidiInputPort) { |
Sync< ArrayList<MidiInputPort*> > midiInputs = pEngineChannel->midiInputs.front(); |
528 |
KillAllVoices(pEngineChannel, itSysexEvent); |
for (int k = 0; k < midiInputs->size(); ++k) { |
529 |
pEngineChannel->ResetControllers(); |
if ((*midiInputs)[k] == itSysexEvent->pMidiInputPort) { |
530 |
|
KillAllVoices(pEngineChannel, itSysexEvent); |
531 |
|
pEngineChannel->ResetControllers(); |
532 |
|
break; |
533 |
|
} |
534 |
} |
} |
535 |
} |
} |
536 |
} |
} |
551 |
if (GSCheckSum(checksum_reader, 12)) goto free_sysex_data; |
if (GSCheckSum(checksum_reader, 12)) goto free_sysex_data; |
552 |
#endif // CONFIG_ASSERT_GS_SYSEX_CHECKSUM |
#endif // CONFIG_ASSERT_GS_SYSEX_CHECKSUM |
553 |
for (int i = 0; i < 12; i++) scale_tunes[i] -= 64; |
for (int i = 0; i < 12; i++) scale_tunes[i] -= 64; |
554 |
AdjustScale((int8_t*) scale_tunes); |
AdjustScaleTuning((int8_t*) scale_tunes); |
555 |
dmsg(3,("\t\t\tNew scale applied.\n")); |
dmsg(3,("\t\t\tNew scale applied.\n")); |
556 |
break; |
break; |
557 |
} |
} |
563 |
for (int i = 0; i < engineChannels.size(); ++i) { |
for (int i = 0; i < engineChannels.size(); ++i) { |
564 |
AbstractEngineChannel* pEngineChannel |
AbstractEngineChannel* pEngineChannel |
565 |
= static_cast<AbstractEngineChannel*>(engineChannels[i]); |
= static_cast<AbstractEngineChannel*>(engineChannels[i]); |
566 |
if ( |
if (pEngineChannel->midiChannel == part || |
567 |
(pEngineChannel->midiChannel == part || |
pEngineChannel->midiChannel == midi_chan_all) |
568 |
pEngineChannel->midiChannel == midi_chan_all) && |
{ |
569 |
pEngineChannel->GetMidiInputPort() == itSysexEvent->pMidiInputPort |
Sync< ArrayList<MidiInputPort*> > midiInputs = pEngineChannel->midiInputs.front(); |
570 |
) { |
for (int k = 0; k < midiInputs->size(); ++k) { |
571 |
try { |
if ((*midiInputs)[k] == itSysexEvent->pMidiInputPort) { |
572 |
pEngineChannel->SetMidiInstrumentMap(map); |
try { |
573 |
} catch (Exception e) { |
pEngineChannel->SetMidiInstrumentMap(map); |
574 |
dmsg(2,("\t\t\tCould not apply MIDI instrument map %d to part %d: %s\n", map, part, e.Message().c_str())); |
} catch (Exception e) { |
575 |
goto free_sysex_data; |
dmsg(2,("\t\t\tCould not apply MIDI instrument map %d to part %d: %s\n", map, part, e.Message().c_str())); |
576 |
} catch (...) { |
goto free_sysex_data; |
577 |
dmsg(2,("\t\t\tCould not apply MIDI instrument map %d to part %d (unknown exception)\n", map, part)); |
} catch (...) { |
578 |
goto free_sysex_data; |
dmsg(2,("\t\t\tCould not apply MIDI instrument map %d to part %d (unknown exception)\n", map, part)); |
579 |
|
goto free_sysex_data; |
580 |
|
} |
581 |
|
break; |
582 |
|
} |
583 |
} |
} |
584 |
} |
} |
585 |
} |
} |