--- gigedit/trunk/src/plugin/linuxsamplerplugin.cpp 2008/02/04 00:40:03 1664 +++ gigedit/trunk/src/plugin/linuxsamplerplugin.cpp 2015/08/30 10:00:49 2841 @@ -1,5 +1,5 @@ /* - * Copyright (C) 2007, 2008 Andreas Persson + * Copyright (C) 2007 - 2015 Andreas Persson * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -20,7 +20,10 @@ #include "linuxsamplerplugin.h" #include +#include +#include #include "../gigedit/gigedit.h" +#include "../gigedit/global.h" #include #include @@ -33,13 +36,17 @@ } LinuxSamplerPlugin::~LinuxSamplerPlugin() { - if (pApp) delete (GigEdit*) pApp; + if (pApp) delete static_cast(pApp); +} + +int LinuxSamplerPlugin::Main(void* pInstrument, String sTypeName, String sTypeVersion, void* /*pUserData*/) { + return Main(pInstrument, sTypeName, sTypeVersion); } int LinuxSamplerPlugin::Main(void* pInstrument, String sTypeName, String sTypeVersion) { std::cout << "Entered Gigedit Main() loop :)\n" << std::flush; gig::Instrument* pGigInstr = static_cast(pInstrument); - GigEdit* app = (GigEdit*) pApp; + GigEdit* app = static_cast(pApp); // connect notification signals app->signal_file_structure_to_be_changed().connect( @@ -96,6 +103,14 @@ "gig::DimensionRegion" ) ); + app->signal_sample_changed().connect( + sigc::bind( + sigc::mem_fun( + *this, &LinuxSamplerPlugin::NotifyDataStructureChanged + ), + "gig::Sample" + ) + ); app->signal_sample_ref_changed().connect( sigc::mem_fun(*this, &LinuxSamplerPlugin::NotifySampleReferenceChanged) ); @@ -106,6 +121,9 @@ app->signal_keyboard_key_released().connect( sigc::mem_fun(*this, &LinuxSamplerPlugin::__onVirtualKeyboardKeyReleased) ); + app->signal_switch_sampler_instrument().connect( + sigc::mem_fun(*this, &LinuxSamplerPlugin::__requestSamplerToSwitchInstrument) + ); // register a timeout job to gigedit's main loop, so we can poll the // the sampler periodically for MIDI events (I HOPE it works on all @@ -123,7 +141,8 @@ } bool LinuxSamplerPlugin::__onPollPeriod() { - GigEdit* app = (GigEdit*) pApp; + #if HAVE_LINUXSAMPLER_VIRTUAL_MIDI_DEVICE + GigEdit* app = static_cast(pApp); if (!NotesChanged()) return true; for (int iKey = 0; iKey < 128; iKey++) if (NoteChanged(iKey)) @@ -131,6 +150,9 @@ app->on_note_on_event(iKey, NoteOnVelocity(iKey)) : app->on_note_off_event(iKey, NoteOffVelocity(iKey)); return true; + #else + return false; + #endif } void LinuxSamplerPlugin::__onSamplesToBeRemoved(std::list lSamples) { @@ -138,18 +160,52 @@ std::set samples; for ( std::list::iterator iter = lSamples.begin(); - iter != lSamples.end(); iter++ + iter != lSamples.end(); ++iter ) samples.insert((void*)*iter); // finally send notification to sampler NotifySamplesToBeRemoved(samples); } void LinuxSamplerPlugin::__onVirtualKeyboardKeyHit(int Key, int Velocity) { + #if HAVE_LINUXSAMPLER_VIRTUAL_MIDI_DEVICE SendNoteOnToSampler(Key, Velocity); + #endif } void LinuxSamplerPlugin::__onVirtualKeyboardKeyReleased(int Key, int Velocity) { + #if HAVE_LINUXSAMPLER_VIRTUAL_MIDI_DEVICE SendNoteOffToSampler(Key, Velocity); + #endif +} + +void LinuxSamplerPlugin::__requestSamplerToSwitchInstrument(gig::Instrument* pInstrument) { + if (!pInstrument) return; + + LinuxSampler::EngineChannel* pEngineChannel = GetEngineChannel(); + if (!pEngineChannel) return; + + LinuxSampler::Engine* pEngine = pEngineChannel->GetEngine(); + if (!pEngine) return; + + LinuxSampler::InstrumentManager* pInstrumentManager = pEngine->GetInstrumentManager(); + if (!pInstrumentManager) return; + + gig::File* pFile = (gig::File*) pInstrument->GetParent(); + + // resolve instrument's index number in its gig file + int index = -1; + for (int i = 0; pFile->GetInstrument(i); ++i) { + if (pFile->GetInstrument(i) == pInstrument) { + index = i; + break; + } + } + if (index < 0) return; + + LinuxSampler::InstrumentManager::instrument_id_t id; + id.FileName = pFile->GetFileName(); + id.Index = index; + pInstrumentManager->LoadInstrumentInBackground(id, pEngineChannel); } bool LinuxSamplerPlugin::IsTypeSupported(String sTypeName, String sTypeVersion) {