summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien Zammit <damien@zamaudio.com>2019-02-09 18:28:38 +1100
committerDamien Zammit <damien@zamaudio.com>2019-02-09 18:31:34 +1100
commit765e2dda8810dc382ade80065999c2f59c032938 (patch)
treeaa04a1c566eabbfafafa0bd4ced857a21a265ac3
parenta8bd1a722dc6a02911044feb8c5b4ad55d7e4b28 (diff)
Actually display a UI!
-rw-r--r--Makefile.plugins.mk2
-rw-r--r--distrho/DistrhoUIMain.cpp2
-rw-r--r--distrho/src/CocoaUI/PluginAU_CocoaUI.m86
-rw-r--r--distrho/src/DistrhoUIAU.cpp211
4 files changed, 84 insertions, 217 deletions
diff --git a/Makefile.plugins.mk b/Makefile.plugins.mk
index b145f6b8..4426bcf5 100644
--- a/Makefile.plugins.mk
+++ b/Makefile.plugins.mk
@@ -387,7 +387,7 @@ $(BUILD_DIR)/DistrhoPluginInfo.r: $(OBJS_DSP) $(BUILD_DIR)/DistrhoPluginAUexport
$(BUILD_DIR)/PluginAU_CocoaUI.mm.o: $(DPF_PATH)/distrho/src/CocoaUI/PluginAU_CocoaUI.m
-@mkdir -p $(shell dirname $@)
@echo "Compiling Cocoa UI for $(NAME)"
- $(CXX) $< $(BUILD_CXX_FLAGS) -Wno-unused-parameter -ObjC++ -c -o $@
+ $(CXX) $< $(BUILD_CXX_FLAGS) -I$(DPF_PATH)/distrho/src -Wno-unused-parameter -ObjC++ -c -o $@
# ---------------------------------------------------------------------------------------------------------------------
diff --git a/distrho/DistrhoUIMain.cpp b/distrho/DistrhoUIMain.cpp
index 2b75c3d7..86b90910 100644
--- a/distrho/DistrhoUIMain.cpp
+++ b/distrho/DistrhoUIMain.cpp
@@ -17,7 +17,7 @@
#include "src/DistrhoUI.cpp"
#if defined(DISTRHO_PLUGIN_TARGET_AU)
-# include "src/DistrhoUIAU.cpp"
+// nothing
#elif defined(DISTRHO_PLUGIN_TARGET_CARLA)
// nothing
#elif defined(DISTRHO_PLUGIN_TARGET_JACK)
diff --git a/distrho/src/CocoaUI/PluginAU_CocoaUI.m b/distrho/src/CocoaUI/PluginAU_CocoaUI.m
index ee8da585..e8e1d7bf 100644
--- a/distrho/src/CocoaUI/PluginAU_CocoaUI.m
+++ b/distrho/src/CocoaUI/PluginAU_CocoaUI.m
@@ -2,15 +2,88 @@
#include <AudioUnit/AudioUnit.h>
#include <AudioToolbox/AudioToolbox.h>
#include <AudioUnit/AUCocoaUIView.h>
+#include "DistrhoUIInternal.hpp"
#define MAX_PARAMS 100
+START_NAMESPACE_DISTRHO
+
+class UIAu
+{
+public:
+ UIAu(const char* const uiTitle)
+ : fUI(this, 0, nullptr, setParameterCallback, setStateCallback, sendNoteCallback, setSizeCallback),
+ fHostClosed(false)
+ {
+ fUI.setWindowTitle(uiTitle);
+ }
+
+ ~UIAu()
+ {
+ }
+
+ void auui_showhide(bool show)
+ {
+ fUI.setWindowVisible(show);
+ }
+
+protected:
+ void setParameterValue(const uint32_t rindex, const float value)
+ {
+ //FIXME fUI.setParameterValue(rindex, value);
+ }
+
+ void setState(const char* const key, const char* const value)
+ {
+ }
+
+ void setSize(const uint width, const uint height)
+ {
+ fUI.setWindowSize(width, height);
+ }
+
+private:
+ UIExporter fUI;
+ bool fHostClosed;
+
+ // -------------------------------------------------------------------
+ // Callbacks
+
+ #define uiPtr ((UIAu*)ptr)
+
+ static void setParameterCallback(void* ptr, uint32_t rindex, float value)
+ {
+ uiPtr->setParameterValue(rindex, value);
+ }
+
+ static void setStateCallback(void* ptr, const char* key, const char* value)
+ {
+ uiPtr->setState(key, value);
+ }
+
+ static void sendNoteCallback(void* ptr, uint8_t channel, uint8_t note, uint8_t velocity)
+ {
+ }
+
+ static void setSizeCallback(void* ptr, uint width, uint height)
+ {
+ uiPtr->setSize(width, height);
+ }
+
+ #undef uiPtr
+};
+
+END_NAMESPACE_DISTRHO
+
+// -----------------------------------------------------------------------
+
@interface PluginAU_CocoaUI : NSView
{
AudioUnit mAU;
AudioUnitParameter mParameter[MAX_PARAMS];
AUParameterListenerRef mParameterListener;
UInt32 paramCount;
+ UIAu* fUIAu;
}
#pragma mark ____ PUBLIC FUNCTIONS ____
@@ -34,6 +107,8 @@
#pragma mark ____ (INIT /) DEALLOC ____
- (void)dealloc {
[self _removeListeners];
+ fUIAu->auui_showhide(false);
+ delete fUIAu;
[super dealloc];
}
@@ -53,7 +128,7 @@
mParameter[i].mElement = 0;
}
- //auUI* dspUI = [self dspUI];
+ fUIAu = new UIAu(DISTRHO_PLUGIN_NAME);
// add new listeners
[self _addListeners];
@@ -61,6 +136,7 @@
// initial setup
[self _synchronizeUIWithParameterValues];
+ fUIAu->auui_showhide(true);
}
#pragma mark ____ LISTENER CALLBACK DISPATCHER ____
@@ -148,9 +224,11 @@ void ParameterListenerDispatcher (void *inRefCon, void *inObject,
}
- (NSView *)uiViewForAudioUnit:(AudioUnit)inAU withSize:(NSSize)inPreferredSize {
- PluginAU_CocoaUI *view = [[PluginAU_CocoaUI alloc] init];
- [view setAU:inAU];
- return [view autorelease];
+ uiFreshlyLoadedView = [[PluginAU_CocoaUI alloc] init];
+ [uiFreshlyLoadedView setAU:inAU];
+ NSView *returnView = uiFreshlyLoadedView;
+ uiFreshlyLoadedView = nil;
+ return [returnView autorelease];
}
@end
diff --git a/distrho/src/DistrhoUIAU.cpp b/distrho/src/DistrhoUIAU.cpp
deleted file mode 100644
index dc5a61c7..00000000
--- a/distrho/src/DistrhoUIAU.cpp
+++ /dev/null
@@ -1,211 +0,0 @@
-/*
- * DISTRHO Plugin Framework (DPF)
- * Copyright (C) 2012-2019 Filipe Coelho <falktx@falktx.com>
- *
- * Permission to use, copy, modify, and/or distribute this software for any purpose with
- * or without fee is hereby granted, provided that the above copyright notice and this
- * permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
- * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
- * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
- * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
- * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
- * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-#include "DistrhoUIInternal.hpp"
-
-#include "../extra/Sleep.hpp"
-
-START_NAMESPACE_DISTRHO
-
-//#if ! DISTRHO_PLUGIN_WANT_MIDI_INPUT
-static const sendNoteFunc sendNoteCallback = nullptr;
-//#endif
-
-// -----------------------------------------------------------------------
-
-class UIAu
-{
-public:
- UIAu(const char* const uiTitle)
- : fUI(this, 0, nullptr, setParameterCallback, setStateCallback, sendNoteCallback, setSizeCallback),
- fHostClosed(false)
- {
- fUI.setWindowTitle(uiTitle);
- }
-
- ~UIAu()
- {
- }
-
- void exec()
- {
- for (;;)
- {
- if (fHostClosed || ! fUI.idle())
- break;
-
- d_msleep(30);
- }
- }
-
- // -------------------------------------------------------------------
-
-#if 0
-#if DISTRHO_PLUGIN_WANT_STATE
- void auui_configure(const char* key, const char* value)
- {
- fUI.stateChanged(key, value);
- }
-#endif
-#endif
-
- void auui_control(ulong index, float value)
- {
- fUI.parameterChanged(index, value);
- }
-
-#if 0
-#if DISTRHO_PLUGIN_WANT_PROGRAMS
- void auui_program(ulong bank, ulong program)
- {
- fUI.programLoaded(bank * 128 + program);
- }
-#endif
-#endif
-
- void auui_samplerate(const double sampleRate)
- {
- fUI.setSampleRate(sampleRate, true);
- }
-
- void auui_show()
- {
- fUI.setWindowVisible(true);
- }
-
- void auui_hide()
- {
- fUI.setWindowVisible(false);
- }
-
- void auui_quit()
- {
- fHostClosed = true;
- fUI.quit();
- }
-
- // -------------------------------------------------------------------
-
-protected:
- void setParameterValue(const uint32_t rindex, const float value)
- {
- //FIXME fUI.setParameterValue(rindex, value);
- }
-
- void setState(const char* const key, const char* const value)
- {
- }
-
-#if 0
-#if DISTRHO_PLUGIN_WANT_MIDI_INPUT
- void sendNote(const uint8_t channel, const uint8_t note, const uint8_t velocity)
- {
- if (fOscData.server == nullptr)
- return;
- if (channel > 0xF)
- return;
-
- uint8_t mdata[4] = {
- 0,
- static_cast<uint8_t>(channel + (velocity != 0 ? 0x90 : 0x80)),
- note,
- velocity
- };
- fOscData.send_midi(mdata);
- }
-#endif
-#endif
-
- void setSize(const uint width, const uint height)
- {
- fUI.setWindowSize(width, height);
- }
-
-private:
- UIExporter fUI;
- bool fHostClosed;
-
- // -------------------------------------------------------------------
- // Callbacks
-
- #define uiPtr ((UIAu*)ptr)
-
- static void setParameterCallback(void* ptr, uint32_t rindex, float value)
- {
- uiPtr->setParameterValue(rindex, value);
- }
-
- static void setStateCallback(void* ptr, const char* key, const char* value)
- {
- uiPtr->setState(key, value);
- }
-
-#if 0
-#if DISTRHO_PLUGIN_WANT_MIDI_INPUT
- static void sendNoteCallback(void* ptr, uint8_t channel, uint8_t note, uint8_t velocity)
- {
- uiPtr->sendNote(channel, note, velocity);
- }
-#endif
-#endif
-
- static void setSizeCallback(void* ptr, uint width, uint height)
- {
- uiPtr->setSize(width, height);
- }
-
- #undef uiPtr
-};
-
-// -----------------------------------------------------------------------
-
-static const char* gUiTitle = nullptr;
-static UIAu* globalUI = nullptr;
-
-static void initUiIfNeeded()
-{
- if (globalUI != nullptr)
- return;
-
- if (d_lastUiSampleRate == 0.0)
- d_lastUiSampleRate = 44100.0;
-
- globalUI = new UIAu(gUiTitle);
-}
-
-END_NAMESPACE_DISTRHO
-
-// -----------------------------------------------------------------------
-
-int main(int argc, char* argv[])
-{
- USE_NAMESPACE_DISTRHO
-
- // dummy test mode
- if (argc == 1)
- {
- gUiTitle = "AU UI Test";
-
- initUiIfNeeded();
- globalUI->auui_show();
- globalUI->exec();
-
- delete globalUI;
- globalUI = nullptr;
-
- return 0;
- }
-}