From e0ee3c678b5d6f4cea3aee47c8f91b70cfc696d7 Mon Sep 17 00:00:00 2001 From: falkTX Date: Sun, 18 Jan 2015 11:38:05 +0000 Subject: [PATCH] Continue bls1 plugin; Misc changes --- source/includes/CarlaNative.hpp | 5 +- source/interposer/interposer-x11.cpp | 6 +- source/native-plugins/zita-bls1.cpp | 176 ++++++++++++------ .../zita-bls1/source/mainwin.cc | 5 - .../native-plugins/zita-bls1/source/mainwin.h | 8 +- .../native-plugins/zita-bls1/source/rotary.cc | 29 ++- 6 files changed, 151 insertions(+), 78 deletions(-) diff --git a/source/includes/CarlaNative.hpp b/source/includes/CarlaNative.hpp index 8ef9a6d21..a79756f4e 100644 --- a/source/includes/CarlaNative.hpp +++ b/source/includes/CarlaNative.hpp @@ -365,10 +365,7 @@ protected: virtual void uiNameChanged(const char* const uiName) { - return; - - // unused - (void)uiName; + CARLA_SAFE_ASSERT_RETURN(uiName != nullptr && uiName[0] != '\0',); } // ------------------------------------------------------------------- diff --git a/source/interposer/interposer-x11.cpp b/source/interposer/interposer-x11.cpp index 863012c79..479b66fd9 100644 --- a/source/interposer/interposer-x11.cpp +++ b/source/interposer/interposer-x11.cpp @@ -36,7 +36,7 @@ static int sMapWindowCounter = 0; static int real_XMapWindow(Display* display, Window w) { - static XMapWindowFunc func = (XMapWindowFunc)::dlsym(RTLD_NEXT, "XMapWindow"); + static const XMapWindowFunc func = (XMapWindowFunc)::dlsym(RTLD_NEXT, "XMapWindow"); CARLA_SAFE_ASSERT_RETURN(func != nullptr, 0); return func(display, w); @@ -44,7 +44,7 @@ static int real_XMapWindow(Display* display, Window w) static int real_XUnmapWindow(Display* display, Window w) { - static XUnmapWindowFunc func = (XUnmapWindowFunc)::dlsym(RTLD_NEXT, "XUnmapWindow"); + static const XUnmapWindowFunc func = (XUnmapWindowFunc)::dlsym(RTLD_NEXT, "XUnmapWindow"); CARLA_SAFE_ASSERT_RETURN(func != nullptr, 0); return func(display, w); @@ -66,7 +66,7 @@ int XMapWindow(Display* display, Window w) CARLA_SAFE_ASSERT_RETURN(winIdStr[0] != '\0', real_XMapWindow(display, w)); const long long winIdLL(std::strtoll(winIdStr, nullptr, 16)); - CARLA_SAFE_ASSERT_RETURN(winIdLL >= 0, real_XMapWindow(display, w)); + CARLA_SAFE_ASSERT_RETURN(winIdLL > 0, real_XMapWindow(display, w)); const Window winId(static_cast(winIdLL)); XSetTransientForHint(display, w, static_cast(winId)); diff --git a/source/native-plugins/zita-bls1.cpp b/source/native-plugins/zita-bls1.cpp index faf4ba803..dd260d7c9 100644 --- a/source/native-plugins/zita-bls1.cpp +++ b/source/native-plugins/zita-bls1.cpp @@ -41,17 +41,22 @@ using juce::ScopedPointer; class BLS1Plugin : public NativePluginClass { public: -#if 0 + static const uint32_t kNumInputs = 2; + static const uint32_t kNumOutputs = 2; + enum Parameters { - kParameterInput = 0, - kParameterCount + kParameterINPBAL, + kParameterHPFILT, + kParameterSHGAIN, + kParameterSHFREQ, + kParameterLFFREQ, + kParameterLFGAIN, + kParameterNROTARY }; -#endif BLS1Plugin(const NativeHostDescriptor* const host) : NativePluginClass(host), fJackClient(), - fMutex(), xresman(), jclient(nullptr), display(nullptr), @@ -75,21 +80,31 @@ public: jclient = new Jclient(xresman.rname(), nullptr); - //fParameters[kParameterInput] = 1.0f; + // set initial values + fParameters[kParameterINPBAL] = 0.0f; + fParameters[kParameterHPFILT] = 40.0f; + fParameters[kParameterSHGAIN] = 15.0f; + fParameters[kParameterSHFREQ] = 5e2f; + fParameters[kParameterLFFREQ] = 80.0f; + fParameters[kParameterLFGAIN] = 0.0f; + + jclient->set_inpbal(fParameters[kParameterINPBAL]); + jclient->set_hpfilt(fParameters[kParameterHPFILT]); + jclient->shuffler()->prepare(fParameters[kParameterSHGAIN], fParameters[kParameterSHFREQ]); + jclient->set_loshelf(fParameters[kParameterLFGAIN], fParameters[kParameterLFFREQ]); } -#if 0 // ------------------------------------------------------------------- // Plugin parameter calls uint32_t getParameterCount() const override { - return kParameterCount; + return kParameterNROTARY; } const NativeParameter* getParameterInfo(const uint32_t index) const override { - CARLA_SAFE_ASSERT_RETURN(index < kParameterCount, nullptr); + CARLA_SAFE_ASSERT_RETURN(index < kParameterNROTARY, nullptr); static NativeParameter param; @@ -109,12 +124,44 @@ public: switch (index) { - case kParameterInput: - hints |= NATIVE_PARAMETER_IS_INTEGER; - param.name = "Input"; - param.ranges.def = 1.0f; - param.ranges.min = 1.0f; - param.ranges.max = 8.0f; + case kParameterINPBAL: + param.name = "INPBAL"; + param.ranges.def = 0.0f; + param.ranges.min = -3.0f; + param.ranges.max = 3.0f; + break; + case kParameterHPFILT: + hints |= NATIVE_PARAMETER_IS_LOGARITHMIC; + param.name = "HPFILT"; + param.ranges.def = 40.0f; + param.ranges.min = 10.0f; + param.ranges.max = 320.0f; + break; + case kParameterSHGAIN: + param.name = "SHGAIN"; + param.ranges.def = 15.0f; + param.ranges.min = 0.0f; + param.ranges.max = 24.0f; + break; + case kParameterSHFREQ: + hints |= NATIVE_PARAMETER_IS_LOGARITHMIC; + param.name = "SHFREQ"; + param.ranges.def = 5e2f; + param.ranges.min = 125.0f; + param.ranges.max = 2e3f; + break; + case kParameterLFFREQ: + hints |= NATIVE_PARAMETER_IS_LOGARITHMIC; + param.name = "LFFREQ"; + param.ranges.def = 80.0f; + param.ranges.min = 20.0f; + param.ranges.max = 320.0f; + break; + case kParameterLFGAIN: + param.name = "LFGAIN"; + param.ranges.def = 0.0f; + param.ranges.min = -9.0f; + param.ranges.max = 9.0f; break; } @@ -125,7 +172,7 @@ public: float getParameterValue(const uint32_t index) const override { - CARLA_SAFE_ASSERT_RETURN(index < kParameterCount, 0.0f); + CARLA_SAFE_ASSERT_RETURN(index < kParameterNROTARY, 0.0f); return fParameters[index]; } @@ -135,11 +182,32 @@ public: void setParameterValue(const uint32_t index, const float value) override { - CARLA_SAFE_ASSERT_RETURN(index < kParameterCount,); + CARLA_SAFE_ASSERT_RETURN(index < kParameterNROTARY,); fParameters[index] = value; + + switch (index) + { + case kParameterINPBAL: + jclient->set_inpbal(value); + break; + case kParameterHPFILT: + jclient->set_hpfilt(value); + break; + case kParameterSHGAIN: + jclient->shuffler()->prepare(value, fParameters[kParameterSHFREQ]); + break; + case kParameterSHFREQ: + jclient->shuffler()->prepare(fParameters[kParameterSHGAIN], value); + break; + case kParameterLFFREQ: + jclient->set_loshelf(fParameters[kParameterLFGAIN], value); + break; + case kParameterLFGAIN: + jclient->set_loshelf(value, fParameters[kParameterLFFREQ]); + break; + } } -#endif // ------------------------------------------------------------------- // Plugin process calls @@ -150,16 +218,16 @@ public: { const int iframes(static_cast(frames)); - for (int i=0; i<2; ++i) + for (uint32_t i=0; ibuffer = inBuffer[i]; - for (int i=0; i<2; ++i) + for (uint32_t i=0; ibuffer = outBuffer[i]; fJackClient.processCallback(frames, fJackClient.processPtr); @@ -170,8 +238,6 @@ public: void uiShow(const bool show) override { - const CarlaMutexLocker cml(fMutex); - if (show) { if (display == nullptr) @@ -183,9 +249,10 @@ public: styles_init(display, &xresman); - rootwin = new X_rootwin(display); - mainwin = new Mainwin(rootwin, &xresman, 0, 0, jclient); + rootwin = new X_rootwin(display); + mainwin = new Mainwin(rootwin, &xresman, 0, 0, jclient); rootwin->handle_event(); + mainwin->x_set_title(getUiName()); handler = new X_handler(display, mainwin, EV_X11); @@ -199,15 +266,15 @@ public: else { handler = nullptr; - mainwin = nullptr; - rootwin = nullptr; - display = nullptr; + mainwin = nullptr; + rootwin = nullptr; + display = nullptr; } } void uiIdle() override { - if (display == nullptr) + if (mainwin == nullptr) return; int ev; @@ -218,14 +285,19 @@ public: handler->next_event(); } -#if 0 // check if parameters were updated - if (mainwin->_input+1 != static_cast(fParameters[kParameterInput])) + float value; + + for (uint32_t i=0; i_input+1; - uiParameterChanged(kParameterInput, fParameters[kParameterInput]); + value = mainwin->_rotary[i]->value(); + + if (fParameters[i] == value) + continue; + + fParameters[i] = value; + uiParameterChanged(i, value); } -#endif if (ev == EV_EXIT) { @@ -237,24 +309,15 @@ public: } } -#if 0 void uiSetParameterValue(const uint32_t index, const float value) override { - CARLA_SAFE_ASSERT_RETURN(index < kParameterCount,); + CARLA_SAFE_ASSERT_RETURN(index < kParameterNROTARY,); - const CarlaMutexLocker cml(fMutex); - - if (itcc == nullptr) + if (mainwin == nullptr) return; - switch (index) - { - case kParameterInput: - mainwin->set_input(static_cast(value)-1); - break; - } + mainwin->_rotary[index]->set_value(value); } -#endif // ------------------------------------------------------------------- // Plugin dispatcher calls @@ -269,15 +332,22 @@ public: fJackClient.sampleRate = sampleRate; } + void uiNameChanged(const char* const uiName) override + { + CARLA_SAFE_ASSERT_RETURN(uiName != nullptr && uiName[0] != '\0',); + + if (mainwin == nullptr) + return; + + mainwin->x_set_title(uiName); + } + // ------------------------------------------------------------------- private: // Fake jack client jack_client_t fJackClient; - // Mutex just in case - CarlaMutex fMutex; - // Zita stuff (core) X_resman xresman; ScopedPointer jclient; @@ -286,7 +356,7 @@ private: ScopedPointer mainwin; ScopedPointer handler; - //float fParameters[kParameterCount]; + float fParameters[kParameterNROTARY]; PluginClassEND(BLS1Plugin) CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(BLS1Plugin) @@ -302,11 +372,11 @@ static const NativePluginDescriptor bls1Desc = { |NATIVE_PLUGIN_NEEDS_UI_MAIN_THREAD |NATIVE_PLUGIN_USES_PARENT_ID), /* supports */ static_cast(0x0), - /* audioIns */ 2, - /* audioOuts */ 2, + /* audioIns */ BLS1Plugin::kNumInputs, + /* audioOuts */ BLS1Plugin::kNumOutputs, /* midiIns */ 0, /* midiOuts */ 0, - /* paramIns */ 0, //JaaaPlugin::kParameterCount, + /* paramIns */ BLS1Plugin::kParameterNROTARY, /* paramOuts */ 0, /* name */ "BLS1", /* label */ "bls1", diff --git a/source/native-plugins/zita-bls1/source/mainwin.cc b/source/native-plugins/zita-bls1/source/mainwin.cc index 46a26a8da..2519eeef7 100644 --- a/source/native-plugins/zita-bls1/source/mainwin.cc +++ b/source/native-plugins/zita-bls1/source/mainwin.cc @@ -61,11 +61,6 @@ Mainwin::Mainwin (X_rootwin *parent, X_resman *xres, int xp, int yp, Jclient *jc _rotary [LFGAIN] = new Rlinctl (this, this, &lfgain_img, 410, 0, 180, 5, -9.0f, 9.0f, 0.0f, LFGAIN); for (i = 0; i < NROTARY; i++) _rotary [i]->x_map (); - _jclient->set_inpbal (_rotary [INPBAL]->value ()); - _jclient->set_hpfilt (_rotary [HPFILT]->value ()); - _jclient->set_loshelf (_rotary [LFGAIN]->value (),_rotary [LFFREQ]->value ()); - _jclient->shuffler ()->prepare (_rotary [SHGAIN]->value (), _rotary [SHFREQ]->value ()); - _numtext = new X_textip (this, 0, &tstyle1, 0, 0, 45, 15, 15); _numtext->set_align (0); _parmind = -1; diff --git a/source/native-plugins/zita-bls1/source/mainwin.h b/source/native-plugins/zita-bls1/source/mainwin.h index 18cc9f042..6f8981caa 100644 --- a/source/native-plugins/zita-bls1/source/mainwin.h +++ b/source/native-plugins/zita-bls1/source/mainwin.h @@ -1,7 +1,7 @@ // ---------------------------------------------------------------------- // // Copyright (C) 2011 Fons Adriaensen -// +// // 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 @@ -41,12 +41,12 @@ public: Mainwin& operator=(const Mainwin&); void stop (void) { _stop = true; } - int process (void); + int process (void); private: enum { INPBAL, HPFILT, SHGAIN, SHFREQ, LFFREQ, LFGAIN, NROTARY }; - + virtual void thr_main (void) {} void handle_time (void); @@ -68,6 +68,8 @@ private: int _parmind; int _timeout; int _touch; + + friend class BLS1Plugin; }; diff --git a/source/native-plugins/zita-bls1/source/rotary.cc b/source/native-plugins/zita-bls1/source/rotary.cc index ca08b7e78..f302f8073 100644 --- a/source/native-plugins/zita-bls1/source/rotary.cc +++ b/source/native-plugins/zita-bls1/source/rotary.cc @@ -1,7 +1,7 @@ // ---------------------------------------------------------------------- // // Copyright (C) 2010 Fons Adriaensen -// +// // 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 @@ -58,7 +58,7 @@ RotaryCtl::RotaryCtl (X_window *parent, { x_add_events ( ExposureMask | Button1MotionMask | ButtonPressMask | ButtonReleaseMask); -} +} RotaryCtl::~RotaryCtl (void) @@ -68,6 +68,9 @@ RotaryCtl::~RotaryCtl (void) void RotaryCtl::init (X_display *disp) { + if (_cairosurf != NULL) + return; + _cairosurf = cairo_xlib_surface_create (disp->dpy (), 0, disp->dvi (), 50, 50); _cairotype = cairo_create (_cairosurf); } @@ -75,8 +78,14 @@ void RotaryCtl::init (X_display *disp) void RotaryCtl::fini (void) { + if (_cairosurf == NULL) + return; + cairo_destroy (_cairotype); cairo_surface_destroy (_cairosurf); + + _cairotype = NULL; + _cairosurf = NULL; } @@ -86,11 +95,11 @@ void RotaryCtl::handle_event (XEvent *E) { case Expose: render (); - break; - + break; + case ButtonPress: bpress ((XButtonEvent *) E); - break; + break; case ButtonRelease: brelse ((XButtonEvent *) E); @@ -100,7 +109,7 @@ void RotaryCtl::handle_event (XEvent *E) motion ((XMotionEvent *) E); break; - default: + default: fprintf (stderr, "RotaryCtl: event %d\n", E->type ); } } @@ -126,11 +135,11 @@ void RotaryCtl::bpress (XButtonEvent *E) else if ((int)E->button == _wb_up) { r = handle_mwheel (1); - } - else if ((int)E->button == _wb_dn) + } + else if ((int)E->button == _wb_dn) { r = handle_mwheel (-1); - } + } if (r) { callback (r); @@ -170,7 +179,7 @@ void RotaryCtl::motion (XMotionEvent *E) void RotaryCtl::set_state (int s) { - _state = s; + _state = s; render (); }