serialize/deserialize MIDISceneChange color; put out of bounds color into static...
[ardour.git] / libs / ardour / session_vst.cc
index 61805be2cd789b9a2ed3534da4c6170c29cc9a5b..dfd9b295311055691bfdcd0eb9619c21b2faab20 100644 (file)
@@ -45,6 +45,20 @@ static int debug_callbacks = -1;
 
 using namespace ARDOUR;
 
+int Session::vst_current_loading_id = 0;
+const char* Session::vst_can_do_strings[] = {
+       X_("supplyIdle"),
+       X_("sendVstTimeInfo"),
+       X_("sendVstEvents"),
+       X_("sendVstMidiEvent"),
+       X_("receiveVstEvents"),
+       X_("receiveVstMidiEvent"),
+       X_("supportShell"),
+       X_("shellCategory"),
+       X_("shellCategorycurID")
+};
+const int Session::vst_can_do_string_count = sizeof (vst_can_do_strings) / sizeof (char*);
+
 intptr_t Session::vst_callback (
        AEffect* effect,
        int32_t opcode,
@@ -65,16 +79,16 @@ intptr_t Session::vst_callback (
        if (effect && effect->user) {
                plug = (VSTPlugin *) (effect->user);
                session = &plug->session();
-#ifdef COMPILER_MSVC
-               SHOW_CALLBACK ("am callback 0x%x, opcode = %d, plugin = \"%s\" ", (int) pthread_self().p, opcode, plug->name());
+#ifdef PLATFORM_WINDOWS
+               SHOW_CALLBACK ("am callback 0x%p, opcode = %d, plugin = \"%s\" ", pthread_self().p, opcode, plug->name());
 #else
                SHOW_CALLBACK ("am callback 0x%x, opcode = %d, plugin = \"%s\" ", (int) pthread_self(), opcode, plug->name());
 #endif
        } else {
                plug = 0;
                session = 0;
-#ifdef COMPILER_MSVC
-               SHOW_CALLBACK ("am callback 0x%x, opcode = %d", (int) pthread_self().p, opcode);
+#ifdef PLATFORM_WINDOWS
+               SHOW_CALLBACK ("am callback 0x%p, opcode = %d", pthread_self().p, opcode);
 #else
                SHOW_CALLBACK ("am callback 0x%x, opcode = %d", (int) pthread_self(), opcode);
 #endif
@@ -93,13 +107,12 @@ intptr_t Session::vst_callback (
        case audioMasterVersion:
                SHOW_CALLBACK ("amc: audioMasterVersion\n");
                // vst version, currently 2 (0 for older)
-               return 2; // XXX 2400
+               return 2400;
 
        case audioMasterCurrentId:
                SHOW_CALLBACK ("amc: audioMasterCurrentId\n");
-               // returns the unique id of a plug that's currently
-               // loading
-               return 0;
+               // returns the unique id of a plug that's currently loading
+               return vst_current_loading_id;
 
        case audioMasterIdle:
                SHOW_CALLBACK ("amc: audioMasterIdle\n");
@@ -123,7 +136,7 @@ intptr_t Session::vst_callback (
        case audioMasterWantMidi:
                SHOW_CALLBACK ("amc: audioMasterWantMidi\n");
                // <value> is a filter which is currently ignored
-               if (plug) {
+               if (plug && plug->get_info() != NULL) {
                        plug->get_info()->n_inputs.set_midi (1);
                }
                return 0;
@@ -248,6 +261,15 @@ intptr_t Session::vst_callback (
        case audioMasterProcessEvents:
                SHOW_CALLBACK ("amc: audioMasterProcessEvents\n");
                // VstEvents* in <ptr>
+               if (plug && plug->midi_buffer()) {
+                       VstEvents* v = (VstEvents*)ptr;
+                       for (int n = 0 ; n < v->numEvents; ++n) {
+                               VstMidiEvent *vme = (VstMidiEvent*) (v->events[n]->dump);
+                               if (vme->type == kVstMidiType) {
+                                       plug->midi_buffer()->push_back(vme->deltaFrames, 3, (uint8_t*)vme->midiData);
+                               }
+                       }
+               }
                return 0;
 
        case audioMasterSetTime:
@@ -408,6 +430,11 @@ intptr_t Session::vst_callback (
        case audioMasterCanDo:
                SHOW_CALLBACK ("amc: audioMasterCanDo\n");
                // string in ptr,  (const char*)ptr
+               for (int i = 0; i < vst_can_do_string_count; i++) {
+                       if (! strcmp(vst_can_do_strings[i], (const char*)ptr)) {
+                               return 1;
+                       }
+               }
                return 0;
 
        case audioMasterGetLanguage: