ZynAddSubFX-UI.cpp (3379B)
1 /* 2 ZynAddSubFX - a software synthesizer 3 4 ZynAddSubFX-UI.cpp - DPF + ZynAddSubFX External UI 5 Copyright (C) 2015-2016 Filipe Coelho 6 Author: Filipe Coelho 7 8 This program is free software; you can redistribute it and/or 9 modify it under the terms of the GNU General Public License 10 as published by the Free Software Foundation; either version 2 11 of the License, or (at your option) any later version. 12 */ 13 14 // DPF includes 15 #include "DistrhoUI.hpp" 16 17 /* ------------------------------------------------------------------------------------------------------------ 18 * ZynAddSubFX UI class */ 19 20 class ZynAddSubFXUI : public UI 21 { 22 public: 23 ZynAddSubFXUI(const intptr_t wid, const char* const bpath) 24 : UI(390, 525), 25 oscPort(0), 26 winId(wid) 27 { 28 setTitle("ZynAddSubFX"); 29 30 #if DISTRHO_OS_MAC 31 extUiPath = bpath; 32 extUiPath += "/zynaddsubfx-ext-gui"; 33 #else 34 extUiPath = "zynaddsubfx-ext-gui"; 35 36 // unused 37 return; (void)bpath; 38 #endif 39 } 40 41 ~ZynAddSubFXUI() override 42 { 43 } 44 45 protected: 46 /* -------------------------------------------------------------------------------------------------------- 47 * DSP/Plugin Callbacks */ 48 49 /** 50 A parameter has changed on the plugin side. 51 This is called by the host to inform the UI about parameter changes. 52 */ 53 void parameterChanged(uint32_t index, float value) override 54 { 55 switch (index) 56 { 57 case kParamOscPort: { 58 const int port = int(value+0.5f); 59 60 if (oscPort != port) 61 { 62 oscPort = port; 63 respawnAtURL(port); 64 } 65 } break; 66 } 67 } 68 69 /** 70 A program has been loaded on the plugin side. 71 This is called by the host to inform the UI about program changes. 72 */ 73 void programLoaded(uint32_t index) override 74 { 75 (void)index; // ZynAddSubFX::loadProgram already informs the UI 76 } 77 78 /** 79 A state has changed on the plugin side. 80 This is called by the host to inform the UI about state changes. 81 */ 82 void stateChanged(const char* key, const char* value) override 83 { 84 (void)key; (void)value; 85 } 86 87 private: 88 int oscPort; 89 String extUiPath; 90 const intptr_t winId; 91 92 void respawnAtURL(const int url) 93 { 94 char urlAsString[32]; 95 sprintf(urlAsString, "osc.udp://localhost:%i/", url); 96 97 char winIdAsString[32]; 98 sprintf(winIdAsString, "%llu", (long long unsigned)(winId ? winId : 1)); 99 100 printf("Now respawning at '%s', using winId '%s'\n", urlAsString, winIdAsString); 101 102 const char* args[] = { 103 extUiPath.buffer(), 104 "--embed", 105 winIdAsString, 106 "--title", 107 getTitle(), 108 urlAsString, 109 nullptr 110 }; 111 112 startExternalProcess(args); 113 } 114 115 DISTRHO_DECLARE_NON_COPY_CLASS(ZynAddSubFXUI) 116 }; 117 118 /* ------------------------------------------------------------------------------------------------------------ 119 * Create UI, entry point */ 120 121 START_NAMESPACE_DISTRHO 122 123 UI* createUI() 124 { 125 #if DISTRHO_PLUGIN_HAS_EMBED_UI 126 const uintptr_t winId = UI::getNextWindowId(); 127 #else 128 const uintptr_t winId = 0; 129 #endif 130 const char* const bundlePath = UI::getNextBundlePath(); 131 132 return new ZynAddSubFXUI(winId, bundlePath); 133 } 134 135 END_NAMESPACE_DISTRHO