diff options
-rw-r--r-- | vst/Makefile.mingw32 | 67 | ||||
-rw-r--r-- | vst/drumgizmo_vst.cc | 113 | ||||
-rw-r--r-- | vst/drumgizmo_vst.h | 7 | ||||
-rw-r--r-- | vst/input_vst.cc | 31 | ||||
-rw-r--r-- | vst/input_vst.h | 3 |
5 files changed, 180 insertions, 41 deletions
diff --git a/vst/Makefile.mingw32 b/vst/Makefile.mingw32 index e4f9127..8fd99b1 100644 --- a/vst/Makefile.mingw32 +++ b/vst/Makefile.mingw32 @@ -4,7 +4,9 @@ VST_SRC = \ ${VST_SRC_BASE}/audioeffectx.cpp \ ${VST_SRC_BASE}/audioeffect.cpp \ ${VST_SRC_BASE}/vstplugmain.cpp +VST_CFLAGS=-I$(VST_BASE) +top_srcdir=.. DG_BASE = .. DG_SRC = \ ${DG_BASE}/src/audiofile.cc \ @@ -13,6 +15,7 @@ DG_SRC = \ ${DG_BASE}/src/channelmixer.cc \ ${DG_BASE}/src/drumgizmo.cc \ ${DG_BASE}/src/drumkit.cc \ + ${DG_BASE}/src/drumkitloader.cc \ ${DG_BASE}/src/drumkitparser.cc \ ${DG_BASE}/src/events.cc \ ${DG_BASE}/src/instrument.cc \ @@ -23,8 +26,10 @@ DG_SRC = \ ${DG_BASE}/src/path.cc \ ${DG_BASE}/src/sample.cc \ ${DG_BASE}/src/saxparser.cc \ + ${DG_BASE}/src/semaphore.cc \ + ${DG_BASE}/src/thread.cc \ ${DG_BASE}/src/velocity.cc -DG_FLAGS = -I../include -I../src -DSSE -msse -msse2 +DG_CFLAGS = -I../include -I../src -DSSE -msse -msse2 GUI_SRC = \ $(DG_BASE)/plugingui/plugingui.cc \ @@ -33,6 +38,7 @@ GUI_SRC = \ $(DG_BASE)/plugingui/eventhandler.cc \ $(DG_BASE)/plugingui/font.cc \ $(DG_BASE)/plugingui/window.cc \ + $(DG_BASE)/plugingui/nativewindow_win32.cc \ $(DG_BASE)/plugingui/widget.cc \ $(DG_BASE)/plugingui/colour.cc \ $(DG_BASE)/plugingui/painter.cc \ @@ -44,42 +50,67 @@ GUI_SRC = \ $(DG_BASE)/plugingui/checkbox.cc \ $(DG_BASE)/plugingui/slider.cc -GUI_FLAGS=-lgdi32 -I../plugingui +GUI_CFLAGS=-I../plugingui -DUSE_THREAD +GUI_LIBS=-lgdi32 -lsetupapi -lws2_32 +DBG_SRC = \ + $(top_srcdir)/hugin/hugin.c \ + $(top_srcdir)/hugin/hugin_syslog.c + +DBG_CFLAGS=-I../hugin -DWITH_HUG_SYSLOG -DWITH_HUG_MUTEX # # http://old.nabble.com/using-VC%2B%2B-.lib-with-mingw-td23151303.html # Given `-lfoo', the win32 build of GNU ld will search for libfoo.a and foo.lib # EXPAT_BASE=c:/expat -EXPAT_FLAGS=-I${EXPAT_BASE}/Source/lib -L${EXPAT_BASE}/Bin -llibexpat +EXPAT_CFLAGS=-I${EXPAT_BASE}/Source/lib +EXPAT_LIBS=-L${EXPAT_BASE}/Bin -llibexpat SNDFILE_BASE=c:/libsndfile -SNDFILE_FLAGS=-I${SNDFILE_BASE}/include -L${SNDFILE_BASE}/lib -llibsndfile-1 +SNDFILE_CFLAGS=-I${SNDFILE_BASE}/include +SNDFILE_LIBS=-L${SNDFILE_BASE}/lib -llibsndfile-1 SRC = \ drumgizmo_vst.cc \ input_vst.cc \ output_vst.cc -all: - g++ -g -Wall -DWIN32 ${DG_FLAGS} -I${VST_BASE} ${DG_SRC} ${VST_SRC} ${SRC} ${GUI_SRC} ${GUI_FLAGS} ${EXPAT_FLAGS} ${SNDFILE_FLAGS} -shared -o drumgizmo_vst.dll -Wl,--out-implib,libdrumgizmo_vst.a - -clean: - rm -f drumgizmo_vst.dll libdrumgizmo_vst.a - -#LDFLAGS="-g -Wall -DWIN32 ${DG_FLAGS} ${EXPAT_FLAGS} ${SNDFILE_FLAGS} -I${VST_BASE}" -#CFLAGS=$(LDFLAGS) -#SOURCES="$(DG_SRC) $(VST_SRC) $(SRC)" -#OBJECTS=$(SOURCES:.cc=.o) +####################### +# +#CXXFLAGS=-DWIN32 $(EXPAT_CFLAGS) $(SNDFILE_CFLAGS) $(DG_CFLAGS) $(GUI_CFLAGS) $(DBG_CFLAGS) $(VST_CFLAGS) +#CFLAGS=$(CXXFLAGS) +#LDFLAGS=$(EXPAT_LIBS) $(SNDFILE_LIBS) $(GUI_LIBS) $(DBG_LIBS) +# +#C_SOURCES=$(DBG_SRC) +#CXX_SOURCES=$(GUI_SRC) $(DG_SRC) +#CPP_SOURCES=$(VST_SRC) # -#all: drumgizmo_vst.dll +#OBJECTS=$(CXX_SOURCES:.cc=.o) $(CPP_SOURCES:.cpp=.o) $(C_SOURCES:.c=.o) +#all: $(CXX_SOURCES) $(CPP_SOURCES) $(C_SOURCES) drumgizmo_vst.dll # #drumgizmo_vst.dll: $(OBJECTS) -# g++ $(OBJECTS) $(LDFLAGS) -shared -o drumgizmo_vst.dll -Wl,--out-implib,libdrumgizmo_vst.a +# g++ $(CXXFLAGS) $(OBJECTS) $(LDFLAGS) -shared -o drumgizmo_vst.dll -Wl,--out-implib,libdrumgizmo_vst.a # #%.o: %.cc -# g++ -c $(CFLAGS) $< -o $@ +# g++ -O3 -c $(CXXFLAGS) $(LDFLAGS) $< -o $(notdir $@) +# +#%.o: %.cpp +# g++ -O3 -c $(CXXFLAGS) $(LDFLAGS) $< -o $(notdir $@) +# +#%.o: %.c +# gcc -O3 -c $(CFLAGS) $(LDFLAGS) $< -o $@ # #clean: -# del -rf *.o drumgizmo_vst.dll libdrumgizmo_vst.a +# del -f $(notdir $(OBJECTS)) drumgizmo_vst.dll libdrumgizmo_vst.a +# +######################## + + +all: + gcc $(DBG_CFLAGS) $(top_srcdir)/hugin/hugin.c -c + gcc $(DBG_CFLAGS) $(top_srcdir)/hugin/hugin_syslog.c -c + g++ -g -Wall -DWIN32 $(DBG_CFLAGS) $(DG_CFLAGS) $(DG_LIBS) $(VST_CFLAGS) hugin.o hugin_syslog.o $(DG_SRC) $(VST_SRC) ${SRC} ${GUI_SRC} ${GUI_CFLAGS} $(GUI_LIBS) $(EXPAT_CFLAGS) $(EXPAT_LIBS) $(SNDFILE_CFLAGS) $(SNDFILE_LIBS) -shared -o drumgizmo_vst.dll -Wl,--out-implib,libdrumgizmo_vst.a + +clean: + del -f drumgizmo_vst.dll libdrumgizmo_vst.a diff --git a/vst/drumgizmo_vst.cc b/vst/drumgizmo_vst.cc index 381f2f9..4d3ce9f 100644 --- a/vst/drumgizmo_vst.cc +++ b/vst/drumgizmo_vst.cc @@ -29,12 +29,26 @@ #include "constants.h" #include <time.h> +#include <drumgizmo.h> + +#include <hugin.hpp> #define NUM_PROGRAMS 0 #define NUM_PARAMS 0 +static void midimapHandler(void *ptr, const char* file) +{ + DEBUG(vst, "midimapHandler\n"); + DrumGizmoVst* effect = (DrumGizmoVst*)ptr; + InputVST *input = effect->input; + DrumGizmo *drumgizmo = effect->drumgizmo; + drumgizmo->midimapfile = file; + input->loadMidiMap(file); +} + DGEditor::DGEditor(AudioEffect* effect) { + DEBUG(dgeditor, "Create DGEditor\n"); dgeff = (DrumGizmoVst*)effect; plugingui = NULL; drumgizmo = dgeff->drumgizmo; @@ -42,44 +56,70 @@ DGEditor::DGEditor(AudioEffect* effect) bool DGEditor::open(void* ptr) { - if(!plugingui) plugingui = new PluginGUI(drumgizmo); - plugingui->show(); + DEBUG(dgeditor, "open GUI (new PluginGUI)\n"); + if(plugingui) delete plugingui; + + plugingui = new PluginGUI(drumgizmo); + plugingui->setChangeMidimapCallback(midimapHandler, dgeff); + + // plugingui->show(); return true; } void DGEditor::close() { - plugingui->hide(); - delete plugingui; + DEBUG(dgeditor, "close GUI (delete PluginGUI)\n"); + // plugingui->hide(); + if(plugingui) delete plugingui; plugingui = NULL; } bool DGEditor::isOpen() { - return plugingui != NULL;; + DEBUG(vst, "isOpen\n"); + return plugingui != NULL; } void DGEditor::idle() { - if(plugingui) plugingui->processEvents(); + DEBUG(vst, "idle\n"); + // if(plugingui) plugingui->processEvents(); } AudioEffect* createEffectInstance(audioMasterCallback audioMaster) { + DEBUG(vst, "createEffectInstance\n"); return new DrumGizmoVst(audioMaster); } DrumGizmoVst::DrumGizmoVst(audioMasterCallback audioMaster) : AudioEffectX(audioMaster, NUM_PROGRAMS, NUM_PARAMS) { + hug_status_t status = hug_init(HUG_FLAG_OUTPUT_TO_SYSLOG | HUG_FLAG_USE_MUTEX, + HUG_OPTION_SYSLOG_HOST, "192.168.0.10", + HUG_OPTION_SYSLOG_PORT, 514, + HUG_OPTION_END); + + if(status != HUG_STATUS_OK) { + printf("Error: %d\n", status); + } + + INFO(example, "We are up and running"); + + DEBUG(vst, "DrumGizmoVst()\n"); + pos = 0; buffer = NULL; buffer_size = 0; + output = NULL; + input = NULL; + drumgizmo = NULL; + output = new OutputVST(); input = new InputVST(); drumgizmo = new DrumGizmo(output, input); - + // initialize programs //programs = new DrumGizmoVstProgram[kNumPrograms]; //for(VstInt32 i = 0; i < 16; i++) channelPrograms[i] = i; @@ -92,7 +132,7 @@ DrumGizmoVst::DrumGizmoVst(audioMasterCallback audioMaster) canProcessReplacing(); isSynth(); - char id[] = "DGV4"; // Four bytes typecasted into an unsigned integer + char id[] = "DGV5"; // Four bytes typecasted into an unsigned integer setUniqueID(*(unsigned int*)id); // setUniqueID((unsigned int)time(NULL)); @@ -104,13 +144,62 @@ DrumGizmoVst::DrumGizmoVst(audioMasterCallback audioMaster) editor = new DGEditor(this); setEditor(editor); + + programsAreChunks(true); + + // getChunk + // file:///home/deva/docs/c/drumgizmo/vst/vstsdk2.4/doc/html/class_audio_effect.html#42883c327783d7d31ed513b10c9204fc + + // setChunk + // file:///home/deva/docs/c/drumgizmo/vst/vstsdk2.4/doc/html/class_audio_effect.html#b6e4c31c1acf8d1fc4046521912787b1 } DrumGizmoVst::~DrumGizmoVst() { - delete drumgizmo; - delete input; - delete output; + DEBUG(vst, "~DrumGizmoVst(1)\n"); + if(drumgizmo) delete drumgizmo; + DEBUG(vst, "~DrumGizmoVst(2)\n"); + if(input) delete input; + DEBUG(vst, "~DrumGizmoVst(3)\n"); + if(output) delete output; + DEBUG(vst, "~DrumGizmoVst(4)\n"); + + hug_close(); +} + +VstInt32 DrumGizmoVst::getChunk(void **data, bool isPreset) +{ + DEBUG(vst, "getChunk(data: %p isPreset: %d)\n", *data, isPreset?1:0); + std::string cfg = drumgizmo->configString(); + DEBUG(vst, "drumgizmo->config := %s\n", cfg.c_str()); + char *config = strdup(cfg.c_str()); + *data = config; + return cfg.length(); +} + +VstInt32 DrumGizmoVst::setChunk(void *data, VstInt32 byteSize, bool isPreset) +{ + std::string config; + config.append((const char*)data, (size_t)byteSize); + DEBUG(vst, "setChunk(isPreset: %d): [%d] %s\n", + isPreset?1:0, byteSize, config.c_str()); + + if(!drumgizmo->setConfigString(config)) { + ERR(vst, "setConfigString failed...\n"); + return 1; + } + DEBUG(vst, "Using Drumkit: %s\n", drumgizmo->kitfile.c_str()); + DEBUG(vst, "Using Midimap: %s\n", drumgizmo->midimapfile.c_str()); + + input->loadMidiMap(drumgizmo->midimapfile); + + /* + drumgizmo->loadkit("z:/c/drumgizmo/kits/test/test.xml"); + drumgizmo->midimapfile = "z:/c/drumgizmo/kits/midimap.xml"; + input->loadMidiMap(drumgizmo->midimapfile); + */ + + return 0; } void DrumGizmoVst::setProgram(VstInt32 program) {} @@ -362,7 +451,7 @@ void DrumGizmoVst::setBlockSize(VstInt32 blockSize) void DrumGizmoVst::initProcess() { - drumgizmo->loadkit(getenv("DRUMGIZMO_DRUMKIT")); + // drumgizmo->loadkit(getenv("DRUMGIZMO_DRUMKIT")); drumgizmo->init(true); } diff --git a/vst/drumgizmo_vst.h b/vst/drumgizmo_vst.h index 5e063ff..4497c48 100644 --- a/vst/drumgizmo_vst.h +++ b/vst/drumgizmo_vst.h @@ -81,7 +81,12 @@ public: bool hasMidiProgramsChanged(VstInt32 channel); bool getMidiKeyName(VstInt32 channel, MidiKeyName* keyName); + VstInt32 getChunk(void **data, bool isPreset); + VstInt32 setChunk(void *data, VstInt32 byteSize, bool isPreset); + DrumGizmo *drumgizmo; + InputVST *input; + OutputVST *output; private: void initProcess(); @@ -89,8 +94,6 @@ private: // void noteOff(); void fillProgram(VstInt32 channel, VstInt32 prg, MidiProgramName* mpn); - InputVST *input; - OutputVST *output; size_t pos; sample_t *buffer; size_t buffer_size; diff --git a/vst/input_vst.cc b/vst/input_vst.cc index 52015ad..5cc73f9 100644 --- a/vst/input_vst.cc +++ b/vst/input_vst.cc @@ -27,6 +27,7 @@ #include "input_vst.h" #include <midimapparser.h> +#include <hugin.hpp> InputVST::InputVST() { @@ -38,16 +39,10 @@ InputVST::~InputVST() { } -bool InputVST::init(Instruments &instruments) +bool InputVST::init(Instruments &i) { - MidiMapParser p(getenv("DRUMGIZMO_MIDIMAP")); - if(p.parse()) {/*return false;*/} - mmap.midimap = p.midimap; - - for(size_t i = 0; i < instruments.size(); i++) { - mmap.instrmap[instruments[i].name()] = i; - } - + DEBUG(inputvst, "init\n"); + instruments = &i; return true; } @@ -98,6 +93,7 @@ void InputVST::processEvents(VstEvents* ev) VstInt32 velocity = midiData[2] & 0x7f; int i = mmap.lookup(note); + DEBUG(inputvst, "Note: %d -> %d\n", note, i); if(velocity && i != -1) { list[listsize].type = TYPE_ONSET; list[listsize].instrument = i; @@ -110,3 +106,20 @@ void InputVST::processEvents(VstEvents* ev) event++; } } + +void InputVST::loadMidiMap(std::string f) +{ + DEBUG(inputvst, "load midi map %s\n", f.c_str()); + + MidiMapParser p(f); + if(p.parse()) { + ERR(inputvst, "Error loading midimap: %s\n", f.c_str()); + return; + } + mmap.midimap = p.midimap; + + for(size_t i = 0; i < instruments->size(); i++) { + DEBUG(inputvst, "Mapping %s to %d\n", (*instruments)[i]->name().c_str(), i); + mmap.instrmap[(*instruments)[i]->name()] = i; + } +} diff --git a/vst/input_vst.h b/vst/input_vst.h index 84df91a..e8378c8 100644 --- a/vst/input_vst.h +++ b/vst/input_vst.h @@ -50,11 +50,14 @@ public: void processEvents(VstEvents* ev); + void loadMidiMap(std::string file); MidiMapper mmap; private: event_t *list; size_t listsize; + + Instruments *instruments; }; #endif/*__DRUMGIZMO_INPUT_VST_H__*/ |