From a667d335ed2559c9065d6ca0dd2d1ff811ba2787 Mon Sep 17 00:00:00 2001 From: falkTX Date: Thu, 13 Feb 2014 12:46:02 +0000 Subject: [PATCH] Add notes plugin; Misc fixing for pyqt UIs --- source/modules/CarlaNative.hpp | 2 +- source/modules/CarlaNativeExtUI.hpp | 12 +- source/modules/native-plugins/Makefile | 7 +- source/modules/native-plugins/_all.c | 2 +- source/modules/native-plugins/notes.cpp | 128 ++++++++++++++++++ .../modules/native-plugins/resources/notes-ui | 2 +- source/utils/CarlaPipeUtils.hpp | 2 +- 7 files changed, 143 insertions(+), 12 deletions(-) create mode 100644 source/modules/native-plugins/notes.cpp diff --git a/source/modules/CarlaNative.hpp b/source/modules/CarlaNative.hpp index 55912f3b1..da18b87f6 100644 --- a/source/modules/CarlaNative.hpp +++ b/source/modules/CarlaNative.hpp @@ -325,7 +325,7 @@ protected: virtual void setCustomData(const char* const key, const char* const value) { - CARLA_SAFE_ASSERT_RETURN(key != nullptr,); + CARLA_SAFE_ASSERT_RETURN(key != nullptr && key[0] != '\0',); CARLA_SAFE_ASSERT_RETURN(value != nullptr,); } diff --git a/source/modules/CarlaNativeExtUI.hpp b/source/modules/CarlaNativeExtUI.hpp index 1c51f5f5f..155c9379c 100644 --- a/source/modules/CarlaNativeExtUI.hpp +++ b/source/modules/CarlaNativeExtUI.hpp @@ -93,9 +93,9 @@ protected: writeMsg("control\n", 8); std::sprintf(tmpBuf, "%i\n", index); - writeAndFixMsg(tmpBuf); + writeMsg(tmpBuf); std::sprintf(tmpBuf, "%f\n", value); - writeAndFixMsg(tmpBuf); + writeMsg(tmpBuf); } void uiSetMidiProgram(const uint8_t channel, const uint32_t bank, const uint32_t program) override @@ -106,16 +106,16 @@ protected: writeMsg("program\n", 8); std::sprintf(tmpBuf, "%i\n", channel); - writeAndFixMsg(tmpBuf); + writeMsg(tmpBuf); std::sprintf(tmpBuf, "%i\n", bank); - writeAndFixMsg(tmpBuf); + writeMsg(tmpBuf); std::sprintf(tmpBuf, "%i\n", program); - writeAndFixMsg(tmpBuf); + writeMsg(tmpBuf); } void uiSetCustomData(const char* const key, const char* const value) override { - CARLA_SAFE_ASSERT_RETURN(key != nullptr,); + CARLA_SAFE_ASSERT_RETURN(key != nullptr && key[0] != '\0',); CARLA_SAFE_ASSERT_RETURN(value != nullptr,); writeMsg("configure\n", 10); diff --git a/source/modules/native-plugins/Makefile b/source/modules/native-plugins/Makefile index 597ed318f..7b8734869 100644 --- a/source/modules/native-plugins/Makefile +++ b/source/modules/native-plugins/Makefile @@ -73,8 +73,8 @@ ifneq ($(WIN32),true) # External-UI plugins OBJS += \ - bigmeter.cpp.o -# ext-notes.cpp.o + bigmeter.cpp.o \ + notes.cpp.o endif # -------------------------------------------------------------- @@ -234,6 +234,9 @@ midi-file.cpp.o: midi-file.cpp midi-base.hpp $(CXXDEPS) midi-sequencer.cpp.o: midi-sequencer.cpp midi-base.hpp $(CXXDEPS) $(CXX) $< $(BUILD_CXX_FLAGS) -c -o $@ +notes.cpp.o: notes.cpp $(CXXDEPS) ../CarlaNativeExtUI.hpp + $(CXX) $< $(BUILD_CXX_FLAGS) -c -o $@ + vex-%.cpp.o: vex-%.cpp $(CXX) $< $(BUILD_CXX_FLAGS) -c -o $@ diff --git a/source/modules/native-plugins/_all.c b/source/modules/native-plugins/_all.c index 42d61b3b1..154156254 100644 --- a/source/modules/native-plugins/_all.c +++ b/source/modules/native-plugins/_all.c @@ -85,7 +85,7 @@ void carla_register_all_plugins() // External-UI plugins carla_register_native_plugin_bigmeter(); - //carla_register_native_plugin_notes(); + carla_register_native_plugin_notes(); #endif // DISTRHO plugins diff --git a/source/modules/native-plugins/notes.cpp b/source/modules/native-plugins/notes.cpp new file mode 100644 index 000000000..5fb1d80f4 --- /dev/null +++ b/source/modules/native-plugins/notes.cpp @@ -0,0 +1,128 @@ +/* + * Carla Native Plugins + * Copyright (C) 2012-2014 Filipe Coelho + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * For a full copy of the GNU General Public License see the doc/GPL.txt file. + */ + +#include "CarlaDefines.h" + +#ifdef CARLA_OS_WIN +# error This file should not be compiled for Windows +#endif + +#include "CarlaNativeExtUI.hpp" + +// ----------------------------------------------------------------------- + +class NotesPlugin : public NativePluginAndUiClass +{ +public: + NotesPlugin(const NativeHostDescriptor* const host) + : NativePluginAndUiClass(host, "/notes-ui"), + fCurPage(1) + { + } + +protected: + // ------------------------------------------------------------------- + // Plugin parameter calls + + uint32_t getParameterCount() const override + { + return 1; + } + + const NativeParameter* getParameterInfo(const uint32_t index) const override + { + if (index != 0) + return nullptr; + + static NativeParameter param; + + param.hints = static_cast(PARAMETER_IS_ENABLED|PARAMETER_IS_AUTOMABLE|PARAMETER_IS_INTEGER); + param.name = "Page"; + param.unit = nullptr; + param.ranges.def = 1.0f; + param.ranges.min = 1.0f; + param.ranges.max = 100.0f; + param.ranges.step = 1.0f; + param.ranges.stepSmall = 1.0f; + param.ranges.stepLarge = 1.0f; + param.scalePointCount = 0; + param.scalePoints = nullptr; + + return ¶m; + } + + float getParameterValue(const uint32_t index) const override + { + if (index != 0) + return 0.0f; + + return static_cast(fCurPage); + } + + // ------------------------------------------------------------------- + // Plugin state calls + + void setParameterValue(const uint32_t index, const float value) override + { + if (index != 0) + return; + + fCurPage = static_cast(value); + } + + // ------------------------------------------------------------------- + // Plugin process calls + + void process(float**, float**, const uint32_t, const NativeMidiEvent* const, const uint32_t) override + { + } + +private: + int fCurPage; + + PluginClassEND(NotesPlugin) + CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(NotesPlugin) +}; + +// ----------------------------------------------------------------------- + +static const NativePluginDescriptor notesDesc = { + /* category */ PLUGIN_CATEGORY_UTILITY, + /* hints */ static_cast(PLUGIN_IS_RTSAFE|PLUGIN_HAS_UI), + /* supports */ static_cast(0x0), + /* audioIns */ 0, + /* audioOuts */ 0, + /* midiIns */ 0, + /* midiOuts */ 0, + /* paramIns */ 1, + /* paramOuts */ 0, + /* name */ "Notes", + /* label */ "notes", + /* maker */ "falkTX", + /* copyright */ "GNU GPL v2+", + PluginDescriptorFILL(NotesPlugin) +}; + +// ----------------------------------------------------------------------- + +CARLA_EXPORT +void carla_register_native_plugin_notes() +{ + carla_register_native_plugin(¬esDesc); +} + +// ----------------------------------------------------------------------- diff --git a/source/modules/native-plugins/resources/notes-ui b/source/modules/native-plugins/resources/notes-ui index 7d1a55293..7ceb43eb6 100755 --- a/source/modules/native-plugins/resources/notes-ui +++ b/source/modules/native-plugins/resources/notes-ui @@ -85,7 +85,7 @@ class DistrhoUINotes(QWidget, ExternalUI): self.showUiIfTesting() def saveCurrentTextState(self): - pageKey = "pageText %i" % self.fCurPage + pageKey = "pageText #%i" % self.fCurPage pageValue = self.fTextEdit.toPlainText() if pageValue != self.fNotes[self.fCurPage-1]: diff --git a/source/utils/CarlaPipeUtils.hpp b/source/utils/CarlaPipeUtils.hpp index e9a7bbbff..0c84c4dea 100644 --- a/source/utils/CarlaPipeUtils.hpp +++ b/source/utils/CarlaPipeUtils.hpp @@ -434,7 +434,7 @@ public: fixedMsg[i] = '\r'; } - if (fixedMsg[size+1] == '\r') + if (fixedMsg[size-1] == '\r') { fixedMsg[size-1] = '\n'; fixedMsg[size] = '\0';