diff --git a/source/Makefile.mk b/source/Makefile.mk index 336739b30..1b19baaea 100644 --- a/source/Makefile.mk +++ b/source/Makefile.mk @@ -18,21 +18,27 @@ WINDRES ?= windres DEBUG ?= false ifeq ($(DEBUG),true) -BASE_FLAGS = -O0 -g -Wall -Wextra +BASE_FLAGS = -O0 -g BASE_FLAGS += -DDEBUG STRIP = true # FIXME else -BASE_FLAGS = -O2 -ffast-math -mtune=generic -msse -mfpmath=sse -Wall -Wextra +BASE_FLAGS = -O2 -ffast-math -mtune=generic -msse -mfpmath=sse BASE_FLAGS += -DNDEBUG endif +BASE_FLAGS += -ansi -pedantic -pedantic-errors -Wall -Wextra -Wformat=2 -Wunused-parameter -Wuninitialized +BASE_FLAGS += -Wcast-qual -Wconversion -Wsign-conversion -Wlogical-op -Waggregate-return +BASE_FLAGS += -fipa-pure-const -Wsuggest-attribute=noreturn #pure,const,noreturn +BASE_FLAGS += -Wno-vla -isystem /usr/include/qt4/ 32BIT_FLAGS = -m32 64BIT_FLAGS = -m64 -BUILD_C_FLAGS = $(BASE_FLAGS) -std=c99 $(CFLAGS) +BUILD_C_FLAGS = $(BASE_FLAGS) -std=c99 -Wc++-compat -Wunsuffixed-float-constants -Wwrite-strings $(CFLAGS) BUILD_CXX_FLAGS = $(BASE_FLAGS) -std=c++0x $(CXXFLAGS) LINK_FLAGS = $(LDFLAGS) +# BUILD_CXX_FLAGS += -Wzero-as-null-pointer-constant + ifneq ($(DEBUG),true) BUILD_CXX_FLAGS += -DQT_NO_DEBUG -DQT_NO_DEBUG_STREAM -DQT_NO_DEBUG_OUTPUT endif diff --git a/source/backend/carla_backend.hpp b/source/backend/carla_backend.hpp index e523e37b3..476d767ae 100644 --- a/source/backend/carla_backend.hpp +++ b/source/backend/carla_backend.hpp @@ -217,7 +217,8 @@ enum InternalParametersIndex { PARAMETER_VOLUME = -4, //!< Volume parameter, range 0.0...1.27; default is 1.0. PARAMETER_BALANCE_LEFT = -5, //!< Stereo Balance-Left parameter, range -1.0...1.0; default is -1.0. PARAMETER_BALANCE_RIGHT = -6, //!< Stereo Balance-Right parameter, range -1.0...1.0; default is 1.0. - PARAMETER_PANNING = -7 //!< Mono Panning parameter, range -1.0...1.0; default is 0.0. + PARAMETER_PANNING = -7, //!< Mono Panning parameter, range -1.0...1.0; default is 0.0. + PARAMETER_MAX = -8 //!< Max value, defined for convenience }; /*! @@ -576,6 +577,19 @@ struct ParameterRanges { step(0.01f), stepSmall(0.0001f), stepLarge(0.1f) {} + + void fixDefault() + { + fixValue(def); + } + + void fixValue(float& value) const + { + if (value < min) + value = min; + else if (value > max) + value = max; + } }; /*! @@ -593,8 +607,7 @@ struct MidiProgramData { ~MidiProgramData() { - if (name) - free((void*)name); + std::free((void*)name); } }; @@ -616,14 +629,9 @@ struct CustomData { ~CustomData() { - if (type) - ::free((void*)type); - - if (key) - ::free((void*)key); - - if (value) - ::free((void*)value); + std::free((void*)type); + std::free((void*)key); + std::free((void*)value); } }; diff --git a/source/backend/carla_engine.hpp b/source/backend/carla_engine.hpp index 89e8c3474..b46469691 100644 --- a/source/backend/carla_engine.hpp +++ b/source/backend/carla_engine.hpp @@ -70,11 +70,13 @@ enum EnginePortType { /*! * Audio port type. + * \see CarlaEngineAudioPort */ kEnginePortTypeAudio = 1, /*! * Event port type. + ** \see CarlaEngineEventPort */ kEnginePortTypeEvent = 2 }; @@ -254,9 +256,9 @@ struct EngineOptions { forceStereo(false), preferPluginBridges(false), preferUiBridges(true), -#ifdef WANT_DSSI + #ifdef WANT_DSSI useDssiVstChunks(false), -#endif + #endif maxParameters(MAX_DEFAULT_PARAMETERS), oscUiTimeout(4000), preferredBufferSize(512), @@ -340,9 +342,8 @@ public: virtual void initBuffer(CarlaEngine* const engine) = 0; protected: - const bool isInput; - const ProcessMode processMode; - void* buffer; + const bool kIsInput; + const ProcessMode kProcessMode; private: CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaEnginePort) @@ -380,6 +381,9 @@ public: */ virtual void initBuffer(CarlaEngine* const engine); +protected: + float* fBuffer; + private: CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaEngineAudioPort) }; @@ -443,7 +447,8 @@ public: virtual void writeMidiEvent(const uint32_t time, const uint8_t channel, const uint8_t* const data, const uint8_t size); private: - const uint32_t m_maxEventCount; + const uint32_t kMaxEventCount; + EngineEvent* fBuffer; CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaEngineEventPort) }; @@ -512,12 +517,12 @@ public: virtual const CarlaEnginePort* addPort(const EnginePortType portType, const char* const name, const bool isInput) = 0; protected: - const EngineType engineType; - const ProcessMode processMode; + const EngineType kEngineType; + const ProcessMode kProcessMode; private: - bool m_active; - uint32_t m_latency; + bool fActive; + uint32_t fLatency; CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaEngineClient) }; @@ -575,12 +580,12 @@ public: /*! * Maximum client name size. */ - virtual int maxClientNameSize(); + virtual unsigned int maxClientNameSize(); /*! * Maximum port name size. */ - virtual int maxPortNameSize(); + virtual unsigned int maxPortNameSize(); /*! * Current number of plugins loaded. @@ -658,13 +663,13 @@ public: * Add new plugin.\n * Returns the id of the plugin, or -1 if the operation failed. */ - short addPlugin(const BinaryType btype, const PluginType ptype, const char* const filename, const char* const name, const char* const label, void* const extra = nullptr); + int addPlugin(const BinaryType btype, const PluginType ptype, const char* const filename, const char* const name, const char* const label, void* const extra = nullptr); /*! * Add new plugin, using native binary type.\n * Returns the id of the plugin, or -1 if the operation failed. */ - short addPlugin(const PluginType ptype, const char* const filename, const char* const name, const char* const label, void* const extra = nullptr) + int addPlugin(const PluginType ptype, const char* const filename, const char* const name, const char* const label, void* const extra = nullptr) { return addPlugin(BINARY_NATIVE, ptype, filename, name, label, extra); } @@ -672,7 +677,7 @@ public: /*! * Remove plugin with id \a id. */ - bool removePlugin(const unsigned short id); + bool removePlugin(const unsigned int id); /*! * Remove all plugins. @@ -842,6 +847,8 @@ protected: #ifndef BUILD_BRIDGE // Rack mode data + EngineEvent* getRackEventBuffer(const bool isInput); + //static const unsigned short MAX_EVENTS = 1024; //EngineEvent fRackEventsIn[MAX_EVENTS]; //EngineEvent fRackEventsOut[MAX_EVENTS]; @@ -919,6 +926,7 @@ private: void osc_send_bridge_set_inpeak(const int32_t portId); void osc_send_bridge_set_outpeak(const int32_t portId); #else +public: void osc_send_control_add_plugin_start(const int32_t pluginId, const char* const pluginName); void osc_send_control_add_plugin_end(const int32_t pluginId); void osc_send_control_remove_plugin(const int32_t pluginId); diff --git a/source/backend/carla_native.h b/source/backend/carla_native.h index 8e3ed65c3..0bb7bcd6a 100644 --- a/source/backend/carla_native.h +++ b/source/backend/carla_native.h @@ -2,17 +2,17 @@ * Carla Native Plugin API * Copyright (C) 2012-2013 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 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 COPYING file + * For a full copy of the GNU General Public License see the GPL.txt file */ #ifndef __CARLA_NATIVE_H__ diff --git a/source/backend/carla_native.hpp b/source/backend/carla_native.hpp index 65c622289..88a5e3bb3 100644 --- a/source/backend/carla_native.hpp +++ b/source/backend/carla_native.hpp @@ -2,17 +2,17 @@ * Carla Native Plugin API * Copyright (C) 2012-2013 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 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 COPYING file + * For a full copy of the GNU General Public License see the GPL.txt file */ #ifndef __CARLA_NATIVE_HPP__ diff --git a/source/backend/carla_plugin.hpp b/source/backend/carla_plugin.hpp index 4d6fdadf9..d84c304ab 100644 --- a/source/backend/carla_plugin.hpp +++ b/source/backend/carla_plugin.hpp @@ -22,11 +22,8 @@ #include "carla_native.h" #include "carla_utils.hpp" -#ifdef WANT_LADSPA -# include "ladspa_rdf.hpp" -#endif - -// Avoid including liblo here +// Avoid including extra libs here +struct LADSPA_RDF_Descriptor; typedef void* lo_address; CARLA_BACKEND_START_NAMESPACE @@ -35,7 +32,7 @@ CARLA_BACKEND_START_NAMESPACE } // Fix editor indentation #endif -#ifndef BUILD_BRIDGE +#if 0 //ndef BUILD_BRIDGE enum PluginBridgeInfoType { kPluginBridgeAudioCount, kPluginBridgeMidiCount, @@ -60,14 +57,14 @@ enum PluginBridgeInfoType { }; #endif -enum PluginPostEventType { - kPluginPostEventNull, - kPluginPostEventDebug, - kPluginPostEventParameterChange, // param, N, value - kPluginPostEventProgramChange, // index - kPluginPostEventMidiProgramChange, // index - kPluginPostEventNoteOn, // channel, note, velo - kPluginPostEventNoteOff // channel, note +enum PluginPostRtEventType { + kPluginPostRtEventNull, + kPluginPostRtEventDebug, + kPluginPostRtEventParameterChange, // param, N, value + kPluginPostRtEventProgramChange, // index + kPluginPostRtEventMidiProgramChange, // index + kPluginPostRtEventNoteOn, // channel, note, velo + kPluginPostRtEventNoteOff // channel, note }; // ----------------------------------------------------------------------- @@ -97,7 +94,7 @@ public: * \param engine The engine which this plugin belongs to, must not be null * \param id The 'id' of this plugin, must be between 0 and CarlaEngine::maxPluginNumber() */ - CarlaPlugin(CarlaEngine* const engine, const unsigned short id); + CarlaPlugin(CarlaEngine* const engine, const unsigned int id); /*! * This is the destructor of the base plugin class. @@ -167,13 +164,19 @@ public: /*! * Get the plugin's category (delay, filter, synth, etc). */ - virtual PluginCategory category(); + virtual PluginCategory category() + { + return PLUGIN_CATEGORY_NONE; + } /*! * Get the plugin's native unique Id.\n * May return 0 on plugin types that don't support Ids. */ - virtual long uniqueId(); + virtual long uniqueId() + { + return 0; + } // ------------------------------------------------------------------- // Information (count) @@ -372,7 +375,7 @@ public: * * \see id() */ - void setId(const unsigned short id); + void setId(const unsigned int id); /*! * Enable or disable the plugin according to \a yesNo. @@ -416,6 +419,8 @@ public: * * \param sendOsc Send message change over OSC * \param sendCallback Send message change to registered callback + * + * \note Pure-Stereo plugins only! */ void setBalanceLeft(double value, const bool sendOsc, const bool sendCallback); @@ -425,14 +430,27 @@ public: * * \param sendOsc Send message change over OSC * \param sendCallback Send message change to registered callback + * + * \note Pure-Stereo plugins only! */ void setBalanceRight(double value, const bool sendOsc, const bool sendCallback); -#ifndef BUILD_BRIDGE + /*! + * Set the plugin's output panning value to \a value.\n + * \a value must be between -1.0 and 1.0. + * + * \param sendOsc Send message change over OSC + * \param sendCallback Send message change to registered callback + * + * \note Force-Stereo plugins only! + */ + void setPanning(double value, const bool sendOsc, const bool sendCallback); + +#if 0 //ndef BUILD_BRIDGE /*! * BridgePlugin call used to set internal data. */ - //virtual int setOscBridgeInfo(const PluginBridgeInfoType type, const int argc, const lo_arg* const* const argv, const char* const types); + virtual int setOscBridgeInfo(const PluginBridgeInfoType type, const int argc, const lo_arg* const* const argv, const char* const types); #endif // ------------------------------------------------------------------- @@ -536,13 +554,6 @@ public: // ------------------------------------------------------------------- // Set gui stuff - /*! - * Set the plugin's custom GUI container.\n - * - * \note This function must be always called from the main thread. - */ - //virtual void setGuiContainer(GuiContainer* const container); - /*! * Show (or hide) the plugin's custom GUI according to \a yesNo. * @@ -589,6 +600,11 @@ public: */ virtual void bufferSizeChanged(const uint32_t newBufferSize); + /*! + * Tell the plugin the current sample rate has changed. + */ + virtual void sampleRateChanged(const double newSampleRate); + /*! * Recreate latency audio buffers. */ @@ -641,7 +657,7 @@ public: * Post pone an event of type \a type.\n * The event will be processed later, but as soon as possible. */ - void postponeEvent(const PluginPostEventType type, const int32_t value1, const int32_t value2, const double value3, const void* const cdata = nullptr); + void postponeEvent(const PluginPostRtEventType type, const int32_t value1, const int32_t value2, const double value3); /*! * Process all the post-poned events. @@ -649,12 +665,6 @@ public: */ void postEventsRun(); - /*! - * Handle custom post event.\n - * Implementation depends on plugin type. - */ - virtual void postEventHandleCustom(const int32_t value1, const int32_t value2, const double value3, const void* const cdata); - /*! * Tell the UI a parameter has changed. */ @@ -732,21 +742,31 @@ public: }; #ifndef BUILD_BRIDGE + static size_t getNativePluginCount(); + static const PluginDescriptor* getNativePluginDescriptor(const size_t index); + static CarlaPlugin* newNative(const Initializer& init); + static CarlaPlugin* newBridge(const Initializer& init, const BinaryType btype, const PluginType ptype, const void* const extra); #endif +#ifdef WANT_LADSPA static CarlaPlugin* newLADSPA(const Initializer& init, const void* const extra); +#endif +#ifdef WANT_DSSI static CarlaPlugin* newDSSI(const Initializer& init, const void* const extra); +#endif +#ifdef WANT_LV2 static CarlaPlugin* newLV2(const Initializer& init); +#endif +#ifdef WANT_VST static CarlaPlugin* newVST(const Initializer& init); -#ifndef BUILD_BRIDGE +#endif +#ifdef WANT_LINUXSAMPLER static CarlaPlugin* newGIG(const Initializer& init); - static CarlaPlugin* newSF2(const Initializer& init); static CarlaPlugin* newSFZ(const Initializer& init); - static CarlaPlugin* newBridge(const Initializer& init, const BinaryType btype, const PluginType ptype, const void* const extra); #endif - - static size_t getNativePluginCount(); - static const PluginDescriptor* getNativePluginDescriptor(const size_t index); +#ifdef WANT_FLUIDSYNTH + static CarlaPlugin* newSF2(const Initializer& init); +#endif // ------------------------------------------------------------------- diff --git a/source/backend/engine/Makefile b/source/backend/engine/Makefile index 091b75ccb..3340bd689 100644 --- a/source/backend/engine/Makefile +++ b/source/backend/engine/Makefile @@ -9,7 +9,7 @@ include ../../Makefile.mk # -------------------------------------------------------------- BUILD_CXX_FLAGS += -fvisibility=hidden -fPIC -I. -I.. -I../../includes -I../../libs -I../../utils -BUILD_CXX_FLAGS += $(shell pkg-config --cflags liblo QtCore) +BUILD_CXX_FLAGS += $(shell pkg-config --cflags QtCore) # liblo -isystem /opt/kxstudio/include/ LINK_FLAGS += -shared LINK_FLAGS += $(shell pkg-config --libs liblo QtCore) @@ -49,16 +49,17 @@ endif # -------------------------------------------------------------- OBJS = \ - carla_engine.cpp.o + carla_engine.cpp.o \ + jack.cpp.o + # carla_engine_osc.cpp.o \ # carla_engine_thread.cpp.o \ -# jack.cpp.o \ # rtaudio.cpp.o ifeq ($(WANT_RTAUDIO),true) -OBJS += \ - rtaudio-4.0.11/RtAudio.cpp.o \ - rtmidi-2.0.1/RtMidi.cpp.o +# OBJS += \ +# rtaudio-4.0.11/RtAudio.cpp.o \ +# rtmidi-2.0.1/RtMidi.cpp.o endif TARGET = ../carla_engine.so diff --git a/source/backend/engine/carla_engine.cpp b/source/backend/engine/carla_engine.cpp index c6bba5386..129a26553 100644 --- a/source/backend/engine/carla_engine.cpp +++ b/source/backend/engine/carla_engine.cpp @@ -24,13 +24,11 @@ CARLA_BACKEND_START_NAMESPACE // ------------------------------------------------------------------------------------------------------------------- // Carla Engine port (Abstract) -CarlaEnginePort::CarlaEnginePort(const bool isInput_, const ProcessMode processMode_) - : isInput(isInput_), - processMode(processMode_) +CarlaEnginePort::CarlaEnginePort(const bool isInput, const ProcessMode processMode) + : kIsInput(isInput), + kProcessMode(processMode) { qDebug("CarlaEnginePort::CarlaEnginePort(%s, %s)", bool2str(isInput), ProcessMode2Str(processMode)); - - buffer = nullptr; } CarlaEnginePort::~CarlaEnginePort() @@ -47,9 +45,11 @@ CarlaEngineAudioPort::CarlaEngineAudioPort(const bool isInput, const ProcessMode qDebug("CarlaEngineAudioPort::CarlaEngineAudioPort(%s, %s)", bool2str(isInput), ProcessMode2Str(processMode)); #ifndef BUILD_BRIDGE - if (processMode == PROCESS_MODE_PATCHBAY) - buffer = new float[PATCHBAY_BUFFER_SIZE]; + if (kProcessMode == PROCESS_MODE_PATCHBAY) + fBuffer = new float[PATCHBAY_BUFFER_SIZE]; + else #endif + fBuffer = nullptr; } CarlaEngineAudioPort::~CarlaEngineAudioPort() @@ -57,12 +57,12 @@ CarlaEngineAudioPort::~CarlaEngineAudioPort() qDebug("CarlaEngineAudioPort::~CarlaEngineAudioPort()"); #ifndef BUILD_BRIDGE - if (processMode == PROCESS_MODE_PATCHBAY) + if (kProcessMode == PROCESS_MODE_PATCHBAY) { - CARLA_ASSERT(buffer); + CARLA_ASSERT(fBuffer); - if (buffer) - delete[] (float*)buffer; + if (fBuffer) + delete[] (float*)fBuffer; } #endif } @@ -70,10 +70,10 @@ CarlaEngineAudioPort::~CarlaEngineAudioPort() void CarlaEngineAudioPort::initBuffer(CarlaEngine* const) { #ifndef BUILD_BRIDGE - if (processMode != PROCESS_MODE_PATCHBAY) - buffer = nullptr; - else if (! isInput) - carla_zeroFloat((float*)buffer, PATCHBAY_BUFFER_SIZE); + if (kProcessMode != PROCESS_MODE_PATCHBAY) + fBuffer = nullptr; + else if (! kIsInput) + carla_zeroFloat(fBuffer, PATCHBAY_BUFFER_SIZE); #endif } @@ -82,14 +82,16 @@ void CarlaEngineAudioPort::initBuffer(CarlaEngine* const) CarlaEngineEventPort::CarlaEngineEventPort(const bool isInput, const ProcessMode processMode) : CarlaEnginePort(isInput, processMode), - m_maxEventCount(processMode == PROCESS_MODE_CONTINUOUS_RACK ? CarlaEngine::MAX_EVENTS : PATCHBAY_EVENT_COUNT) + kMaxEventCount(processMode == PROCESS_MODE_CONTINUOUS_RACK ? RACK_EVENT_COUNT : PATCHBAY_EVENT_COUNT) { qDebug("CarlaEngineEventPort::CarlaEngineEventPort(%s, %s)", bool2str(isInput), ProcessMode2Str(processMode)); #ifndef BUILD_BRIDGE - if (processMode == PROCESS_MODE_PATCHBAY) - buffer = new EngineEvent[PATCHBAY_EVENT_COUNT]; + if (kProcessMode == PROCESS_MODE_PATCHBAY) + fBuffer = new EngineEvent[PATCHBAY_EVENT_COUNT]; + else #endif + fBuffer = nullptr; } CarlaEngineEventPort::~CarlaEngineEventPort() @@ -97,47 +99,50 @@ CarlaEngineEventPort::~CarlaEngineEventPort() qDebug("CarlaEngineEventPort::~CarlaEngineEventPort()"); #ifndef BUILD_BRIDGE - if (processMode == PROCESS_MODE_PATCHBAY) + if (kProcessMode == PROCESS_MODE_PATCHBAY) { - CARLA_ASSERT(buffer); + CARLA_ASSERT(fBuffer); - if (buffer) - delete[] (EngineEvent*)buffer; + if (fBuffer) + delete[] fBuffer; } #endif } void CarlaEngineEventPort::initBuffer(CarlaEngine* const engine) { - CARLA_ASSERT(engine); + CARLA_ASSERT(engine != nullptr); + + if (engine == nullptr) + return; #ifndef BUILD_BRIDGE - if (processMode == PROCESS_MODE_CONTINUOUS_RACK) - buffer = isInput ? engine->rackEventsIn : engine->rackEventsOut; - else if (processMode == PROCESS_MODE_PATCHBAY && ! isInput) - carla_zeroMem(buffer, sizeof(EngineEvent)*PATCHBAY_EVENT_COUNT); + if (kProcessMode == PROCESS_MODE_CONTINUOUS_RACK) + fBuffer = engine->getRackEventBuffer(kIsInput); + else if (kProcessMode == PROCESS_MODE_PATCHBAY && ! kIsInput) + carla_zeroMem(fBuffer, sizeof(EngineEvent)*PATCHBAY_EVENT_COUNT); #endif } uint32_t CarlaEngineEventPort::getEventCount() { - if (! isInput) + if (! kIsInput) return 0; - CARLA_ASSERT(buffer); + CARLA_ASSERT(fBuffer != nullptr); - if (! buffer) + if (fBuffer == nullptr) return 0; #ifndef BUILD_BRIDGE - if (processMode == PROCESS_MODE_CONTINUOUS_RACK || processMode == PROCESS_MODE_PATCHBAY) + if (kProcessMode == PROCESS_MODE_CONTINUOUS_RACK || kProcessMode == PROCESS_MODE_PATCHBAY) { uint32_t count = 0; - const EngineEvent* const events = (EngineEvent*)buffer; + const EngineEvent* const events = fBuffer; - for (unsigned short i=0; i < m_maxEventCount; i++, count++) + for (unsigned short i=0; i < kMaxEventCount; i++, count++) { - if (events[i].type == EngineEventTypeNull) + if (events[i].type == kEngineEventTypeNull) break; } @@ -150,21 +155,21 @@ uint32_t CarlaEngineEventPort::getEventCount() const EngineEvent* CarlaEngineEventPort::getEvent(const uint32_t index) { - if (! isInput) + if (! kIsInput) return nullptr; - CARLA_ASSERT(buffer); - CARLA_ASSERT(index < m_maxEventCount); + CARLA_ASSERT(fBuffer != nullptr); + CARLA_ASSERT(index < kMaxEventCount); - if (! buffer) + if (fBuffer == nullptr) return nullptr; - if (index >= m_maxEventCount) + if (index >= kMaxEventCount) return nullptr; #ifndef BUILD_BRIDGE - if (processMode == PROCESS_MODE_CONTINUOUS_RACK || processMode == PROCESS_MODE_PATCHBAY) + if (kProcessMode == PROCESS_MODE_CONTINUOUS_RACK || kProcessMode == PROCESS_MODE_PATCHBAY) { - const EngineEvent* const events = (EngineEvent*)buffer; + const EngineEvent* const events = fBuffer; return &events[index]; } @@ -175,35 +180,35 @@ const EngineEvent* CarlaEngineEventPort::getEvent(const uint32_t index) void CarlaEngineEventPort::writeControlEvent(const uint32_t time, const uint8_t channel, const EngineControlEventType type, const uint16_t parameter, const double value) { - if (isInput) + if (kIsInput) return; - CARLA_ASSERT(buffer); - CARLA_ASSERT(type != EngineControlEventTypeNull); + CARLA_ASSERT(fBuffer != nullptr); + CARLA_ASSERT(type != kEngineControlEventTypeNull); CARLA_ASSERT(channel < MAX_MIDI_CHANNELS); - if (! buffer) + if (fBuffer == nullptr) return; - if (type == EngineControlEventTypeNull) + if (type == kEngineControlEventTypeNull) return; if (channel >= MAX_MIDI_CHANNELS) return; - if (type == EngineControlEventTypeParameter) + if (type == kEngineControlEventTypeParameter) { CARLA_ASSERT(! MIDI_IS_CONTROL_BANK_SELECT(parameter)); } #ifndef BUILD_BRIDGE - if (processMode == PROCESS_MODE_CONTINUOUS_RACK || processMode == PROCESS_MODE_PATCHBAY) + if (kProcessMode == PROCESS_MODE_CONTINUOUS_RACK || kProcessMode == PROCESS_MODE_PATCHBAY) { - EngineEvent* const events = (EngineEvent*)buffer; + EngineEvent* const events = fBuffer; - for (unsigned short i=0; i < m_maxEventCount; i++) + for (unsigned short i=0; i < kMaxEventCount; i++) { - if (events[i].type != EngineEventTypeNull) + if (events[i].type != kEngineEventTypeNull) continue; - events[i].type = EngineEventTypeControl; + events[i].type = kEngineEventTypeControl; events[i].time = time; events[i].channel = channel; @@ -225,15 +230,15 @@ void CarlaEngineEventPort::writeControlEvent(const uint32_t time, const uint8_t void CarlaEngineEventPort::writeMidiEvent(const uint32_t time, const uint8_t channel, const uint8_t* const data, const uint8_t size) { - if (isInput) + if (kIsInput) return; - CARLA_ASSERT(buffer); + CARLA_ASSERT(fBuffer != nullptr); CARLA_ASSERT(channel < MAX_MIDI_CHANNELS); CARLA_ASSERT(data); CARLA_ASSERT(size > 0); - if (! buffer) + if (fBuffer == nullptr) return; if (channel >= MAX_MIDI_CHANNELS) return; @@ -241,19 +246,19 @@ void CarlaEngineEventPort::writeMidiEvent(const uint32_t time, const uint8_t cha return; #ifndef BUILD_BRIDGE - if (processMode == PROCESS_MODE_CONTINUOUS_RACK || processMode == PROCESS_MODE_PATCHBAY) + if (kProcessMode == PROCESS_MODE_CONTINUOUS_RACK || kProcessMode == PROCESS_MODE_PATCHBAY) { if (size > 3) return; - EngineEvent* const events = (EngineEvent*)buffer; + EngineEvent* const events = fBuffer; - for (unsigned short i=0; i < m_maxEventCount; i++) + for (unsigned short i=0; i < kMaxEventCount; i++) { - if (events[i].type != EngineEventTypeNull) + if (events[i].type != kEngineEventTypeNull) continue; - events[i].type = EngineEventTypeMidi; + events[i].type = kEngineEventTypeMidi; events[i].time = time; events[i].channel = channel; @@ -275,44 +280,44 @@ void CarlaEngineEventPort::writeMidiEvent(const uint32_t time, const uint8_t cha // ------------------------------------------------------------------------------------------------------------------- // Carla Engine client (Abstract) -CarlaEngineClient::CarlaEngineClient(const EngineType engineType_, const ProcessMode processMode_) - : engineType(engineType_), - processMode(processMode_) +CarlaEngineClient::CarlaEngineClient(const EngineType engineType, const ProcessMode processMode) + : kEngineType(engineType), + kProcessMode(processMode) { qDebug("CarlaEngineClient::CarlaEngineClient(%s, %s)", EngineType2Str(engineType), ProcessMode2Str(processMode)); - CARLA_ASSERT(engineType != EngineTypeNull); + CARLA_ASSERT(engineType != kEngineTypeNull); - m_active = false; - m_latency = 0; + fActive = false; + fLatency = 0; } CarlaEngineClient::~CarlaEngineClient() { qDebug("CarlaEngineClient::~CarlaEngineClient()"); - CARLA_ASSERT(! m_active); + CARLA_ASSERT(! fActive); } void CarlaEngineClient::activate() { qDebug("CarlaEngineClient::activate()"); - CARLA_ASSERT(! m_active); + CARLA_ASSERT(! fActive); - m_active = true; + fActive = true; } void CarlaEngineClient::deactivate() { qDebug("CarlaEngineClient::deactivate()"); - CARLA_ASSERT(m_active); + CARLA_ASSERT(fActive); - m_active = false; + fActive = false; } bool CarlaEngineClient::isActive() const { qDebug("CarlaEngineClient::isActive()"); - return m_active; + return fActive; } bool CarlaEngineClient::isOk() const @@ -324,24 +329,24 @@ bool CarlaEngineClient::isOk() const uint32_t CarlaEngineClient::getLatency() const { - return m_latency; + return fLatency; } void CarlaEngineClient::setLatency(const uint32_t samples) { - m_latency = samples; + fLatency = samples; } // ------------------------------------------------------------------------------------------------------------------- // Carla Engine CarlaEngine::CarlaEngine() - : data(new CarlaEnginePrivateData(this)) + : fData(new CarlaEngineProtectedData(this)) { qDebug("CarlaEngine::CarlaEngine()"); - bufferSize = 0; - sampleRate = 0.0; + fBufferSize = 0; + fSampleRate = 0.0; } CarlaEngine::~CarlaEngine() @@ -437,24 +442,24 @@ CarlaEngine* CarlaEngine::newDriverByName(const char* const driverName) // ----------------------------------------------------------------------- // Maximum values -int CarlaEngine::maxClientNameSize() +unsigned int CarlaEngine::maxClientNameSize() { return STR_MAX/2; } -int CarlaEngine::maxPortNameSize() +unsigned int CarlaEngine::maxPortNameSize() { return STR_MAX; } unsigned int CarlaEngine::currentPluginCount() const { - return data->curPluginCount; + return fData->curPluginCount; } unsigned int CarlaEngine::maxPluginNumber() const { - return data->maxPluginNumber; + return fData->maxPluginNumber; } // ----------------------------------------------------------------------- @@ -463,33 +468,33 @@ unsigned int CarlaEngine::maxPluginNumber() const bool CarlaEngine::init(const char* const clientName) { qDebug("CarlaEngine::init(\"%s\")", clientName); - CARLA_ASSERT(! data->plugins); + CARLA_ASSERT(fData->plugins == nullptr); - data->aboutToClose = false; - data->curPluginCount = 0; - data->maxPluginNumber = 0; + fData->aboutToClose = false; + fData->curPluginCount = 0; + fData->maxPluginNumber = 0; - switch (options.processMode) + switch (fOptions.processMode) { case PROCESS_MODE_CONTINUOUS_RACK: - data->maxPluginNumber = MAX_RACK_PLUGINS; + fData->maxPluginNumber = MAX_RACK_PLUGINS; break; case PROCESS_MODE_PATCHBAY: - data->maxPluginNumber = MAX_PATCHBAY_PLUGINS; + fData->maxPluginNumber = MAX_PATCHBAY_PLUGINS; break; default: - data->maxPluginNumber = MAX_DEFAULT_PLUGINS; + fData->maxPluginNumber = MAX_DEFAULT_PLUGINS; break; } - data->plugins = new EnginePluginData[data->maxPluginNumber]; + fData->plugins = new EnginePluginData[fData->maxPluginNumber]; - data->osc.init(clientName); + fData->osc.init(clientName); #ifndef BUILD_BRIDGE - data->oscData = data->osc.getControlData(); + fData->oscData = fData->osc.getControlData(); #else - data->oscData = nullptr; // set in setOscBridgeData() + fData->oscData = nullptr; // set in setOscBridgeData() #endif #ifndef BUILD_BRIDGE @@ -497,7 +502,7 @@ bool CarlaEngine::init(const char* const clientName) carla_setprocname(clientName); #endif - data->thread.startNow(); + fData->thread.startNow(); return true; } @@ -505,28 +510,28 @@ bool CarlaEngine::init(const char* const clientName) bool CarlaEngine::close() { qDebug("CarlaEngine::close()"); - CARLA_ASSERT(data->plugins); + CARLA_ASSERT(fData->plugins != nullptr); - data->thread.stopNow(); + fData->thread.stopNow(); #ifndef BUILD_BRIDGE osc_send_control_exit(); #endif - data->osc.close(); + fData->osc.close(); - data->oscData = nullptr; + fData->oscData = nullptr; - data->aboutToClose = true; - data->curPluginCount = 0; - data->maxPluginNumber = 0; + fData->aboutToClose = true; + fData->curPluginCount = 0; + fData->maxPluginNumber = 0; - if (data->plugins) + if (fData->plugins != nullptr) { - delete[] data->plugins; - data->plugins = nullptr; + delete[] fData->plugins; + fData->plugins = nullptr; } - name.clear(); + fName.clear(); return true; } @@ -546,41 +551,41 @@ int CarlaEngine::getNewPluginId() const CarlaPlugin* CarlaEngine::getPlugin(const unsigned short id) const { - qDebug("CarlaEngine::getPlugin(%i) [count:%i]", id, data->curPluginCount); - CARLA_ASSERT(data->curPluginCount > 0); - CARLA_ASSERT(id < data->curPluginCount); - CARLA_ASSERT(data->plugins); + qDebug("CarlaEngine::getPlugin(%i) [count:%i]", id, fData->curPluginCount); + CARLA_ASSERT(fData->curPluginCount > 0); + CARLA_ASSERT(id < fData->curPluginCount); + CARLA_ASSERT(fData->plugins != nullptr); - if (id < data->curPluginCount && data->plugins) - return data->plugins[id].plugin; + if (id < fData->curPluginCount && fData->plugins) + return fData->plugins[id].plugin; return nullptr; } CarlaPlugin* CarlaEngine::getPluginUnchecked(const unsigned short id) const { - return data->plugins[id].plugin; + return fData->plugins[id].plugin; } const char* CarlaEngine::getNewUniquePluginName(const char* const name) { qDebug("CarlaEngine::getNewUniquePluginName(\"%s\")", name); - CARLA_ASSERT(data->curPluginCount > 0); - CARLA_ASSERT(data->plugins); + CARLA_ASSERT(fData->curPluginCount > 0); + CARLA_ASSERT(fData->plugins != nullptr); CARLA_ASSERT(name); CarlaString sname(name); - if (sname.isEmpty() || ! data->plugins) + if (sname.isEmpty() || fData->plugins == nullptr) return strdup("(No name)"); sname.truncate(maxClientNameSize()-5-1); // 5 = strlen(" (10)") sname.replace(':', '.'); // ':' is used in JACK1 to split client/port names - for (unsigned short i=0; i < data->curPluginCount; i++) + for (unsigned short i=0; i < fData->curPluginCount; i++) { // Check if unique name doesn't exist - if (const char* const pluginName = data->plugins[i].plugin->name()) + if (const char* const pluginName = fData->plugins[i].plugin->name()) { if (sname != pluginName) continue; @@ -593,7 +598,7 @@ const char* CarlaEngine::getNewUniquePluginName(const char* const name) // 1 digit, ex: " (2)" if (sname[len-4] == ' ' && sname[len-3] == '(' && sname.isDigit(len-2) && sname[len-1] == ')') { - int number = sname[len-2]-'0'; + int number = sname[len-2] - '0'; if (number == 9) { @@ -603,7 +608,7 @@ const char* CarlaEngine::getNewUniquePluginName(const char* const name) //sname.replace(" (9)", " (10)"); } else - sname[len-2] = '0'+number+1; + sname[len-2] = '0' + number + 1; continue; } @@ -636,7 +641,7 @@ const char* CarlaEngine::getNewUniquePluginName(const char* const name) return strdup(sname); } -short CarlaEngine::addPlugin(const BinaryType btype, const PluginType ptype, const char* const filename, const char* const name, const char* const label, void* const extra) +int CarlaEngine::addPlugin(const BinaryType btype, const PluginType ptype, const char* const filename, const char* const name, const char* const label, void* const extra) { qDebug("CarlaEngine::addPlugin(%s, %s, \"%s\", \"%s\", \"%s\", %p)", BinaryType2Str(btype), PluginType2Str(ptype), filename, name, label, extra); CARLA_ASSERT(btype != BINARY_NONE); @@ -659,34 +664,38 @@ short CarlaEngine::addPlugin(const BinaryType btype, const PluginType ptype, con switch (btype) { case BINARY_POSIX32: - bridgeBinary = options.bridge_posix32.isNotEmpty() ? (const char*)options.bridge_posix32 : nullptr; + bridgeBinary = fOptions.bridge_posix32.isNotEmpty() ? (const char*)fOptions.bridge_posix32 : nullptr; + break; case BINARY_POSIX64: - bridgeBinary = options.bridge_posix64.isNotEmpty() ? (const char*)options.bridge_posix64 : nullptr; + bridgeBinary = fOptions.bridge_posix64.isNotEmpty() ? (const char*)fOptions.bridge_posix64 : nullptr; + break; case BINARY_WIN32: - bridgeBinary = options.bridge_win32.isNotEmpty() ? (const char*)options.bridge_win32 : nullptr; + bridgeBinary = fOptions.bridge_win32.isNotEmpty() ? (const char*)fOptions.bridge_win32 : nullptr; + break; case BINARY_WIN64: - bridgeBinary = options.bridge_win64.isNotEmpty() ? (const char*)options.bridge_win64 : nullptr; + bridgeBinary = fOptions.bridge_win64.isNotEmpty() ? (const char*)fOptions.bridge_win64 : nullptr; + break; default: bridgeBinary = nullptr; break; } #ifndef Q_OS_WIN - if (btype == BINARY_NATIVE && options.bridge_native.isNotEmpty()) - bridgeBinary = (const char*)options.bridge_native; + if (btype == BINARY_NATIVE && fOptions.bridge_native.isNotEmpty()) + bridgeBinary = (const char*)fOptions.bridge_native; #endif - if (options.preferPluginBridges && bridgeBinary) + if (fOptions.preferPluginBridges && bridgeBinary != nullptr) { // TODO - if (options.processMode != PROCESS_MODE_MULTIPLE_CLIENTS) + if (fOptions.processMode != PROCESS_MODE_MULTIPLE_CLIENTS) { setLastError("Can only use bridged plugins in JACK Multi-Client mode"); return -1; } // TODO - if (type() != EngineTypeJack) + if (type() != kEngineTypeJack) { setLastError("Can only use bridged plugins with JACK backend"); return -1; @@ -701,55 +710,80 @@ short CarlaEngine::addPlugin(const BinaryType btype, const PluginType ptype, con { case PLUGIN_NONE: break; -#ifndef BUILD_BRIDGE case PLUGIN_INTERNAL: +#ifndef BUILD_BRIDGE plugin = CarlaPlugin::newNative(init); - break; #endif + break; + case PLUGIN_LADSPA: +#ifdef WANT_LADSPA plugin = CarlaPlugin::newLADSPA(init, extra); +#endif break; + case PLUGIN_DSSI: +#ifdef WANT_DSSI plugin = CarlaPlugin::newDSSI(init, extra); +#endif break; + case PLUGIN_LV2: +#ifdef WANT_LV2 plugin = CarlaPlugin::newLV2(init); +#endif break; + case PLUGIN_VST: +#ifdef WANT_VST plugin = CarlaPlugin::newVST(init); +#endif break; -#ifndef BUILD_BRIDGE + case PLUGIN_GIG: +#ifdef WANT_LINUXSAMPLER plugin = CarlaPlugin::newGIG(init); +#endif break; + case PLUGIN_SF2: +#ifdef WANT_FLUIDSYNTH plugin = CarlaPlugin::newSF2(init); +#endif break; + case PLUGIN_SFZ: +#ifdef WANT_LINUXSAMPLER plugin = CarlaPlugin::newSFZ(init); - break; #endif + break; } } if (! plugin) return -1; - const short id = data->curPluginCount++; + const unsigned int id = fData->curPluginCount++; plugin->setId(id); - return id; + return static_cast(id); } -bool CarlaEngine::removePlugin(const unsigned short id) +bool CarlaEngine::removePlugin(const unsigned int id) { qDebug("CarlaEngine::removePlugin(%i)", id); - CARLA_ASSERT(data->curPluginCount > 0); - CARLA_ASSERT(id < data->curPluginCount); - CARLA_ASSERT(data->plugins); + CARLA_ASSERT(fData->curPluginCount > 0); + CARLA_ASSERT(id < fData->curPluginCount); + CARLA_ASSERT(fData->plugins != nullptr); + + if (fData->plugins == nullptr) + { + // TODO - warning + return false; + } - CarlaPlugin* plugin = data->plugins[id].plugin; + CarlaPlugin* plugin = fData->plugins[id].plugin; CARLA_ASSERT(plugin); @@ -757,17 +791,17 @@ bool CarlaEngine::removePlugin(const unsigned short id) { CARLA_ASSERT(plugin->id() == id); - data->thread.stopNow(); + fData->thread.stopNow(); // wait for processing to stop for this plugin // TODO // clear this plugin - data->plugins[id].plugin = nullptr; - data->plugins[id].insPeak[0] = 0.0; - data->plugins[id].insPeak[1] = 0.0; - data->plugins[id].outsPeak[0] = 0.0; - data->plugins[id].outsPeak[1] = 0.0; + fData->plugins[id].plugin = nullptr; + fData->plugins[id].insPeak[0] = 0.0; + fData->plugins[id].insPeak[1] = 0.0; + fData->plugins[id].outsPeak[0] = 0.0; + fData->plugins[id].outsPeak[1] = 0.0; // wait for processing to stop for this plugin // TODO @@ -781,29 +815,29 @@ bool CarlaEngine::removePlugin(const unsigned short id) delete plugin; #ifndef BUILD_BRIDGE - osc_send_control_remove_plugin(id); + osc_send_control_remove_plugin(static_cast(id)); // move all plugins 1 spot backwards - for (unsigned short i=id; i < data->curPluginCount-1; i++) + for (unsigned int i=id; i < fData->curPluginCount-1; i++) { - plugin = data->plugins[i+1].plugin; + plugin = fData->plugins[i+1].plugin; CARLA_ASSERT(plugin); if (plugin) plugin->setId(i); - data->plugins[i].plugin = plugin; - data->plugins[i].insPeak[0] = 0.0; - data->plugins[i].insPeak[1] = 0.0; - data->plugins[i].outsPeak[0] = 0.0; - data->plugins[i].outsPeak[1] = 0.0; + fData->plugins[i].plugin = plugin; + fData->plugins[i].insPeak[0] = 0.0; + fData->plugins[i].insPeak[1] = 0.0; + fData->plugins[i].outsPeak[0] = 0.0; + fData->plugins[i].outsPeak[1] = 0.0; } - data->curPluginCount--; + fData->curPluginCount--; - if (isRunning() && ! data->aboutToClose) - data->thread.startNow(); + if (isRunning() && ! fData->aboutToClose) + fData->thread.startNow(); #endif return true; @@ -818,19 +852,19 @@ void CarlaEngine::removeAllPlugins() { qDebug("CarlaEngine::removeAllPlugins()"); - data->thread.stopNow(); + fData->thread.stopNow(); - const unsigned int oldCount = data->curPluginCount; + const unsigned int oldCount = fData->curPluginCount; // wait for processing // TODO - data->curPluginCount = 0; - data->maxPluginNumber = 0; + fData->curPluginCount = 0; + fData->maxPluginNumber = 0; for (unsigned short i=0; i < oldCount; i++) { - CarlaPlugin* const plugin = data->plugins[i].plugin; + CarlaPlugin* const plugin = fData->plugins[i].plugin; CARLA_ASSERT(plugin); @@ -838,15 +872,15 @@ void CarlaEngine::removeAllPlugins() delete plugin; // clear this plugin - data->plugins[i].plugin = nullptr; - data->plugins[i].insPeak[0] = 0.0; - data->plugins[i].insPeak[1] = 0.0; - data->plugins[i].outsPeak[0] = 0.0; - data->plugins[i].outsPeak[1] = 0.0; + fData->plugins[i].plugin = nullptr; + fData->plugins[i].insPeak[0] = 0.0; + fData->plugins[i].insPeak[1] = 0.0; + fData->plugins[i].outsPeak[0] = 0.0; + fData->plugins[i].outsPeak[1] = 0.0; } - if (isRunning() && ! data->aboutToClose) - data->thread.startNow(); + if (isRunning() && ! fData->aboutToClose) + fData->thread.startNow(); } #if 0 @@ -875,7 +909,7 @@ void CarlaEngine::__bridgePluginRegister(const unsigned short id, CarlaPlugin* c void CarlaEngine::setAboutToClose() { qDebug("CarlaEngine::setAboutToClose()"); - data->aboutToClose = true; + fData->aboutToClose = true; } #if 0 @@ -922,8 +956,8 @@ void CarlaEngine::callback(const CallbackType action, const unsigned short plugi { qDebug("CarlaEngine::callback(%s, %i, %i, %i, %f, \"%s\")", CallbackType2Str(action), pluginId, value1, value2, value3, valueStr); - if (data->callback) - data->callback(data->callbackPtr, action, pluginId, value1, value2, value3, valueStr); + if (fData->callback) + fData->callback(fData->callbackPtr, action, pluginId, value1, value2, value3, valueStr); } void CarlaEngine::setCallback(const CallbackFunc func, void* const ptr) @@ -931,8 +965,8 @@ void CarlaEngine::setCallback(const CallbackFunc func, void* const ptr) qDebug("CarlaEngine::setCallback(%p, %p)", func, ptr); CARLA_ASSERT(func); - data->callback = func; - data->callbackPtr = ptr; + fData->callback = func; + fData->callbackPtr = ptr; } // ----------------------------------------------------------------------- @@ -940,12 +974,12 @@ void CarlaEngine::setCallback(const CallbackFunc func, void* const ptr) const char* CarlaEngine::getLastError() const { - return (const char*)data->lastError; + return (const char*)fData->lastError; } void CarlaEngine::setLastError(const char* const error) { - data->lastError = error; + fData->lastError = error; } // ----------------------------------------------------------------------- @@ -955,7 +989,7 @@ void CarlaEngine::setLastError(const char* const error) const QProcessEnvironment& CarlaEngine::getOptionsAsProcessEnvironment() const { - return data->procEnv; + return fData->procEnv; } #define CARLA_ENGINE_SET_OPTION_RUNNING_CHECK \ @@ -978,7 +1012,7 @@ void CarlaEngine::setOption(const OptionsType option, const int value, const cha if (value < PROCESS_MODE_SINGLE_CLIENT || value > PROCESS_MODE_PATCHBAY) return qCritical("CarlaEngine::setOption(%s, %i, \"%s\") - invalid value", OptionsType2Str(option), value, valueStr); - options.processMode = static_cast(value); + fOptions.processMode = static_cast(value); break; case OPTION_MAX_PARAMETERS: @@ -987,95 +1021,95 @@ void CarlaEngine::setOption(const OptionsType option, const int value, const cha if (value < 0) return; // TODO error here - options.maxParameters = value; + fOptions.maxParameters = static_cast(value); break; case OPTION_PREFERRED_BUFFER_SIZE: CARLA_ENGINE_SET_OPTION_RUNNING_CHECK - options.preferredBufferSize = value; + fOptions.preferredBufferSize = static_cast(value); break; case OPTION_PREFERRED_SAMPLE_RATE: CARLA_ENGINE_SET_OPTION_RUNNING_CHECK - options.preferredSampleRate = value; + fOptions.preferredSampleRate = static_cast(value); break; case OPTION_FORCE_STEREO: CARLA_ENGINE_SET_OPTION_RUNNING_CHECK - options.forceStereo = value; + fOptions.forceStereo = (value != 0); break; #ifdef WANT_DSSI case OPTION_USE_DSSI_VST_CHUNKS: CARLA_ENGINE_SET_OPTION_RUNNING_CHECK - options.useDssiVstChunks = value; + fOptions.useDssiVstChunks = (value != 0); break; #endif case OPTION_PREFER_PLUGIN_BRIDGES: CARLA_ENGINE_SET_OPTION_RUNNING_CHECK - options.preferPluginBridges = value; + fOptions.preferPluginBridges = (value != 0); break; case OPTION_PREFER_UI_BRIDGES: CARLA_ENGINE_SET_OPTION_RUNNING_CHECK - options.preferUiBridges = value; + fOptions.preferUiBridges = (value != 0); break; case OPTION_OSC_UI_TIMEOUT: CARLA_ENGINE_SET_OPTION_RUNNING_CHECK - options.oscUiTimeout = value; + fOptions.oscUiTimeout = static_cast(value); break; case OPTION_PATH_BRIDGE_NATIVE: - options.bridge_native = valueStr; + fOptions.bridge_native = valueStr; break; case OPTION_PATH_BRIDGE_POSIX32: - options.bridge_posix32 = valueStr; + fOptions.bridge_posix32 = valueStr; break; case OPTION_PATH_BRIDGE_POSIX64: - options.bridge_posix64 = valueStr; + fOptions.bridge_posix64 = valueStr; break; case OPTION_PATH_BRIDGE_WIN32: - options.bridge_win32 = valueStr; + fOptions.bridge_win32 = valueStr; break; case OPTION_PATH_BRIDGE_WIN64: - options.bridge_win64 = valueStr; + fOptions.bridge_win64 = valueStr; break; #ifdef WANT_LV2 case OPTION_PATH_BRIDGE_LV2_GTK2: - options.bridge_lv2gtk2 = valueStr; + fOptions.bridge_lv2gtk2 = valueStr; break; case OPTION_PATH_BRIDGE_LV2_GTK3: - options.bridge_lv2gtk3 = valueStr; + fOptions.bridge_lv2gtk3 = valueStr; break; case OPTION_PATH_BRIDGE_LV2_QT4: - options.bridge_lv2qt4 = valueStr; + fOptions.bridge_lv2qt4 = valueStr; break; case OPTION_PATH_BRIDGE_LV2_QT5: - options.bridge_lv2qt5 = valueStr; + fOptions.bridge_lv2qt5 = valueStr; break; case OPTION_PATH_BRIDGE_LV2_COCOA: - options.bridge_lv2cocoa = valueStr; + fOptions.bridge_lv2cocoa = valueStr; break; case OPTION_PATH_BRIDGE_LV2_WINDOWS: - options.bridge_lv2win = valueStr; + fOptions.bridge_lv2win = valueStr; break; case OPTION_PATH_BRIDGE_LV2_X11: - options.bridge_lv2x11 = valueStr; + fOptions.bridge_lv2x11 = valueStr; break; #endif #ifdef WANT_VST case OPTION_PATH_BRIDGE_VST_COCOA: - options.bridge_vstcocoa = valueStr; + fOptions.bridge_vstcocoa = valueStr; break; case OPTION_PATH_BRIDGE_VST_HWND: - options.bridge_vsthwnd = valueStr; + fOptions.bridge_vsthwnd = valueStr; break; case OPTION_PATH_BRIDGE_VST_X11: - options.bridge_vstx11 = valueStr; + fOptions.bridge_vstx11 = valueStr; break; #endif } @@ -1088,40 +1122,41 @@ void CarlaEngine::setOption(const OptionsType option, const int value, const cha #ifdef BUILD_BRIDGE bool CarlaEngine::isOscBridgeRegistered() const { - return bool(data->oscData); + return (fData->oscData != nullptr); } #else bool CarlaEngine::isOscControlRegistered() const { - return data->osc.isControlRegistered(); + return fData->osc.isControlRegistered(); } #endif void CarlaEngine::idleOsc() { - data->osc.idle(); + fData->osc.idle(); } const char* CarlaEngine::getOscServerPathTCP() const { - return data->osc.getServerPathTCP(); + return fData->osc.getServerPathTCP(); } const char* CarlaEngine::getOscServerPathUDP() const { - return data->osc.getServerPathUDP(); + return fData->osc.getServerPathUDP(); } #ifdef BUILD_BRIDGE void CarlaEngine::setOscBridgeData(const CarlaOscData* const oscData) { - data->oscData = oscData; + fData->oscData = oscData; } #endif // ----------------------------------------------------------------------- // protected calls +#if 0 #ifndef BUILD_BRIDGE void CarlaEngine::processRack(float* inBuf[2], float* outBuf[2], const uint32_t frames) { @@ -1132,7 +1167,6 @@ void CarlaEngine::processRack(float* inBuf[2], float* outBuf[2], const uint32_t bool processed = false; -#if 0 // process plugins for (unsigned short i=0, max=maxPluginNumber(); i < max; i++) { @@ -1223,7 +1257,6 @@ void CarlaEngine::processRack(float* inBuf[2], float* outBuf[2], const uint32_t processed = true; } -#endif // if no plugins in the rack, copy inputs over outputs if (! processed) @@ -1243,6 +1276,7 @@ void CarlaEngine::processPatchbay(float** inBuf, float** outBuf, const uint32_t Q_UNUSED(frames); } #endif +#endif void CarlaEngine::bufferSizeChanged(const uint32_t newBufferSize) { @@ -1300,144 +1334,144 @@ void CarlaEngine::osc_send_peaks(CarlaPlugin* const plugin, const unsigned short void CarlaEngine::osc_send_control_add_plugin_start(const int32_t pluginId, const char* const pluginName) { qDebug("CarlaEngine::osc_send_control_add_plugin_start(%i, \"%s\")", pluginId, pluginName); - CARLA_ASSERT(data->oscData); - CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)data->maxPluginNumber); + CARLA_ASSERT(fData->oscData != nullptr); + CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)fData->curPluginCount); CARLA_ASSERT(pluginName); - if (data->oscData && data->oscData->target) + if (fData->oscData != nullptr && fData->oscData->target != nullptr) { - char target_path[strlen(data->oscData->path)+18]; - strcpy(target_path, data->oscData->path); + char target_path[strlen(fData->oscData->path)+18]; + strcpy(target_path, fData->oscData->path); strcat(target_path, "/add_plugin_start"); - lo_send(data->oscData->target, target_path, "is", pluginId, pluginName); + lo_send(fData->oscData->target, target_path, "is", pluginId, pluginName); } } void CarlaEngine::osc_send_control_add_plugin_end(const int32_t pluginId) { qDebug("CarlaEngine::osc_send_control_add_plugin_end(%i)", pluginId); - CARLA_ASSERT(data->oscData); - CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)data->maxPluginNumber); + CARLA_ASSERT(fData->oscData != nullptr); + CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)fData->curPluginCount); - if (data->oscData && data->oscData->target) + if (fData->oscData != nullptr && fData->oscData->target != nullptr) { - char target_path[strlen(data->oscData->path)+16]; - strcpy(target_path, data->oscData->path); + char target_path[strlen(fData->oscData->path)+16]; + strcpy(target_path, fData->oscData->path); strcat(target_path, "/add_plugin_end"); - lo_send(data->oscData->target, target_path, "i", pluginId); + lo_send(fData->oscData->target, target_path, "i", pluginId); } } void CarlaEngine::osc_send_control_remove_plugin(const int32_t pluginId) { qDebug("CarlaEngine::osc_send_control_remove_plugin(%i)", pluginId); - CARLA_ASSERT(data->oscData); - CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)data->maxPluginNumber); + CARLA_ASSERT(fData->oscData != nullptr); + CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)fData->curPluginCount); - if (data->oscData && data->oscData->target) + if (fData->oscData != nullptr && fData->oscData->target != nullptr) { - char target_path[strlen(data->oscData->path)+15]; - strcpy(target_path, data->oscData->path); + char target_path[strlen(fData->oscData->path)+15]; + strcpy(target_path, fData->oscData->path); strcat(target_path, "/remove_plugin"); - lo_send(data->oscData->target, target_path, "i", pluginId); + lo_send(fData->oscData->target, target_path, "i", pluginId); } } void CarlaEngine::osc_send_control_set_plugin_data(const int32_t pluginId, const int32_t type, const int32_t category, const int32_t hints, const char* const realName, const char* const label, const char* const maker, const char* const copyright, const int64_t uniqueId) { qDebug("CarlaEngine::osc_send_control_set_plugin_data(%i, %i, %i, %i, \"%s\", \"%s\", \"%s\", \"%s\", " P_INT64 ")", pluginId, type, category, hints, realName, label, maker, copyright, uniqueId); - CARLA_ASSERT(data->oscData); - CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)data->maxPluginNumber); + CARLA_ASSERT(fData->oscData != nullptr); + CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)fData->curPluginCount); CARLA_ASSERT(type != PLUGIN_NONE); - if (data->oscData && data->oscData->target) + if (fData->oscData != nullptr && fData->oscData->target != nullptr) { - char target_path[strlen(data->oscData->path)+17]; - strcpy(target_path, data->oscData->path); + char target_path[strlen(fData->oscData->path)+17]; + strcpy(target_path, fData->oscData->path); strcat(target_path, "/set_plugin_data"); - lo_send(data->oscData->target, target_path, "iiiissssh", pluginId, type, category, hints, realName, label, maker, copyright, uniqueId); + lo_send(fData->oscData->target, target_path, "iiiissssh", pluginId, type, category, hints, realName, label, maker, copyright, uniqueId); } } void CarlaEngine::osc_send_control_set_plugin_ports(const int32_t pluginId, const int32_t audioIns, const int32_t audioOuts, const int32_t midiIns, const int32_t midiOuts, const int32_t cIns, const int32_t cOuts, const int32_t cTotals) { qDebug("CarlaEngine::osc_send_control_set_plugin_ports(%i, %i, %i, %i, %i, %i, %i, %i)", pluginId, audioIns, audioOuts, midiIns, midiOuts, cIns, cOuts, cTotals); - CARLA_ASSERT(data->oscData); - CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)data->maxPluginNumber); + CARLA_ASSERT(fData->oscData != nullptr); + CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)fData->curPluginCount); - if (data->oscData && data->oscData->target) + if (fData->oscData != nullptr && fData->oscData->target != nullptr) { - char target_path[strlen(data->oscData->path)+18]; - strcpy(target_path, data->oscData->path); + char target_path[strlen(fData->oscData->path)+18]; + strcpy(target_path, fData->oscData->path); strcat(target_path, "/set_plugin_ports"); - lo_send(data->oscData->target, target_path, "iiiiiiii", pluginId, audioIns, audioOuts, midiIns, midiOuts, cIns, cOuts, cTotals); + lo_send(fData->oscData->target, target_path, "iiiiiiii", pluginId, audioIns, audioOuts, midiIns, midiOuts, cIns, cOuts, cTotals); } } void CarlaEngine::osc_send_control_set_parameter_data(const int32_t pluginId, const int32_t index, const int32_t type, const int32_t hints, const char* const name, const char* const label, const double current) { qDebug("CarlaEngine::osc_send_control_set_parameter_data(%i, %i, %i, %i, \"%s\", \"%s\", %g)", pluginId, index, type, hints, name, label, current); - CARLA_ASSERT(data->oscData); - CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)data->maxPluginNumber); + CARLA_ASSERT(fData->oscData != nullptr); + CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)fData->curPluginCount); CARLA_ASSERT(index >= 0); CARLA_ASSERT(type != PARAMETER_UNKNOWN); - if (data->oscData && data->oscData->target) + if (fData->oscData != nullptr && fData->oscData->target != nullptr) { - char target_path[strlen(data->oscData->path)+20]; - strcpy(target_path, data->oscData->path); + char target_path[strlen(fData->oscData->path)+20]; + strcpy(target_path, fData->oscData->path); strcat(target_path, "/set_parameter_data"); - lo_send(data->oscData->target, target_path, "iiiissd", pluginId, index, type, hints, name, label, current); + lo_send(fData->oscData->target, target_path, "iiiissd", pluginId, index, type, hints, name, label, current); } } void CarlaEngine::osc_send_control_set_parameter_ranges(const int32_t pluginId, const int32_t index, const double min, const double max, const double def, const double step, const double stepSmall, const double stepLarge) { qDebug("CarlaEngine::osc_send_control_set_parameter_ranges(%i, %i, %g, %g, %g, %g, %g, %g)", pluginId, index, min, max, def, step, stepSmall, stepLarge); - CARLA_ASSERT(data->oscData); - CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)data->maxPluginNumber); + CARLA_ASSERT(fData->oscData != nullptr); + CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)fData->curPluginCount); CARLA_ASSERT(index >= 0); CARLA_ASSERT(min < max); - if (data->oscData && data->oscData->target) + if (fData->oscData != nullptr && fData->oscData->target != nullptr) { - char target_path[strlen(data->oscData->path)+22]; - strcpy(target_path, data->oscData->path); + char target_path[strlen(fData->oscData->path)+22]; + strcpy(target_path, fData->oscData->path); strcat(target_path, "/set_parameter_ranges"); - lo_send(data->oscData->target, target_path, "iidddddd", pluginId, index, min, max, def, step, stepSmall, stepLarge); + lo_send(fData->oscData->target, target_path, "iidddddd", pluginId, index, min, max, def, step, stepSmall, stepLarge); } } void CarlaEngine::osc_send_control_set_parameter_midi_cc(const int32_t pluginId, const int32_t index, const int32_t cc) { qDebug("CarlaEngine::osc_send_control_set_parameter_midi_cc(%i, %i, %i)", pluginId, index, cc); - CARLA_ASSERT(data->oscData); - CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)data->maxPluginNumber); + CARLA_ASSERT(fData->oscData != nullptr); + CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)fData->curPluginCount); CARLA_ASSERT(index >= 0); - if (data->oscData && data->oscData->target) + if (fData->oscData != nullptr && fData->oscData->target != nullptr) { - char target_path[strlen(data->oscData->path)+23]; - strcpy(target_path, data->oscData->path); + char target_path[strlen(fData->oscData->path)+23]; + strcpy(target_path, fData->oscData->path); strcat(target_path, "/set_parameter_midi_cc"); - lo_send(data->oscData->target, target_path, "iii", pluginId, index, cc); + lo_send(fData->oscData->target, target_path, "iii", pluginId, index, cc); } } void CarlaEngine::osc_send_control_set_parameter_midi_channel(const int32_t pluginId, const int32_t index, const int32_t channel) { qDebug("CarlaEngine::osc_send_control_set_parameter_midi_channel(%i, %i, %i)", pluginId, index, channel); - CARLA_ASSERT(data->oscData); - CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)data->maxPluginNumber); + CARLA_ASSERT(fData->oscData != nullptr); + CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)fData->curPluginCount); CARLA_ASSERT(index >= 0); CARLA_ASSERT(channel >= 0 && channel < 16); - if (data->oscData && data->oscData->target) + if (fData->oscData != nullptr && fData->oscData->target != nullptr) { - char target_path[strlen(data->oscData->path)+28]; - strcpy(target_path, data->oscData->path); + char target_path[strlen(fData->oscData->path)+28]; + strcpy(target_path, fData->oscData->path); strcat(target_path, "/set_parameter_midi_channel"); - lo_send(data->oscData->target, target_path, "iii", pluginId, index, channel); + lo_send(fData->oscData->target, target_path, "iii", pluginId, index, channel); } } @@ -1449,164 +1483,164 @@ void CarlaEngine::osc_send_control_set_parameter_value(const int32_t pluginId, c else qDebug("CarlaEngine::osc_send_control_set_parameter_value(%i, %i, %g)", pluginId, index, value); #endif - CARLA_ASSERT(data->oscData); - CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)data->maxPluginNumber); + CARLA_ASSERT(fData->oscData != nullptr); + CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)fData->curPluginCount); - if (data->oscData && data->oscData->target) + if (fData->oscData != nullptr && fData->oscData->target != nullptr) { - char target_path[strlen(data->oscData->path)+21]; - strcpy(target_path, data->oscData->path); + char target_path[strlen(fData->oscData->path)+21]; + strcpy(target_path, fData->oscData->path); strcat(target_path, "/set_parameter_value"); - lo_send(data->oscData->target, target_path, "iid", pluginId, index, value); + lo_send(fData->oscData->target, target_path, "iid", pluginId, index, value); } } void CarlaEngine::osc_send_control_set_default_value(const int32_t pluginId, const int32_t index, const double value) { qDebug("CarlaEngine::osc_send_control_set_default_value(%i, %i, %g)", pluginId, index, value); - CARLA_ASSERT(data->oscData); - CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)data->maxPluginNumber); + CARLA_ASSERT(fData->oscData != nullptr); + CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)fData->maxPluginNumber); CARLA_ASSERT(index >= 0); - if (data->oscData && data->oscData->target) + if (fData->oscData != nullptr && fData->oscData->target != nullptr) { - char target_path[strlen(data->oscData->path)+19]; - strcpy(target_path, data->oscData->path); + char target_path[strlen(fData->oscData->path)+19]; + strcpy(target_path, fData->oscData->path); strcat(target_path, "/set_default_value"); - lo_send(data->oscData->target, target_path, "iid", pluginId, index, value); + lo_send(fData->oscData->target, target_path, "iid", pluginId, index, value); } } void CarlaEngine::osc_send_control_set_program(const int32_t pluginId, const int32_t index) { qDebug("CarlaEngine::osc_send_control_set_program(%i, %i)", pluginId, index); - CARLA_ASSERT(data->oscData); - CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)data->maxPluginNumber); + CARLA_ASSERT(fData->oscData != nullptr); + CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)fData->maxPluginNumber); - if (data->oscData && data->oscData->target) + if (fData->oscData != nullptr && fData->oscData->target != nullptr) { - char target_path[strlen(data->oscData->path)+13]; - strcpy(target_path, data->oscData->path); + char target_path[strlen(fData->oscData->path)+13]; + strcpy(target_path, fData->oscData->path); strcat(target_path, "/set_program"); - lo_send(data->oscData->target, target_path, "ii", pluginId, index); + lo_send(fData->oscData->target, target_path, "ii", pluginId, index); } } void CarlaEngine::osc_send_control_set_program_count(const int32_t pluginId, const int32_t count) { qDebug("CarlaEngine::osc_send_control_set_program_count(%i, %i)", pluginId, count); - CARLA_ASSERT(data->oscData); - CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)data->maxPluginNumber); + CARLA_ASSERT(fData->oscData != nullptr); + CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)fData->maxPluginNumber); CARLA_ASSERT(count >= 0); - if (data->oscData && data->oscData->target) + if (fData->oscData != nullptr && fData->oscData->target != nullptr) { - char target_path[strlen(data->oscData->path)+19]; - strcpy(target_path, data->oscData->path); + char target_path[strlen(fData->oscData->path)+19]; + strcpy(target_path, fData->oscData->path); strcat(target_path, "/set_program_count"); - lo_send(data->oscData->target, target_path, "ii", pluginId, count); + lo_send(fData->oscData->target, target_path, "ii", pluginId, count); } } void CarlaEngine::osc_send_control_set_program_name(const int32_t pluginId, const int32_t index, const char* const name) { qDebug("CarlaEngine::osc_send_control_set_program_name(%i, %i, \"%s\")", pluginId, index, name); - CARLA_ASSERT(data->oscData); - CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)data->maxPluginNumber); + CARLA_ASSERT(fData->oscData != nullptr); + CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)fData->maxPluginNumber); CARLA_ASSERT(index >= 0); CARLA_ASSERT(name); - if (data->oscData && data->oscData->target) + if (fData->oscData != nullptr && fData->oscData->target != nullptr) { - char target_path[strlen(data->oscData->path)+18]; - strcpy(target_path, data->oscData->path); + char target_path[strlen(fData->oscData->path)+18]; + strcpy(target_path, fData->oscData->path); strcat(target_path, "/set_program_name"); - lo_send(data->oscData->target, target_path, "iis", pluginId, index, name); + lo_send(fData->oscData->target, target_path, "iis", pluginId, index, name); } } void CarlaEngine::osc_send_control_set_midi_program(const int32_t pluginId, const int32_t index) { qDebug("CarlaEngine::osc_send_control_set_midi_program(%i, %i)", pluginId, index); - CARLA_ASSERT(data->oscData); - CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)data->maxPluginNumber); + CARLA_ASSERT(fData->oscData != nullptr); + CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)fData->maxPluginNumber); - if (data->oscData && data->oscData->target) + if (fData->oscData != nullptr && fData->oscData->target != nullptr) { - char target_path[strlen(data->oscData->path)+18]; - strcpy(target_path, data->oscData->path); + char target_path[strlen(fData->oscData->path)+18]; + strcpy(target_path, fData->oscData->path); strcat(target_path, "/set_midi_program"); - lo_send(data->oscData->target, target_path, "ii", pluginId, index); + lo_send(fData->oscData->target, target_path, "ii", pluginId, index); } } void CarlaEngine::osc_send_control_set_midi_program_count(const int32_t pluginId, const int32_t count) { qDebug("CarlaEngine::osc_send_control_set_midi_program_count(%i, %i)", pluginId, count); - CARLA_ASSERT(data->oscData); - CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)data->maxPluginNumber); + CARLA_ASSERT(fData->oscData != nullptr); + CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)fData->maxPluginNumber); CARLA_ASSERT(count >= 0); - if (data->oscData && data->oscData->target) + if (fData->oscData != nullptr && fData->oscData->target != nullptr) { - char target_path[strlen(data->oscData->path)+24]; - strcpy(target_path, data->oscData->path); + char target_path[strlen(fData->oscData->path)+24]; + strcpy(target_path, fData->oscData->path); strcat(target_path, "/set_midi_program_count"); - lo_send(data->oscData->target, target_path, "ii", pluginId, count); + lo_send(fData->oscData->target, target_path, "ii", pluginId, count); } } void CarlaEngine::osc_send_control_set_midi_program_data(const int32_t pluginId, const int32_t index, const int32_t bank, const int32_t program, const char* const name) { qDebug("CarlaEngine::osc_send_control_set_midi_program_data(%i, %i, %i, %i, \"%s\")", pluginId, index, bank, program, name); - CARLA_ASSERT(data->oscData); - CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)data->maxPluginNumber); + CARLA_ASSERT(fData->oscData != nullptr); + CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)fData->maxPluginNumber); CARLA_ASSERT(index >= 0); CARLA_ASSERT(bank >= 0); CARLA_ASSERT(program >= 0); CARLA_ASSERT(name); - if (data->oscData && data->oscData->target) + if (fData->oscData != nullptr && fData->oscData->target != nullptr) { - char target_path[strlen(data->oscData->path)+23]; - strcpy(target_path, data->oscData->path); + char target_path[strlen(fData->oscData->path)+23]; + strcpy(target_path, fData->oscData->path); strcat(target_path, "/set_midi_program_data"); - lo_send(data->oscData->target, target_path, "iiiis", pluginId, index, bank, program, name); + lo_send(fData->oscData->target, target_path, "iiiis", pluginId, index, bank, program, name); } } void CarlaEngine::osc_send_control_note_on(const int32_t pluginId, const int32_t channel, const int32_t note, const int32_t velo) { qDebug("CarlaEngine::osc_send_control_note_on(%i, %i, %i, %i)", pluginId, channel, note, velo); - CARLA_ASSERT(data->oscData); - CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)data->maxPluginNumber); + CARLA_ASSERT(fData->oscData != nullptr); + CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)fData->maxPluginNumber); CARLA_ASSERT(channel >= 0 && channel < 16); CARLA_ASSERT(note >= 0 && note < 128); CARLA_ASSERT(velo > 0 && velo < 128); - if (data->oscData && data->oscData->target) + if (fData->oscData != nullptr && fData->oscData->target != nullptr) { - char target_path[strlen(data->oscData->path)+9]; - strcpy(target_path, data->oscData->path); + char target_path[strlen(fData->oscData->path)+9]; + strcpy(target_path, fData->oscData->path); strcat(target_path, "/note_on"); - lo_send(data->oscData->target, target_path, "iiii", pluginId, channel, note, velo); + lo_send(fData->oscData->target, target_path, "iiii", pluginId, channel, note, velo); } } void CarlaEngine::osc_send_control_note_off(const int32_t pluginId, const int32_t channel, const int32_t note) { qDebug("CarlaEngine::osc_send_control_note_off(%i, %i, %i)", pluginId, channel, note); - CARLA_ASSERT(data->oscData); - CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)data->maxPluginNumber); + CARLA_ASSERT(fData->oscData != nullptr); + CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)fData->maxPluginNumber); CARLA_ASSERT(channel >= 0 && channel < 16); CARLA_ASSERT(note >= 0 && note < 128); - if (data->oscData && data->oscData->target) + if (fData->oscData != nullptr && fData->oscData->target != nullptr) { - char target_path[strlen(data->oscData->path)+10]; - strcpy(target_path, data->oscData->path); + char target_path[strlen(fData->oscData->path)+10]; + strcpy(target_path, fData->oscData->path); strcat(target_path, "/note_off"); - lo_send(data->oscData->target, target_path, "iii", pluginId, channel, note); + lo_send(fData->oscData->target, target_path, "iii", pluginId, channel, note); } } @@ -1614,32 +1648,32 @@ void CarlaEngine::osc_send_control_note_off(const int32_t pluginId, const int32_ void CarlaEngine::osc_send_control_set_input_peak_value(const int32_t pluginId, const int32_t portId) { //qDebug("CarlaEngine::osc_send_control_set_input_peak_value(%i, %i)", pluginId, portId); - CARLA_ASSERT(data->oscData); - CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)data->maxPluginNumber); + CARLA_ASSERT(fData->oscData != nullptr); + CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)fData->maxPluginNumber); CARLA_ASSERT(portId == 1 || portId == 2); - if (data->oscData && data->oscData->target) + if (fData->oscData != nullptr && fData->oscData->target != nullptr) { - char target_path[strlen(data->oscData->path)+22]; - strcpy(target_path, data->oscData->path); + char target_path[strlen(fData->oscData->path)+22]; + strcpy(target_path, fData->oscData->path); strcat(target_path, "/set_input_peak_value"); - lo_send(data->oscData->target, target_path, "iid", pluginId, portId, data->insPeak[pluginId*MAX_PEAKS + portId-1]); + lo_send(fData->oscData->target, target_path, "iid", pluginId, portId, data->insPeak[pluginId*MAX_PEAKS + portId-1]); } } void CarlaEngine::osc_send_control_set_output_peak_value(const int32_t pluginId, const int32_t portId) { //qDebug("CarlaEngine::osc_send_control_set_output_peak_value(%i, %i)", pluginId, portId); - CARLA_ASSERT(data->oscData); - CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)data->maxPluginNumber); + CARLA_ASSERT(fData->oscData != nullptr); + CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)fData->maxPluginNumber); CARLA_ASSERT(portId == 1 || portId == 2); - if (data->oscData && data->oscData->target) + if (fData->oscData != nullptr && fData->oscData->target != nullptr) { - char target_path[strlen(data->oscData->path)+23]; - strcpy(target_path, data->oscData->path); + char target_path[strlen(fData->oscData->path)+23]; + strcpy(target_path, fData->oscData->path); strcat(target_path, "/set_output_peak_value"); - lo_send(data->oscData->target, target_path, "iid", pluginId, portId, data->outsPeak[pluginId*MAX_PEAKS + portId-1]); + lo_send(fData->oscData->target, target_path, "iid", pluginId, portId, data->outsPeak[pluginId*MAX_PEAKS + portId-1]); } } #endif @@ -1647,251 +1681,251 @@ void CarlaEngine::osc_send_control_set_output_peak_value(const int32_t pluginId, void CarlaEngine::osc_send_control_exit() { qDebug("CarlaEngine::osc_send_control_exit()"); - CARLA_ASSERT(data->oscData); + CARLA_ASSERT(fData->oscData); - if (data->oscData && data->oscData->target) + if (fData->oscData && fData->oscData->target) { - char target_path[strlen(data->oscData->path)+6]; - strcpy(target_path, data->oscData->path); + char target_path[strlen(fData->oscData->path)+6]; + strcpy(target_path, fData->oscData->path); strcat(target_path, "/exit"); - lo_send(data->oscData->target, target_path, ""); + lo_send(fData->oscData->target, target_path, ""); } } #else void CarlaEngine::osc_send_bridge_audio_count(const int32_t ins, const int32_t outs, const int32_t total) { qDebug("CarlaEngine::osc_send_bridge_audio_count(%i, %i, %i)", ins, outs, total); - CARLA_ASSERT(data->oscData); + CARLA_ASSERT(fData->oscData != nullptr); CARLA_ASSERT(total >= 0 && total >= ins + outs); - if (data->oscData && data->oscData->target) + if (fData->oscData != nullptr && fData->oscData->target != nullptr) { - char target_path[strlen(data->oscData->path)+20]; - strcpy(target_path, data->oscData->path); + char target_path[strlen(fData->oscData->path)+20]; + strcpy(target_path, fData->oscData->path); strcat(target_path, "/bridge_audio_count"); - lo_send(data->oscData->target, target_path, "iii", ins, outs, total); + lo_send(fData->oscData->target, target_path, "iii", ins, outs, total); } } void CarlaEngine::osc_send_bridge_midi_count(const int32_t ins, const int32_t outs, const int32_t total) { qDebug("CarlaEngine::osc_send_bridge_midi_count(%i, %i, %i)", ins, outs, total); - CARLA_ASSERT(data->oscData); + CARLA_ASSERT(fData->oscData != nullptr); CARLA_ASSERT(total >= 0 && total >= ins + outs); - if (data->oscData && data->oscData->target) + if (fData->oscData != nullptr && fData->oscData->target != nullptr) { - char target_path[strlen(data->oscData->path)+19]; - strcpy(target_path, data->oscData->path); + char target_path[strlen(fData->oscData->path)+19]; + strcpy(target_path, fData->oscData->path); strcat(target_path, "/bridge_midi_count"); - lo_send(data->oscData->target, target_path, "iii", ins, outs, total); + lo_send(fData->oscData->target, target_path, "iii", ins, outs, total); } } void CarlaEngine::osc_send_bridge_parameter_count(const int32_t ins, const int32_t outs, const int32_t total) { qDebug("CarlaEngine::osc_send_bridge_parameter_count(%i, %i, %i)", ins, outs, total); - CARLA_ASSERT(data->oscData); + CARLA_ASSERT(fData->oscData != nullptr); CARLA_ASSERT(total >= 0 && total >= ins + outs); - if (data->oscData && data->oscData->target) + if (fData->oscData != nullptr && fData->oscData->target != nullptr) { - char target_path[strlen(data->oscData->path)+24]; - strcpy(target_path, data->oscData->path); + char target_path[strlen(fData->oscData->path)+24]; + strcpy(target_path, fData->oscData->path); strcat(target_path, "/bridge_parameter_count"); - lo_send(data->oscData->target, target_path, "iii", ins, outs, total); + lo_send(fData->oscData->target, target_path, "iii", ins, outs, total); } } void CarlaEngine::osc_send_bridge_program_count(const int32_t count) { qDebug("CarlaEngine::osc_send_bridge_program_count(%i)", count); - CARLA_ASSERT(data->oscData); + CARLA_ASSERT(fData->oscData != nullptr); CARLA_ASSERT(count >= 0); - if (data->oscData && data->oscData->target) + if (fData->oscData != nullptr && fData->oscData->target != nullptr) { - char target_path[strlen(data->oscData->path)+22]; - strcpy(target_path, data->oscData->path); + char target_path[strlen(fData->oscData->path)+22]; + strcpy(target_path, fData->oscData->path); strcat(target_path, "/bridge_program_count"); - lo_send(data->oscData->target, target_path, "i", count); + lo_send(fData->oscData->target, target_path, "i", count); } } void CarlaEngine::osc_send_bridge_midi_program_count(const int32_t count) { qDebug("CarlaEngine::osc_send_bridge_midi_program_count(%i)", count); - CARLA_ASSERT(data->oscData); + CARLA_ASSERT(fData->oscData != nullptr); CARLA_ASSERT(count >= 0); - if (data->oscData && data->oscData->target) + if (fData->oscData != nullptr && fData->oscData->target != nullptr) { - char target_path[strlen(data->oscData->path)+27]; - strcpy(target_path, data->oscData->path); + char target_path[strlen(fData->oscData->path)+27]; + strcpy(target_path, fData->oscData->path); strcat(target_path, "/bridge_midi_program_count"); - lo_send(data->oscData->target, target_path, "i", count); + lo_send(fData->oscData->target, target_path, "i", count); } } void CarlaEngine::osc_send_bridge_plugin_info(const int32_t category, const int32_t hints, const char* const name, const char* const label, const char* const maker, const char* const copyright, const int64_t uniqueId) { qDebug("CarlaEngine::osc_send_bridge_plugin_info(%i, %i, \"%s\", \"%s\", \"%s\", \"%s\", " P_INT64 ")", category, hints, name, label, maker, copyright, uniqueId); - CARLA_ASSERT(data->oscData); + CARLA_ASSERT(fData->oscData != nullptr); CARLA_ASSERT(name); CARLA_ASSERT(label); CARLA_ASSERT(maker); CARLA_ASSERT(copyright); - if (data->oscData && data->oscData->target) + if (fData->oscData != nullptr && fData->oscData->target != nullptr) { - char target_path[strlen(data->oscData->path)+20]; - strcpy(target_path, data->oscData->path); + char target_path[strlen(fData->oscData->path)+20]; + strcpy(target_path, fData->oscData->path); strcat(target_path, "/bridge_plugin_info"); - lo_send(data->oscData->target, target_path, "iissssh", category, hints, name, label, maker, copyright, uniqueId); + lo_send(fData->oscData->target, target_path, "iissssh", category, hints, name, label, maker, copyright, uniqueId); } } void CarlaEngine::osc_send_bridge_parameter_info(const int32_t index, const char* const name, const char* const unit) { qDebug("CarlaEngine::osc_send_bridge_parameter_info(%i, \"%s\", \"%s\")", index, name, unit); - CARLA_ASSERT(data->oscData); + CARLA_ASSERT(fData->oscData != nullptr); CARLA_ASSERT(name); CARLA_ASSERT(unit); - if (data->oscData && data->oscData->target) + if (fData->oscData != nullptr && fData->oscData->target != nullptr) { - char target_path[strlen(data->oscData->path)+23]; - strcpy(target_path, data->oscData->path); + char target_path[strlen(fData->oscData->path)+23]; + strcpy(target_path, fData->oscData->path); strcat(target_path, "/bridge_parameter_info"); - lo_send(data->oscData->target, target_path, "iss", index, name, unit); + lo_send(fData->oscData->target, target_path, "iss", index, name, unit); } } void CarlaEngine::osc_send_bridge_parameter_data(const int32_t index, const int32_t type, const int32_t rindex, const int32_t hints, const int32_t midiChannel, const int32_t midiCC) { qDebug("CarlaEngine::osc_send_bridge_parameter_data(%i, %i, %i, %i, %i, %i)", index, type, rindex, hints, midiChannel, midiCC); - CARLA_ASSERT(data->oscData); + CARLA_ASSERT(fData->oscData != nullptr); - if (data->oscData && data->oscData->target) + if (fData->oscData != nullptr && fData->oscData->target != nullptr) { - char target_path[strlen(data->oscData->path)+23]; - strcpy(target_path, data->oscData->path); + char target_path[strlen(fData->oscData->path)+23]; + strcpy(target_path, fData->oscData->path); strcat(target_path, "/bridge_parameter_data"); - lo_send(data->oscData->target, target_path, "iiiiii", index, type, rindex, hints, midiChannel, midiCC); + lo_send(fData->oscData->target, target_path, "iiiiii", index, type, rindex, hints, midiChannel, midiCC); } } void CarlaEngine::osc_send_bridge_parameter_ranges(const int32_t index, const double def, const double min, const double max, const double step, const double stepSmall, const double stepLarge) { qDebug("CarlaEngine::osc_send_bridge_parameter_ranges(%i, %g, %g, %g, %g, %g, %g)", index, def, min, max, step, stepSmall, stepLarge); - CARLA_ASSERT(data->oscData); + CARLA_ASSERT(fData->oscData != nullptr); - if (data->oscData && data->oscData->target) + if (fData->oscData != nullptr && fData->oscData->target != nullptr) { - char target_path[strlen(data->oscData->path)+25]; - strcpy(target_path, data->oscData->path); + char target_path[strlen(fData->oscData->path)+25]; + strcpy(target_path, fData->oscData->path); strcat(target_path, "/bridge_parameter_ranges"); - lo_send(data->oscData->target, target_path, "idddddd", index, def, min, max, step, stepSmall, stepLarge); + lo_send(fData->oscData->target, target_path, "idddddd", index, def, min, max, step, stepSmall, stepLarge); } } void CarlaEngine::osc_send_bridge_program_info(const int32_t index, const char* const name) { qDebug("CarlaEngine::osc_send_bridge_program_info(%i, \"%s\")", index, name); - CARLA_ASSERT(data->oscData); + CARLA_ASSERT(fData->oscData != nullptr); - if (data->oscData && data->oscData->target) + if (fData->oscData != nullptr && fData->oscData->target != nullptr) { - char target_path[strlen(data->oscData->path)+21]; - strcpy(target_path, data->oscData->path); + char target_path[strlen(fData->oscData->path)+21]; + strcpy(target_path, fData->oscData->path); strcat(target_path, "/bridge_program_info"); - lo_send(data->oscData->target, target_path, "is", index, name); + lo_send(fData->oscData->target, target_path, "is", index, name); } } void CarlaEngine::osc_send_bridge_midi_program_info(const int32_t index, const int32_t bank, const int32_t program, const char* const label) { qDebug("CarlaEngine::osc_send_bridge_midi_program_info(%i, %i, %i, \"%s\")", index, bank, program, label); - CARLA_ASSERT(data->oscData); + CARLA_ASSERT(fData->oscData != nullptr); - if (data->oscData && data->oscData->target) + if (fData->oscData != nullptr && fData->oscData->target != nullptr) { - char target_path[strlen(data->oscData->path)+26]; - strcpy(target_path, data->oscData->path); + char target_path[strlen(fData->oscData->path)+26]; + strcpy(target_path, fData->oscData->path); strcat(target_path, "/bridge_midi_program_info"); - lo_send(data->oscData->target, target_path, "iiis", index, bank, program, label); + lo_send(fData->oscData->target, target_path, "iiis", index, bank, program, label); } } void CarlaEngine::osc_send_bridge_configure(const char* const key, const char* const value) { qDebug("CarlaEngine::osc_send_bridge_configure(\"%s\", \"%s\")", key, value); - CARLA_ASSERT(data->oscData); + CARLA_ASSERT(fData->oscData != nullptr); CARLA_ASSERT(key); CARLA_ASSERT(value); - if (data->oscData && data->oscData->target) + if (fData->oscData != nullptr && fData->oscData->target != nullptr) { - char target_path[strlen(data->oscData->path)+18]; - strcpy(target_path, data->oscData->path); + char target_path[strlen(fData->oscData->path)+18]; + strcpy(target_path, fData->oscData->path); strcat(target_path, "/bridge_configure"); - lo_send(data->oscData->target, target_path, "ss", key, value); + lo_send(fData->oscData->target, target_path, "ss", key, value); } } void CarlaEngine::osc_send_bridge_set_parameter_value(const int32_t index, const double value) { qDebug("CarlaEngine::osc_send_bridge_set_parameter_value(%i, %g)", index, value); - CARLA_ASSERT(data->oscData); + CARLA_ASSERT(fData->oscData != nullptr); - if (data->oscData && data->oscData->target) + if (fData->oscData != nullptr && fData->oscData->target != nullptr) { - char target_path[strlen(data->oscData->path)+28]; - strcpy(target_path, data->oscData->path); + char target_path[strlen(fData->oscData->path)+28]; + strcpy(target_path, fData->oscData->path); strcat(target_path, "/bridge_set_parameter_value"); - lo_send(data->oscData->target, target_path, "id", index, value); + lo_send(fData->oscData->target, target_path, "id", index, value); } } void CarlaEngine::osc_send_bridge_set_default_value(const int32_t index, const double value) { qDebug("CarlaEngine::osc_send_bridge_set_default_value(%i, %g)", index, value); - CARLA_ASSERT(data->oscData); + CARLA_ASSERT(fData->oscData != nullptr); - if (data->oscData && data->oscData->target) + if (fData->oscData != nullptr && fData->oscData->target != nullptr) { - char target_path[strlen(data->oscData->path)+26]; - strcpy(target_path, data->oscData->path); + char target_path[strlen(fData->oscData->path)+26]; + strcpy(target_path, fData->oscData->path); strcat(target_path, "/bridge_set_default_value"); - lo_send(data->oscData->target, target_path, "id", index, value); + lo_send(fData->oscData->target, target_path, "id", index, value); } } void CarlaEngine::osc_send_bridge_set_program(const int32_t index) { qDebug("CarlaEngine::osc_send_bridge_set_program(%i)", index); - CARLA_ASSERT(data->oscData); + CARLA_ASSERT(fData->oscData != nullptr); - if (data->oscData && data->oscData->target) + if (fData->oscData != nullptr && fData->oscData->target != nullptr) { - char target_path[strlen(data->oscData->path)+20]; - strcpy(target_path, data->oscData->path); + char target_path[strlen(fData->oscData->path)+20]; + strcpy(target_path, fData->oscData->path); strcat(target_path, "/bridge_set_program"); - lo_send(data->oscData->target, target_path, "i", index); + lo_send(fData->oscData->target, target_path, "i", index); } } void CarlaEngine::osc_send_bridge_set_midi_program(const int32_t index) { qDebug("CarlaEngine::osc_send_bridge_set_midi_program(%i)", index); - CARLA_ASSERT(data->oscData); + CARLA_ASSERT(fData->oscData != nullptr); - if (data->oscData && data->oscData->target) + if (fData->oscData != nullptr && fData->oscData->target != nullptr) { - char target_path[strlen(data->oscData->path)+25]; - strcpy(target_path, data->oscData->path); + char target_path[strlen(fData->oscData->path)+25]; + strcpy(target_path, fData->oscData->path); strcat(target_path, "/bridge_set_midi_program"); - lo_send(data->oscData->target, target_path, "i", index); + lo_send(fData->oscData->target, target_path, "i", index); } } @@ -1900,10 +1934,10 @@ void CarlaEngine::osc_send_bridge_set_custom_data(const char* const type, const qDebug("CarlaEngine::osc_send_bridge_set_custom_data(\"%s\", \"%s\", \"%s\")", type, key, value); CARLA_ASSERT(m_oscData); - if (data->oscData && data->oscData->target) + if (fData->oscData != nullptr && fData->oscData->target != nullptr) { - char target_path[strlen(data->oscData->path)+24]; - strcpy(target_path, data->oscData->path); + char target_path[strlen(fData->oscData->path)+24]; + strcpy(target_path, fData->oscData->path); strcat(target_path, "/bridge_set_custom_data"); lo_send(m_oscData->target, target_path, "sss", type, key, value); } @@ -1912,26 +1946,26 @@ void CarlaEngine::osc_send_bridge_set_custom_data(const char* const type, const void CarlaEngine::osc_send_bridge_set_chunk_data(const char* const chunkFile) { qDebug("CarlaEngine::osc_send_bridge_set_chunk_data(\"%s\")", chunkFile); - CARLA_ASSERT(data->oscData); + CARLA_ASSERT(fData->oscData != nullptr); - if (data->oscData && data->oscData->target) + if (fData->oscData != nullptr && fData->oscData->target != nullptr) { - char target_path[strlen(data->oscData->path)+23]; - strcpy(target_path, data->oscData->path); + char target_path[strlen(fData->oscData->path)+23]; + strcpy(target_path, fData->oscData->path); strcat(target_path, "/bridge_set_chunk_data"); - lo_send(data->oscData->target, target_path, "s", chunkFile); + lo_send(fData->oscData->target, target_path, "s", chunkFile); } } void CarlaEngine::osc_send_bridge_set_inpeak(const int32_t portId) { - CARLA_ASSERT(data->oscData); + CARLA_ASSERT(fData->oscData != nullptr); CARLA_ASSERT(portId == 1 || portId == 2); - if (data->oscData && data->oscData->target) + if (fData->oscData != nullptr && fData->oscData->target != nullptr) { - char target_path[strlen(data->oscData->path)+28]; - strcpy(target_path, data->oscData->path); + char target_path[strlen(fData->oscData->path)+28]; + strcpy(target_path, fData->oscData->path); strcat(target_path, "/bridge_set_inpeak"); lo_send(m_oscData->target, target_path, "id", portId, data->insPeak[portId-1]); } @@ -1939,15 +1973,15 @@ void CarlaEngine::osc_send_bridge_set_inpeak(const int32_t portId) void CarlaEngine::osc_send_bridge_set_outpeak(const int32_t portId) { - CARLA_ASSERT(data->oscData); + CARLA_ASSERT(fData->oscData != nullptr); CARLA_ASSERT(portId == 1 || portId == 2); - if (data->oscData && data->oscData->target) + if (fData->oscData != nullptr && fData->oscData->target != nullptr) { - char target_path[strlen(data->oscData->path)+29]; - strcpy(target_path, data->oscData->path); + char target_path[strlen(fData->oscData->path)+29]; + strcpy(target_path, fData->oscData->path); strcat(target_path, "/bridge_set_outpeak"); - lo_send(data->oscData->target, target_path, "id", portId, data->insPeak[portId-1]); + lo_send(fData->oscData->target, target_path, "id", portId, data->insPeak[portId-1]); } } #endif diff --git a/source/backend/engine/carla_engine.pro b/source/backend/engine/carla_engine.pro index 1d79fa779..d2ae96fcf 100644 --- a/source/backend/engine/carla_engine.pro +++ b/source/backend/engine/carla_engine.pro @@ -56,7 +56,8 @@ HEADERS += \ ../../includes/carla_midi.h \ ../../utils/carla_utils.hpp \ ../../utils/carla_backend_utils.hpp \ - ../../utils/carla_juce_utils.hpp + ../../utils/carla_juce_utils.hpp \ + ../../utils/carla_osc_utils.hpp HEADERS += \ plugin/DistrhoPluginInfo.h diff --git a/source/backend/engine/carla_engine_internal.hpp b/source/backend/engine/carla_engine_internal.hpp index c4a43c7a2..cac1423a5 100644 --- a/source/backend/engine/carla_engine_internal.hpp +++ b/source/backend/engine/carla_engine_internal.hpp @@ -2,17 +2,17 @@ * Carla Engine * Copyright (C) 2012-2013 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 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 COPYING file + * For a full copy of the GNU General Public License see the GPL.txt file */ #ifndef __CARLA_ENGINE_INTERNAL_HPP__ @@ -39,14 +39,14 @@ const char* EngineType2Str(const EngineType type) { switch (type) { - case EngineTypeNull: - return "EngineTypeNull"; - case EngineTypeJack: - return "EngineTypeJack"; - case EngineTypeRtAudio: - return "EngineTypeRtAudio"; - case EngineTypePlugin: - return "EngineTypePlugin"; + case kEngineTypeNull: + return "kEngineTypeNull"; + case kEngineTypeJack: + return "kEngineTypeJack"; + case kEngineTypeRtAudio: + return "kEngineTypeRtAudio"; + case kEngineTypePlugin: + return "kEngineTypePlugin"; } qWarning("CarlaBackend::EngineType2Str(%i) - invalid type", type); @@ -58,12 +58,12 @@ const char* EnginePortType2Str(const EnginePortType type) { switch (type) { - case EnginePortTypeNull: - return "EnginePortTypeNull"; - case EnginePortTypeAudio: - return "EnginePortTypeAudio"; - case EnginePortTypeEvent: - return "EnginePortTypeEvent"; + case kEnginePortTypeNull: + return "kEnginePortTypeNull"; + case kEnginePortTypeAudio: + return "kEnginePortTypeAudio"; + case kEnginePortTypeEvent: + return "kEnginePortTypeEvent"; } qWarning("CarlaBackend::EnginePortType2Str(%i) - invalid type", type); @@ -75,18 +75,18 @@ const char* EngineControlEventType2Str(const EngineControlEventType type) { switch (type) { - case EngineControlEventTypeNull: - return "EngineNullEvent"; - case EngineControlEventTypeParameter: - return "EngineControlEventTypeParameter"; - case EngineControlEventTypeMidiBank: - return "EngineControlEventTypeMidiBank"; - case EngineControlEventTypeMidiProgram: - return "EngineControlEventTypeMidiProgram"; - case EngineControlEventTypeAllSoundOff: - return "EngineControlEventTypeAllSoundOff"; - case EngineControlEventTypeAllNotesOff: - return "EngineControlEventTypeAllNotesOff"; + case kEngineControlEventTypeNull: + return "kEngineNullEvent"; + case kEngineControlEventTypeParameter: + return "kEngineControlEventTypeParameter"; + case kEngineControlEventTypeMidiBank: + return "kEngineControlEventTypeMidiBank"; + case kEngineControlEventTypeMidiProgram: + return "kEngineControlEventTypeMidiProgram"; + case kEngineControlEventTypeAllSoundOff: + return "kEngineControlEventTypeAllSoundOff"; + case kEngineControlEventTypeAllNotesOff: + return "kEngineControlEventTypeAllNotesOff"; } qWarning("CarlaBackend::EngineControlEventType2Str(%i) - invalid type", type); @@ -103,6 +103,7 @@ const char* EngineControlEventType2Str(const EngineControlEventType type) const uint32_t PATCHBAY_BUFFER_SIZE = 128; const unsigned short PATCHBAY_EVENT_COUNT = 512; +const unsigned short RACK_EVENT_COUNT = 1024; #if 0 enum EnginePostEventType { diff --git a/source/backend/engine/carla_engine_osc.hpp b/source/backend/engine/carla_engine_osc.hpp index 415efc121..2263535f5 100644 --- a/source/backend/engine/carla_engine_osc.hpp +++ b/source/backend/engine/carla_engine_osc.hpp @@ -2,17 +2,17 @@ * Carla Engine OSC * Copyright (C) 2012-2013 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 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 COPYING file + * For a full copy of the GNU General Public License see the GPL.txt file */ #ifndef __CARLA_ENGINE_OSC_HPP__ diff --git a/source/backend/engine/carla_engine_thread.hpp b/source/backend/engine/carla_engine_thread.hpp index 2c3d0ceca..4099293a8 100644 --- a/source/backend/engine/carla_engine_thread.hpp +++ b/source/backend/engine/carla_engine_thread.hpp @@ -2,17 +2,17 @@ * Carla Engine Thread * Copyright (C) 2012-2013 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 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 COPYING file + * For a full copy of the GNU General Public License see the GPL.txt file */ #ifndef __CARLA_ENGINE_THREAD_HPP__ diff --git a/source/backend/engine/jack.cpp b/source/backend/engine/jack.cpp index 919ff584e..0645f2f08 100644 --- a/source/backend/engine/jack.cpp +++ b/source/backend/engine/jack.cpp @@ -66,24 +66,24 @@ public: if (! engine) { - buffer = nullptr; + fBuffer = nullptr; return; } if (! m_port) return CarlaEngineAudioPort::initBuffer(engine); - buffer = jackbridge_port_get_buffer(m_port, engine->getBufferSize()); + fBuffer = (float*)jackbridge_port_get_buffer(m_port, engine->getBufferSize()); } float* getBuffer() const { - return (float*)buffer; + return fBuffer; } private: jack_client_t* const m_client; - jack_port_t* const m_port; + jack_port_t* const m_port; CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaEngineJackAudioPort) }; @@ -125,17 +125,17 @@ public: if (! engine) { - buffer = nullptr; + fBuffer = nullptr; return; } if (! m_port) return CarlaEngineEventPort::initBuffer(engine); - buffer = jackbridge_port_get_buffer(m_port, engine->getBufferSize()); + fBuffer = jackbridge_port_get_buffer(m_port, engine->getBufferSize()); - if (! isInput) - jackbridge_midi_clear_buffer(buffer); + if (! kIsInput) + jackbridge_midi_clear_buffer(fBuffer); } uint32_t getEventCount() @@ -143,15 +143,15 @@ public: if (! m_port) return CarlaEngineEventPort::getEventCount(); - if (! isInput) + if (! kIsInput) return 0; - CARLA_ASSERT(buffer); + CARLA_ASSERT(fBuffer); - if (! buffer) + if (! fBuffer) return 0; - return jackbridge_midi_get_event_count(buffer); + return jackbridge_midi_get_event_count(fBuffer); } const EngineEvent* getEvent(const uint32_t index) @@ -159,17 +159,17 @@ public: if (! m_port) return CarlaEngineEventPort::getEvent(index); - if (! isInput) + if (! kIsInput) return nullptr; - CARLA_ASSERT(buffer); + CARLA_ASSERT(fBuffer); - if (! buffer) + if (! fBuffer) return nullptr; jack_midi_event_t jackEvent; - if (jackbridge_midi_event_get(&jackEvent, buffer, index) != 0 || jackEvent.size > 3) + if (jackbridge_midi_event_get(&jackEvent, fBuffer, index) != 0 || jackEvent.size > 3) return nullptr; m_retEvent.clear(); @@ -183,25 +183,25 @@ public: if (MIDI_IS_STATUS_CONTROL_CHANGE(midiStatus)) { const uint8_t midiControl = jackEvent.buffer[1]; - m_retEvent.type = EngineEventTypeControl; + m_retEvent.type = kEngineEventTypeControl; if (MIDI_IS_CONTROL_BANK_SELECT(midiControl)) { const uint8_t midiBank = jackEvent.buffer[2]; - m_retEvent.ctrl.type = EngineControlEventTypeMidiBank; + m_retEvent.ctrl.type = kEngineControlEventTypeMidiBank; m_retEvent.ctrl.parameter = midiBank; m_retEvent.ctrl.value = 0.0; } else if (midiControl == MIDI_CONTROL_ALL_SOUND_OFF) { - m_retEvent.ctrl.type = EngineControlEventTypeAllSoundOff; + m_retEvent.ctrl.type = kEngineControlEventTypeAllSoundOff; m_retEvent.ctrl.parameter = 0; m_retEvent.ctrl.value = 0.0; } else if (midiControl == MIDI_CONTROL_ALL_NOTES_OFF) { - m_retEvent.ctrl.type = EngineControlEventTypeAllNotesOff; + m_retEvent.ctrl.type = kEngineControlEventTypeAllNotesOff; m_retEvent.ctrl.parameter = 0; m_retEvent.ctrl.value = 0.0; } @@ -209,7 +209,7 @@ public: { const uint8_t midiValue = jackEvent.buffer[2]; - m_retEvent.ctrl.type = EngineControlEventTypeParameter; + m_retEvent.ctrl.type = kEngineControlEventTypeParameter; m_retEvent.ctrl.parameter = midiControl; m_retEvent.ctrl.value = double(midiValue)/127; } @@ -217,15 +217,15 @@ public: else if (MIDI_IS_STATUS_PROGRAM_CHANGE(midiStatus)) { const uint8_t midiProgram = jackEvent.buffer[1]; - m_retEvent.type = EngineEventTypeControl; + m_retEvent.type = kEngineEventTypeControl; - m_retEvent.ctrl.type = EngineControlEventTypeMidiProgram; + m_retEvent.ctrl.type = kEngineControlEventTypeMidiProgram; m_retEvent.ctrl.parameter = midiProgram; m_retEvent.ctrl.value = 0.0; } else { - m_retEvent.type = EngineEventTypeMidi; + m_retEvent.type = kEngineEventTypeMidi; m_retEvent.midi.data[0] = midiStatus; m_retEvent.midi.data[1] = jackEvent.buffer[1]; @@ -241,20 +241,20 @@ public: if (! m_port) return CarlaEngineEventPort::writeControlEvent(time, channel, type, parameter, value); - if (isInput) + if (kIsInput) return; - CARLA_ASSERT(buffer); - CARLA_ASSERT(type != EngineControlEventTypeNull); + CARLA_ASSERT(fBuffer); + CARLA_ASSERT(type != kEngineControlEventTypeNull); CARLA_ASSERT(channel < MAX_MIDI_CHANNELS); - if (! buffer) + if (! fBuffer) return; - if (type == EngineControlEventTypeNull) + if (type == kEngineControlEventTypeNull) return; if (channel >= MAX_MIDI_CHANNELS) return; - if (type == EngineControlEventTypeParameter) + if (type == kEngineControlEventTypeParameter) { CARLA_ASSERT(! MIDI_IS_CONTROL_BANK_SELECT(parameter)); } @@ -264,31 +264,31 @@ public: switch (type) { - case EngineControlEventTypeNull: + case kEngineControlEventTypeNull: break; - case EngineControlEventTypeParameter: + case kEngineControlEventTypeParameter: data[0] = MIDI_STATUS_CONTROL_CHANGE + channel; data[1] = parameter; data[2] = value * 127; size = 3; break; - case EngineControlEventTypeMidiBank: + case kEngineControlEventTypeMidiBank: data[0] = MIDI_STATUS_CONTROL_CHANGE + channel; data[1] = MIDI_CONTROL_BANK_SELECT; data[2] = value; size = 3; break; - case EngineControlEventTypeMidiProgram: + case kEngineControlEventTypeMidiProgram: data[0] = MIDI_STATUS_PROGRAM_CHANGE + channel; data[1] = value; size = 2; break; - case EngineControlEventTypeAllSoundOff: + case kEngineControlEventTypeAllSoundOff: data[0] = MIDI_STATUS_CONTROL_CHANGE + channel; data[1] = MIDI_CONTROL_ALL_SOUND_OFF; size = 2; break; - case EngineControlEventTypeAllNotesOff: + case kEngineControlEventTypeAllNotesOff: data[0] = MIDI_STATUS_CONTROL_CHANGE + channel; data[1] = MIDI_CONTROL_ALL_NOTES_OFF; size = 2; @@ -296,7 +296,7 @@ public: } if (size > 0) - jackbridge_midi_event_write(buffer, time, data, size); + jackbridge_midi_event_write(fBuffer, time, data, size); } void writeMidiEvent(const uint32_t time, const uint8_t channel, const uint8_t* const data, const uint8_t size) @@ -304,15 +304,15 @@ public: if (! m_port) return CarlaEngineEventPort::writeMidiEvent(time, channel, data, size); - if (isInput) + if (kIsInput) return; - CARLA_ASSERT(buffer); + CARLA_ASSERT(fBuffer); CARLA_ASSERT(channel < MAX_MIDI_CHANNELS); CARLA_ASSERT(data); CARLA_ASSERT(size > 0); - if (! buffer) + if (! fBuffer) return; if (channel >= MAX_MIDI_CHANNELS) return; @@ -324,12 +324,14 @@ public: jdata[0] = data[0] + channel; - jackbridge_midi_event_write(buffer, time, jdata, size); + jackbridge_midi_event_write(fBuffer, time, jdata, size); } private: + void* fBuffer; + jack_client_t* const m_client; - jack_port_t* const m_port; + jack_port_t* const m_port; EngineEvent m_retEvent; @@ -359,7 +361,7 @@ public: { qDebug("CarlaEngineClient::~CarlaEngineClient()"); - if (processMode == PROCESS_MODE_MULTIPLE_CLIENTS) + if (kProcessMode == PROCESS_MODE_MULTIPLE_CLIENTS) { if (m_client) jackbridge_client_close(m_client); @@ -370,7 +372,7 @@ public: { qDebug("CarlaEngineClient::activate()"); - if (processMode == PROCESS_MODE_MULTIPLE_CLIENTS) + if (kProcessMode == PROCESS_MODE_MULTIPLE_CLIENTS) { CARLA_ASSERT(m_client && ! isActive()); @@ -385,7 +387,7 @@ public: { qDebug("CarlaEngineClient::deactivate()"); - if (processMode == PROCESS_MODE_MULTIPLE_CLIENTS) + if (kProcessMode == PROCESS_MODE_MULTIPLE_CLIENTS) { CARLA_ASSERT(m_client && isActive()); @@ -425,12 +427,12 @@ public: { switch (portType) { - case EnginePortTypeNull: + case kEnginePortTypeNull: break; - case EnginePortTypeAudio: + case kEnginePortTypeAudio: port = jackbridge_port_register(m_client, name, JACK_DEFAULT_AUDIO_TYPE, isInput ? JackPortIsInput : JackPortIsOutput, 0); break; - case EnginePortTypeEvent: + case kEnginePortTypeEvent: port = jackbridge_port_register(m_client, name, JACK_DEFAULT_MIDI_TYPE, isInput ? JackPortIsInput : JackPortIsOutput, 0); break; } @@ -439,12 +441,12 @@ public: // Create Engine port switch (portType) { - case EnginePortTypeNull: + case kEnginePortTypeNull: break; - case EnginePortTypeAudio: - return new CarlaEngineJackAudioPort(isInput, processMode, m_client, port); - case EnginePortTypeEvent: - return new CarlaEngineJackEventPort(isInput, processMode, m_client, port); + case kEnginePortTypeAudio: + return new CarlaEngineJackAudioPort(isInput, kProcessMode, m_client, port); + case kEnginePortTypeEvent: + return new CarlaEngineJackEventPort(isInput, kProcessMode, m_client, port); } qCritical("CarlaJackEngineClient::addPort(%s, \"%s\", %s) - invalid type", EnginePortType2Str(portType), name, bool2str(isInput)); @@ -467,7 +469,7 @@ public: CarlaEngineJack() : CarlaEngine() #ifndef BUILD_BRIDGE - , m_rackPorts{nullptr} + , fRackPorts{nullptr} #endif { qDebug("CarlaEngineJack::CarlaEngineJack()"); @@ -492,22 +494,22 @@ public: // ------------------------------------------------------------------- // Maximum values - int maxClientNameSize() + unsigned int maxClientNameSize() { #ifndef BUILD_BRIDGE - if (options.processMode == PROCESS_MODE_SINGLE_CLIENT || options.processMode == PROCESS_MODE_MULTIPLE_CLIENTS) + if (fOptions.processMode == PROCESS_MODE_SINGLE_CLIENT || fOptions.processMode == PROCESS_MODE_MULTIPLE_CLIENTS) #endif - return jackbridge_client_name_size() - 3; // reserve space for "_2" forced-stereo ports + return (unsigned int)jackbridge_client_name_size() - 3; // reserve space for "_2" forced-stereo ports return CarlaEngine::maxClientNameSize(); } - int maxPortNameSize() + unsigned int maxPortNameSize() { #ifndef BUILD_BRIDGE - if (options.processMode == PROCESS_MODE_SINGLE_CLIENT || options.processMode == PROCESS_MODE_MULTIPLE_CLIENTS) + if (fOptions.processMode == PROCESS_MODE_SINGLE_CLIENT || fOptions.processMode == PROCESS_MODE_MULTIPLE_CLIENTS) #endif - return jackbridge_port_name_size(); + return (unsigned int)jackbridge_port_name_size(); return CarlaEngine::maxPortNameSize(); } @@ -527,8 +529,8 @@ public: if (m_client) { - bufferSize = jackbridge_get_buffer_size(m_client); - sampleRate = jackbridge_get_sample_rate(m_client); + fBufferSize = jackbridge_get_buffer_size(m_client); + fSampleRate = jackbridge_get_sample_rate(m_client); jackbridge_set_buffer_size_callback(m_client, carla_jack_bufsize_callback, this); jackbridge_set_sample_rate_callback(m_client, carla_jack_srate_callback, this); @@ -537,22 +539,22 @@ public: jackbridge_set_latency_callback(m_client, carla_jack_latency_callback, this); jackbridge_on_shutdown(m_client, carla_jack_shutdown_callback, this); - if (options.processMode == PROCESS_MODE_CONTINUOUS_RACK) + if (fOptions.processMode == PROCESS_MODE_CONTINUOUS_RACK) { - m_rackPorts[rackPortAudioIn1] = jackbridge_port_register(m_client, "audio-in1", JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0); - m_rackPorts[rackPortAudioIn2] = jackbridge_port_register(m_client, "audio-in2", JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0); - m_rackPorts[rackPortAudioOut1] = jackbridge_port_register(m_client, "audio-out1", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); - m_rackPorts[rackPortAudioOut2] = jackbridge_port_register(m_client, "audio-out2", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); - m_rackPorts[rackPortEventIn] = jackbridge_port_register(m_client, "events-in", JACK_DEFAULT_MIDI_TYPE, JackPortIsInput, 0); - m_rackPorts[rackPortEventOut] = jackbridge_port_register(m_client, "events-out", JACK_DEFAULT_MIDI_TYPE, JackPortIsOutput, 0); + fRackPorts[rackPortAudioIn1] = jackbridge_port_register(m_client, "audio-in1", JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0); + fRackPorts[rackPortAudioIn2] = jackbridge_port_register(m_client, "audio-in2", JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0); + fRackPorts[rackPortAudioOut1] = jackbridge_port_register(m_client, "audio-out1", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); + fRackPorts[rackPortAudioOut2] = jackbridge_port_register(m_client, "audio-out2", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); + fRackPorts[rackPortEventIn] = jackbridge_port_register(m_client, "events-in", JACK_DEFAULT_MIDI_TYPE, JackPortIsInput, 0); + fRackPorts[rackPortEventOut] = jackbridge_port_register(m_client, "events-out", JACK_DEFAULT_MIDI_TYPE, JackPortIsOutput, 0); } if (jackbridge_activate(m_client) == 0) { - name = jackbridge_get_client_name(m_client); - name.toBasic(); + fName = jackbridge_get_client_name(m_client); + fName.toBasic(); - CarlaEngine::init(name); + CarlaEngine::init(fName); return true; } else @@ -601,14 +603,14 @@ public: #else if (jackbridge_deactivate(m_client) == 0) { - if (options.processMode == PROCESS_MODE_CONTINUOUS_RACK) + if (fOptions.processMode == PROCESS_MODE_CONTINUOUS_RACK) { - jackbridge_port_unregister(m_client, m_rackPorts[rackPortAudioIn1]); - jackbridge_port_unregister(m_client, m_rackPorts[rackPortAudioIn2]); - jackbridge_port_unregister(m_client, m_rackPorts[rackPortAudioOut1]); - jackbridge_port_unregister(m_client, m_rackPorts[rackPortAudioOut2]); - jackbridge_port_unregister(m_client, m_rackPorts[rackPortEventIn]); - jackbridge_port_unregister(m_client, m_rackPorts[rackPortEventOut]); + jackbridge_port_unregister(m_client, fRackPorts[rackPortAudioIn1]); + jackbridge_port_unregister(m_client, fRackPorts[rackPortAudioIn2]); + jackbridge_port_unregister(m_client, fRackPorts[rackPortAudioOut1]); + jackbridge_port_unregister(m_client, fRackPorts[rackPortAudioOut2]); + jackbridge_port_unregister(m_client, fRackPorts[rackPortEventIn]); + jackbridge_port_unregister(m_client, fRackPorts[rackPortEventOut]); } if (jackbridge_client_close(m_client) == 0) @@ -643,7 +645,7 @@ public: EngineType type() const { - return EngineTypeJack; + return kEngineTypeJack; } CarlaEngineClient* addClient(CarlaPlugin* const plugin) @@ -663,11 +665,11 @@ public: jackbridge_set_latency_callback(client, carla_jack_latency_callback, this); jackbridge_on_shutdown(client, carla_jack_shutdown_callback, this); #else - if (options.processMode == PROCESS_MODE_SINGLE_CLIENT) + if (fOptions.processMode == PROCESS_MODE_SINGLE_CLIENT) { client = m_client; } - else if (options.processMode == PROCESS_MODE_MULTIPLE_CLIENTS) + else if (fOptions.processMode == PROCESS_MODE_MULTIPLE_CLIENTS) { client = jackbridge_client_open(plugin->name(), JackNullOption, nullptr); jackbridge_set_process_callback(client, carla_jack_process_callback_plugin, plugin); @@ -676,9 +678,9 @@ public: #endif #ifdef BUILD_BRIDGE - return new CarlaEngineJackClient(EngineTypeJack, PROCESS_MODE_MULTIPLE_CLIENTS, client); + return new CarlaEngineJackClient(kEngineTypeJack, PROCESS_MODE_MULTIPLE_CLIENTS, client); #else - return new CarlaEngineJackClient(EngineTypeJack, options.processMode, client); + return new CarlaEngineJackClient(kEngineTypeJack, fOptions.processMode, client); #endif } @@ -687,10 +689,10 @@ public: protected: void handleJackBufferSizeCallback(const uint32_t newBufferSize) { - bufferSize = newBufferSize; + fBufferSize = newBufferSize; #ifndef BUILD_BRIDGE - if (options.processHighPrecision) + if (fOptions.processHighPrecision) return; #endif @@ -699,7 +701,7 @@ protected: void handleJackSampleRateCallback(const double newSampleRate) { - sampleRate = newSampleRate; + fSampleRate = newSampleRate; } void handleJackFreewheelCallback(const bool isFreewheel) @@ -717,32 +719,32 @@ protected: m_pos.unique_1 = m_pos.unique_2 + 1; // invalidate m_state = jackbridge_transport_query(m_client, &m_pos); - timeInfo.playing = (m_state != JackTransportStopped); + fTimeInfo.playing = (m_state != JackTransportStopped); if (m_pos.unique_1 == m_pos.unique_2) { - timeInfo.frame = m_pos.frame; - timeInfo.time = m_pos.usecs; + fTimeInfo.frame = m_pos.frame; + fTimeInfo.time = m_pos.usecs; if (m_pos.valid & JackPositionBBT) { - timeInfo.valid = timeInfo.ValidBBT; - timeInfo.bbt.bar = m_pos.bar; - timeInfo.bbt.beat = m_pos.beat; - timeInfo.bbt.tick = m_pos.tick; - timeInfo.bbt.barStartTick = m_pos.bar_start_tick; - timeInfo.bbt.beatsPerBar = m_pos.beats_per_bar; - timeInfo.bbt.beatType = m_pos.beat_type; - timeInfo.bbt.ticksPerBeat = m_pos.ticks_per_beat; - timeInfo.bbt.beatsPerMinute = m_pos.beats_per_minute; + fTimeInfo.valid = EngineTimeInfo::ValidBBT; + fTimeInfo.bbt.bar = m_pos.bar; + fTimeInfo.bbt.beat = m_pos.beat; + fTimeInfo.bbt.tick = m_pos.tick; + fTimeInfo.bbt.barStartTick = m_pos.bar_start_tick; + fTimeInfo.bbt.beatsPerBar = m_pos.beats_per_bar; + fTimeInfo.bbt.beatType = m_pos.beat_type; + fTimeInfo.bbt.ticksPerBeat = m_pos.ticks_per_beat; + fTimeInfo.bbt.beatsPerMinute = m_pos.beats_per_minute; } else - timeInfo.valid = 0; + fTimeInfo.valid = 0; } else { - timeInfo.frame = 0; - timeInfo.valid = 0; + fTimeInfo.frame = 0; + fTimeInfo.valid = 0; } #if 0 @@ -940,7 +942,7 @@ protected: void handleJackLatencyCallback(const jack_latency_callback_mode_t mode) { #ifndef BUILD_BRIDGE - if (options.processMode != PROCESS_MODE_SINGLE_CLIENT) + if (fOptions.processMode != PROCESS_MODE_SINGLE_CLIENT) return; #endif @@ -992,7 +994,7 @@ private: rackPortCount = 8 }; - jack_port_t* m_rackPorts[rackPortCount]; + jack_port_t* fRackPorts[rackPortCount]; #endif // ------------------------------------- @@ -1119,10 +1121,10 @@ private: if (plugin && plugin->enabled()) { - plugin->engineProcessLock(); + //plugin->engineProcessLock(); plugin->initBuffers(); processPlugin(plugin, nframes); - plugin->engineProcessUnlock(); + //plugin->engineProcessUnlock(); } return 0; diff --git a/source/backend/engine/rtaudio.cpp b/source/backend/engine/rtaudio.cpp index e4a28a257..b72a9bb7f 100644 --- a/source/backend/engine/rtaudio.cpp +++ b/source/backend/engine/rtaudio.cpp @@ -53,12 +53,12 @@ public: switch (portType) { - case EnginePortTypeNull: + case kEnginePortTypeNull: break; - case EnginePortTypeAudio: - return new CarlaEngineAudioPort(isInput, processMode); - case EnginePortTypeEvent: - return new CarlaEngineEventPort(isInput, processMode); + case kEnginePortTypeAudio: + return new CarlaEngineAudioPort(isInput, kProcessMode); + case kEnginePortTypeEvent: + return new CarlaEngineEventPort(isInput, kProcessMode); } qCritical("CarlaEngineRtAudioClient::addPort(%s, \"%s\", %s) - invalid type", EnginePortType2Str(portType), name, bool2str(isInput)); @@ -91,8 +91,8 @@ public: m_outBuf2 = nullptr; // just to make sure - options.forceStereo = true; - options.processMode = PROCESS_MODE_CONTINUOUS_RACK; + fOptions.forceStereo = true; + fOptions.processMode = PROCESS_MODE_CONTINUOUS_RACK; } ~CarlaEngineRtAudio() @@ -112,8 +112,8 @@ public: return false; } - bufferSize = options.preferredBufferSize; - sampleRate = options.preferredSampleRate; + fBufferSize = fOptions.preferredBufferSize; + fSampleRate = fOptions.preferredSampleRate; RtAudio::StreamParameters iParams, oParams; iParams.deviceId = audio.getDefaultInputDevice(); @@ -139,7 +139,7 @@ public: m_audioInterleaved = true; try { - audio.openStream(&oParams, &iParams, RTAUDIO_FLOAT32, sampleRate, &bufferSize, carla_rtaudio_process_callback, this, &rtOptions); + audio.openStream(&oParams, &iParams, RTAUDIO_FLOAT32, fSampleRate, &fBufferSize, carla_rtaudio_process_callback, this, &rtOptions); } catch (RtError& e) { @@ -156,12 +156,12 @@ public: return false; } - sampleRate = audio.getStreamSampleRate(); + fSampleRate = audio.getStreamSampleRate(); - m_inBuf1 = new float [bufferSize]; - m_inBuf2 = new float [bufferSize]; - m_outBuf1 = new float [bufferSize]; - m_outBuf2 = new float [bufferSize]; + m_inBuf1 = new float[fBufferSize]; + m_inBuf2 = new float[fBufferSize]; + m_outBuf1 = new float[fBufferSize]; + m_outBuf2 = new float[fBufferSize]; //midiIn = new MidiInAlsa(clientName, 512); //midiIn->openVirtualPort("control-in"); @@ -171,10 +171,10 @@ public: //midiOut->openVirtualPort("control-out"); //midiOut->openVirtualPort("midi-out"); - name = clientName; - name.toBasic(); + fName = clientName; + fName.toBasic(); - CarlaEngine::init(name); + CarlaEngine::init(fName); return true; } @@ -245,12 +245,12 @@ public: EngineType type() const { - return EngineTypeRtAudio; + return kEngineTypeRtAudio; } CarlaEngineClient* addClient(CarlaPlugin* const) { - return new CarlaEngineRtAudioClient(EngineTypeRtAudio, options.processMode); + return new CarlaEngineRtAudioClient(kEngineTypeRtAudio, fOptions.processMode); } // ------------------------------------- @@ -294,7 +294,7 @@ protected: float* outBuf[2] = { m_outBuf1, m_outBuf2 }; // initialize events input - memset(rackEventsIn, 0, sizeof(EngineEvent)*MAX_EVENTS); + //memset(rackEventsIn, 0, sizeof(EngineEvent)*MAX_EVENTS); { // TODO } diff --git a/source/backend/native/3bandeq/DistrhoPlugin3BandEQ.cpp b/source/backend/native/3bandeq/DistrhoPlugin3BandEQ.cpp index 1afb599ae..31e8da2b4 100644 --- a/source/backend/native/3bandeq/DistrhoPlugin3BandEQ.cpp +++ b/source/backend/native/3bandeq/DistrhoPlugin3BandEQ.cpp @@ -166,17 +166,17 @@ void DistrhoPlugin3BandEQ::d_setParameterValue(uint32_t index, float value) outVol = std::exp( (fMaster/48.0f) * 48 / cfAMP_DB); break; case paramLowMidFreq: - fLowMidFreq = std::min(value, fMidHighFreq); + fLowMidFreq = std::fmin(value, fMidHighFreq); freqLP = fLowMidFreq; //fLowMidFreq * (fLowMidFreq / 24000.0f) * (fLowMidFreq / 24000.0f); - xLP = std::exp(-2.0 * cfPI * freqLP / d_sampleRate()); - a0LP = 1.0 - xLP; + xLP = std::exp(-2.0f * cfPI * freqLP / (float)d_sampleRate()); + a0LP = 1.0f - xLP; b1LP = -xLP; break; case paramMidHighFreq: - fMidHighFreq = std::max(value, fLowMidFreq); + fMidHighFreq = std::fmax(value, fLowMidFreq); freqHP = fMidHighFreq; //fMidHighFreq * (fMidHighFreq / 24000.0f) * (fMidHighFreq / 24000.0f); - xHP = std::exp(-2.0 * cfPI * freqHP / d_sampleRate()); - a0HP = 1.0 - xHP; + xHP = std::exp(-2.0f * cfPI * freqHP / (float)d_sampleRate()); + a0HP = 1.0f - xHP; b1HP = -xHP; break; } @@ -209,11 +209,11 @@ void DistrhoPlugin3BandEQ::d_setProgram(uint32_t index) void DistrhoPlugin3BandEQ::d_activate() { - xLP = std::exp(-2.0 * cfPI * freqLP / d_sampleRate()); + xLP = std::exp(-2.0f * cfPI * freqLP / (float)d_sampleRate()); a0LP = 1.0f - xLP; b1LP = -xLP; - xHP = std::exp(-2.0 * cfPI * freqHP / d_sampleRate()); + xHP = std::exp(-2.0f * cfPI * freqHP / (float)d_sampleRate()); a0HP = 1.0f - xHP; b1HP = -xHP; } diff --git a/source/backend/native/3bandeq/DistrhoUI3BandEQ.hpp b/source/backend/native/3bandeq/DistrhoUI3BandEQ.hpp index a3d05dcc0..1ad00ab80 100644 --- a/source/backend/native/3bandeq/DistrhoUI3BandEQ.hpp +++ b/source/backend/native/3bandeq/DistrhoUI3BandEQ.hpp @@ -36,14 +36,14 @@ public: protected: // Information - unsigned int d_width() + int d_width() { - return DistrhoArtwork3BandEQ::backgroundWidth; + return (int)DistrhoArtwork3BandEQ::backgroundWidth; } - unsigned int d_height() + int d_height() { - return DistrhoArtwork3BandEQ::backgroundHeight; + return (int)DistrhoArtwork3BandEQ::backgroundHeight; } // DSP Callbacks diff --git a/source/backend/native/3bandsplitter/DistrhoPlugin3BandSplitter.cpp b/source/backend/native/3bandsplitter/DistrhoPlugin3BandSplitter.cpp index 5aedc71d0..d6be2e22b 100644 --- a/source/backend/native/3bandsplitter/DistrhoPlugin3BandSplitter.cpp +++ b/source/backend/native/3bandsplitter/DistrhoPlugin3BandSplitter.cpp @@ -166,17 +166,17 @@ void DistrhoPlugin3BandSplitter::d_setParameterValue(uint32_t index, float value outVol = std::exp( (fMaster/48.0f) * 48 / cfAMP_DB); break; case paramLowMidFreq: - fLowMidFreq = std::min(value, fMidHighFreq); + fLowMidFreq = std::fmin(value, fMidHighFreq); freqLP = fLowMidFreq; //fLowMidFreq * (fLowMidFreq / 24000.0f) * (fLowMidFreq / 24000.0f); - xLP = std::exp(-2.0 * cfPI * freqLP / d_sampleRate()); - a0LP = 1.0 - xLP; + xLP = std::exp(-2.0f * cfPI * freqLP / (float)d_sampleRate()); + a0LP = 1.0f - xLP; b1LP = -xLP; break; case paramMidHighFreq: - fMidHighFreq = std::max(value, fLowMidFreq); + fMidHighFreq = std::fmax(value, fLowMidFreq); freqHP = fMidHighFreq; //fMidHighFreq * (fMidHighFreq / 24000.0f) * (fMidHighFreq / 24000.0f); - xHP = std::exp(-2.0 * cfPI * freqHP / d_sampleRate()); - a0HP = 1.0 - xHP; + xHP = std::exp(-2.0f * cfPI * freqHP / (float)d_sampleRate()); + a0HP = 1.0f - xHP; b1HP = -xHP; break; } @@ -209,11 +209,11 @@ void DistrhoPlugin3BandSplitter::d_setProgram(uint32_t index) void DistrhoPlugin3BandSplitter::d_activate() { - xLP = std::exp(-2.0 * cfPI * freqLP / d_sampleRate()); + xLP = std::exp(-2.0f * cfPI * freqLP / (float)d_sampleRate()); a0LP = 1.0f - xLP; b1LP = -xLP; - xHP = std::exp(-2.0 * cfPI * freqHP / d_sampleRate()); + xHP = std::exp(-2.0f * cfPI * freqHP / (float)d_sampleRate()); a0HP = 1.0f - xHP; b1HP = -xHP; } diff --git a/source/backend/native/3bandsplitter/DistrhoUI3BandSplitter.hpp b/source/backend/native/3bandsplitter/DistrhoUI3BandSplitter.hpp index e85d1d593..25e16f78a 100644 --- a/source/backend/native/3bandsplitter/DistrhoUI3BandSplitter.hpp +++ b/source/backend/native/3bandsplitter/DistrhoUI3BandSplitter.hpp @@ -36,12 +36,12 @@ public: protected: // Information - unsigned int d_width() + int d_width() { return DistrhoArtwork3BandSplitter::backgroundWidth; } - unsigned int d_height() + int d_height() { return DistrhoArtwork3BandSplitter::backgroundHeight; } diff --git a/source/backend/native/bypass.c b/source/backend/native/bypass.c index 5b5088bf3..ec0967de5 100644 --- a/source/backend/native/bypass.c +++ b/source/backend/native/bypass.c @@ -2,17 +2,17 @@ * Carla Native Plugins * Copyright (C) 2012-2013 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 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 COPYING file + * For a full copy of the GNU General Public License see the GPL.txt file */ #include "carla_native.h" diff --git a/source/backend/native/distrho-3bandeq.cpp b/source/backend/native/distrho-3bandeq.cpp index b49dbc0a3..65a934fe7 100644 --- a/source/backend/native/distrho-3bandeq.cpp +++ b/source/backend/native/distrho-3bandeq.cpp @@ -2,17 +2,17 @@ * Carla Native Plugins * Copyright (C) 2012-2013 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 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 COPYING file + * For a full copy of the GNU General Public License see the GPL.txt file */ #include "carla_native.hpp" @@ -29,7 +29,7 @@ START_NAMESPACE_DISTRHO // ----------------------------------------------------------------------- -static PluginDescriptor tBandEqDesc = { +static const PluginDescriptor tBandEqDesc = { /* category */ ::PLUGIN_CATEGORY_EQ, /* hints */ static_cast(::PLUGIN_IS_RTSAFE | ::PLUGIN_HAS_GUI), /* audioIns */ DISTRHO_PLUGIN_NUM_INPUTS, diff --git a/source/backend/native/distrho-3bandsplitter.cpp b/source/backend/native/distrho-3bandsplitter.cpp index 44ce49eec..f15ed4b4b 100644 --- a/source/backend/native/distrho-3bandsplitter.cpp +++ b/source/backend/native/distrho-3bandsplitter.cpp @@ -2,17 +2,17 @@ * Carla Native Plugins * Copyright (C) 2012-2013 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 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 COPYING file + * For a full copy of the GNU General Public License see the GPL.txt file */ #include "carla_native.hpp" @@ -29,7 +29,7 @@ START_NAMESPACE_DISTRHO // ----------------------------------------------------------------------- -static PluginDescriptor tBandSplitterDesc = { +static const PluginDescriptor tBandSplitterDesc = { /* category */ ::PLUGIN_CATEGORY_EQ, /* hints */ static_cast(::PLUGIN_IS_RTSAFE | ::PLUGIN_HAS_GUI), /* audioIns */ DISTRHO_PLUGIN_NUM_INPUTS, diff --git a/source/backend/native/distrho-pingpongpan.cpp b/source/backend/native/distrho-pingpongpan.cpp index 78b9e5ae2..fbacf4ee8 100644 --- a/source/backend/native/distrho-pingpongpan.cpp +++ b/source/backend/native/distrho-pingpongpan.cpp @@ -2,17 +2,17 @@ * Carla Native Plugins * Copyright (C) 2012-2013 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 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 COPYING file + * For a full copy of the GNU General Public License see the GPL.txt file */ #include "carla_native.hpp" diff --git a/source/backend/native/distrho/DistrhoPluginCarla.cpp b/source/backend/native/distrho/DistrhoPluginCarla.cpp index 12082dc1e..8a719da4b 100644 --- a/source/backend/native/distrho/DistrhoPluginCarla.cpp +++ b/source/backend/native/distrho/DistrhoPluginCarla.cpp @@ -46,7 +46,6 @@ public: setCentralWidget(&widget); setFixedSize(ui.getWidth(), ui.getHeight()); setWindowTitle(DISTRHO_PLUGIN_NAME); - } ~UICarla() @@ -111,7 +110,7 @@ protected: } # endif - void uiResize(unsigned int width, unsigned int height) + void uiResize(int width, int height) { setFixedSize(width, height); } @@ -182,7 +181,7 @@ private: # endif } - static void uiResizeCallback(void* ptr, unsigned int width, unsigned int height) + static void uiResizeCallback(void* ptr, int width, int height) { if (UICarla* _this_ = (UICarla*)ptr) _this_->uiResize(width, height); diff --git a/source/backend/native/midi-split.c b/source/backend/native/midi-split.c index 16eb7b825..050d9e0ee 100644 --- a/source/backend/native/midi-split.c +++ b/source/backend/native/midi-split.c @@ -2,21 +2,21 @@ * Carla Native Plugins * Copyright (C) 2012-2013 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 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 COPYING file + * For a full copy of the GNU General Public License see the GPL.txt file */ -#include "carla_midi.h" #include "carla_native.h" +#include "carla_midi.h" #include diff --git a/source/backend/native/midi-through.c b/source/backend/native/midi-through.c index 416cd8b1c..f85ff9b5c 100644 --- a/source/backend/native/midi-through.c +++ b/source/backend/native/midi-through.c @@ -2,21 +2,21 @@ * Carla Native Plugins * Copyright (C) 2012-2013 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 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 COPYING file + * For a full copy of the GNU General Public License see the GPL.txt file */ -#include "carla_midi.h" #include "carla_native.h" +#include "carla_midi.h" #include diff --git a/source/backend/native/pingpongpan/DistrhoPluginPingPongPan.cpp b/source/backend/native/pingpongpan/DistrhoPluginPingPongPan.cpp index dcba61488..f1795469a 100644 --- a/source/backend/native/pingpongpan/DistrhoPluginPingPongPan.cpp +++ b/source/backend/native/pingpongpan/DistrhoPluginPingPongPan.cpp @@ -100,7 +100,7 @@ void DistrhoPluginPingPongPan::d_setParameterValue(uint32_t index, float value) { case paramFreq: fFreq = value; - waveSpeed = (cf2PI * fFreq / 100.0f)/d_sampleRate(); + waveSpeed = (cf2PI * fFreq / 100.0f)/(float)d_sampleRate(); break; case paramWidth: fWidth = value; @@ -126,7 +126,7 @@ void DistrhoPluginPingPongPan::d_setProgram(uint32_t index) void DistrhoPluginPingPongPan::d_activate() { - waveSpeed = (cf2PI * fFreq / 100.0f)/d_sampleRate(); + waveSpeed = (cf2PI * fFreq / 100.0f)/(float)d_sampleRate(); } void DistrhoPluginPingPongPan::d_deactivate() @@ -143,7 +143,7 @@ void DistrhoPluginPingPongPan::d_run(float** inputs, float** outputs, uint32_t f for (uint32_t i=0; i < frames; i++) { - pan = std::min(std::max(sin(wavePos) * (fWidth/100.0f), -1.0f), 1.0f); + pan = std::fmin(std::fmax(std::sin(wavePos) * (fWidth/100.0f), -1.0f), 1.0f); if ((wavePos += waveSpeed) >= cf2PI) wavePos -= cf2PI; diff --git a/source/backend/native/pingpongpan/DistrhoUIPingPongPan.hpp b/source/backend/native/pingpongpan/DistrhoUIPingPongPan.hpp index fca10628f..68cbd4aa9 100644 --- a/source/backend/native/pingpongpan/DistrhoUIPingPongPan.hpp +++ b/source/backend/native/pingpongpan/DistrhoUIPingPongPan.hpp @@ -36,12 +36,12 @@ public: protected: // Information - unsigned int d_width() + int d_width() { return DistrhoArtworkPingPongPan::backgroundWidth; } - unsigned int d_height() + int d_height() { return DistrhoArtworkPingPongPan::backgroundHeight; } diff --git a/source/backend/native/zynaddsubfx.cpp b/source/backend/native/zynaddsubfx.cpp index a7f111607..f7fbc00e0 100644 --- a/source/backend/native/zynaddsubfx.cpp +++ b/source/backend/native/zynaddsubfx.cpp @@ -2,25 +2,25 @@ * Carla Native Plugins * Copyright (C) 2012-2013 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 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 COPYING file + * For a full copy of the GNU General Public License see the GPL.txt file */ // for UINT32_MAX #define __STDC_LIMIT_MACROS #include -#include "carla_midi.h" #include "carla_native.hpp" +#include "carla_midi.h" #include "zynaddsubfx/Misc/Master.h" #include "zynaddsubfx/Misc/Util.h" diff --git a/source/includes/carla_midi.h b/source/includes/carla_midi.h index e72ab76bb..8fb805b55 100644 --- a/source/includes/carla_midi.h +++ b/source/includes/carla_midi.h @@ -2,23 +2,25 @@ * Carla common MIDI code * Copyright (C) 2012-2013 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 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 COPYING file + * For a full copy of the GNU General Public License see the GPL.txt file */ #ifndef __CARLA_MIDI_H__ #define __CARLA_MIDI_H__ #define MAX_MIDI_CHANNELS 16 +#define MAX_MIDI_NOTE 128 +#define MAX_MIDI_VALUE 128 // MIDI Messages List #define MIDI_STATUS_NOTE_OFF 0x80 // note (0-127), velocity (0-127) diff --git a/source/libs/distrho-plugin-toolkit/DistrhoPlugin.h b/source/libs/distrho-plugin-toolkit/DistrhoPlugin.h index 20ea00ae8..006b638c6 100644 --- a/source/libs/distrho-plugin-toolkit/DistrhoPlugin.h +++ b/source/libs/distrho-plugin-toolkit/DistrhoPlugin.h @@ -69,7 +69,7 @@ struct ParameterRanges { this->stepLarge = stepLarge; } - void fixRange(float& value) const + void fixValue(float& value) const { if (value < min) value = min; diff --git a/source/libs/distrho-plugin-toolkit/DistrhoUI.h b/source/libs/distrho-plugin-toolkit/DistrhoUI.h index a57eaca28..37d2b2756 100644 --- a/source/libs/distrho-plugin-toolkit/DistrhoUI.h +++ b/source/libs/distrho-plugin-toolkit/DistrhoUI.h @@ -45,14 +45,14 @@ public: #if DISTRHO_PLUGIN_IS_SYNTH void d_uiSendNote(bool onOff, uint8_t channel, uint8_t note, uint8_t velocity); #endif - void d_uiResize(unsigned int width, unsigned int height); + void d_uiResize(int width, int height); // --------------------------------------------- protected: // Information - virtual unsigned int d_width() = 0; - virtual unsigned int d_height() = 0; + virtual int d_width() = 0; + virtual int d_height() = 0; // DSP Callbacks virtual void d_parameterChanged(uint32_t index, float value) = 0; diff --git a/source/libs/distrho-plugin-toolkit/DistrhoUIOpenGL.h b/source/libs/distrho-plugin-toolkit/DistrhoUIOpenGL.h index 0c330082a..24d08f1ae 100644 --- a/source/libs/distrho-plugin-toolkit/DistrhoUIOpenGL.h +++ b/source/libs/distrho-plugin-toolkit/DistrhoUIOpenGL.h @@ -17,7 +17,7 @@ #ifndef __DISTRHO_UI_OPENGL_H__ #define __DISTRHO_UI_OPENGL_H__ -#include "src/DistrhoDefines.h" +#include "src/DistrhoMacros.h" #ifdef DISTRHO_UI_OPENGL @@ -101,8 +101,8 @@ public: protected: // Information - virtual unsigned int d_width() = 0; - virtual unsigned int d_height() = 0; + virtual int d_width() = 0; + virtual int d_height() = 0; // DSP Callbacks virtual void d_parameterChanged(uint32_t index, float value) = 0; diff --git a/source/libs/distrho-plugin-toolkit/DistrhoUIOpenGLExt.h b/source/libs/distrho-plugin-toolkit/DistrhoUIOpenGLExt.h index d152fc03a..5c6099cbb 100644 --- a/source/libs/distrho-plugin-toolkit/DistrhoUIOpenGLExt.h +++ b/source/libs/distrho-plugin-toolkit/DistrhoUIOpenGLExt.h @@ -17,7 +17,7 @@ #ifndef __DISTRHO_UI_OPENGL_EXT_H__ #define __DISTRHO_UI_OPENGL_EXT_H__ -#include "src/DistrhoDefines.h" +#include "src/DistrhoMacros.h" #ifdef DISTRHO_UI_OPENGL @@ -249,8 +249,8 @@ public: protected: // Information - virtual unsigned int d_width() = 0; - virtual unsigned int d_height() = 0; + virtual int d_width() = 0; + virtual int d_height() = 0; // DSP Callbacks virtual void d_parameterChanged(uint32_t index, float value) = 0; diff --git a/source/libs/distrho-plugin-toolkit/DistrhoUtils.h b/source/libs/distrho-plugin-toolkit/DistrhoUtils.h index 795ad745f..7298ff371 100644 --- a/source/libs/distrho-plugin-toolkit/DistrhoUtils.h +++ b/source/libs/distrho-plugin-toolkit/DistrhoUtils.h @@ -102,7 +102,7 @@ public: d_string(int value) { - size_t strBufSize = abs(value/10) + 3; + size_t strBufSize = (unsigned int)abs(value/10) + 3; char strBuf[strBufSize]; snprintf(strBuf, strBufSize, "%d", value); diff --git a/source/libs/distrho-plugin-toolkit/src/DistrhoUI.cpp b/source/libs/distrho-plugin-toolkit/src/DistrhoUI.cpp index f5cbfda5f..67d7b3a2a 100644 --- a/source/libs/distrho-plugin-toolkit/src/DistrhoUI.cpp +++ b/source/libs/distrho-plugin-toolkit/src/DistrhoUI.cpp @@ -81,7 +81,7 @@ void UI::d_uiSendNote(bool onOff, uint8_t channel, uint8_t note, uint8_t velocit } #endif -void UI::d_uiResize(unsigned int width, unsigned int height) +void UI::d_uiResize(int width, int height) { data->uiResizeCallback(width, height); } diff --git a/source/libs/distrho-plugin-toolkit/src/DistrhoUIInternal.h b/source/libs/distrho-plugin-toolkit/src/DistrhoUIInternal.h index 1e19763db..7563fb396 100644 --- a/source/libs/distrho-plugin-toolkit/src/DistrhoUIInternal.h +++ b/source/libs/distrho-plugin-toolkit/src/DistrhoUIInternal.h @@ -51,7 +51,7 @@ typedef void (*setParamFunc) (void* ptr, uint32_t index, float value); typedef void (*setStateFunc) (void* ptr, const char* key, const char* value); typedef void (*uiEditParamFunc) (void* ptr, uint32_t index, bool started); typedef void (*uiSendNoteFunc) (void* ptr, bool onOff, uint8_t channel, uint8_t note, uint8_t velo); -typedef void (*uiResizeFunc) (void* ptr, unsigned int width, unsigned int height); +typedef void (*uiResizeFunc) (void* ptr, int width, int height); extern double d_lastUiSampleRate; @@ -140,7 +140,7 @@ struct UIPrivateData { uiSendNoteCallbackFunc(ptr, onOff, channel, note, velocity); } - void uiResizeCallback(unsigned int width, unsigned int height) + void uiResizeCallback(int width, int height) { if (uiResizeCallbackFunc) uiResizeCallbackFunc(ptr, width, height); @@ -201,13 +201,13 @@ public: ui->d_uiIdle(); } - unsigned int getWidth() + int getWidth() { assert(ui); return ui ? ui->d_width() : 0; } - unsigned int getHeight() + int getHeight() { assert(ui); return ui ? ui->d_height() : 0; diff --git a/source/libs/distrho-plugin-toolkit/src/DistrhoUIOpenGL.cpp b/source/libs/distrho-plugin-toolkit/src/DistrhoUIOpenGL.cpp index 6535b34a8..f7c46604f 100644 --- a/source/libs/distrho-plugin-toolkit/src/DistrhoUIOpenGL.cpp +++ b/source/libs/distrho-plugin-toolkit/src/DistrhoUIOpenGL.cpp @@ -14,7 +14,7 @@ * For a full copy of the license see the LGPL.txt file */ -#include "DistrhoDefines.h" +#include "DistrhoMacros.h" #ifdef DISTRHO_UI_OPENGL diff --git a/source/libs/distrho-plugin-toolkit/src/DistrhoUIOpenGLExt.cpp b/source/libs/distrho-plugin-toolkit/src/DistrhoUIOpenGLExt.cpp index 92e7d8ae8..65358755d 100644 --- a/source/libs/distrho-plugin-toolkit/src/DistrhoUIOpenGLExt.cpp +++ b/source/libs/distrho-plugin-toolkit/src/DistrhoUIOpenGLExt.cpp @@ -14,7 +14,7 @@ * For a full copy of the license see the LGPL.txt file */ -#include "DistrhoDefines.h" +#include "DistrhoMacros.h" #ifdef DISTRHO_UI_OPENGL @@ -168,15 +168,15 @@ Size& Size::operator/=(int d) Size& Size::operator*=(float m) { - _width *= m; - _height *= m; + _width = (int)((float)_width * m); + _height = (int)((float)_height * m); return *this; } Size& Size::operator/=(float d) { - _width /= d; - _height /= d; + _width = (int)((float)_width / d); + _height = (int)((float)_height / d); return *this; } @@ -729,7 +729,7 @@ public: if (view) { #if DISTRHO_OS_LINUX - PuglInternals* impl = puglGetInternalsImpl(view); + PuglInternals* impl = puglGetInternalsImpl(view); Display* display = impl->display; Window window = impl->win; XRaiseWindow(display, window); @@ -1073,7 +1073,7 @@ void OpenGLExtUI::d_onDisplay() int layerDataSize = knob->_layerSize * knob->_layerSize * 4; int imageDataSize = layerDataSize * knob->_layerCount; - int imageDataOffset = imageDataSize - layerDataSize - layerDataSize * rint(vper*(knob->_layerCount-1)); + int imageDataOffset = imageDataSize - layerDataSize - layerDataSize * int(vper * float(knob->_layerCount-1)); glRasterPos2i(knob->_pos.getX(), knob->_pos.getY()+knob->_area.getHeight()); glDrawPixels(knob->_layerSize, knob->_layerSize, knob->_image.getFormat(), knob->_image.getType(), knob->_image.getData() + imageDataOffset); @@ -1093,10 +1093,10 @@ void OpenGLExtUI::d_onDisplay() if (slider->_endPos.getX() > slider->_startPos.getX()) // horizontal - x += rint(vper * (slider->_area.getWidth()-slider->getWidth())); + x += int(vper * float(slider->_area.getWidth() - slider->getWidth())); else // vertical - y += slider->_area.getHeight() - rint(vper * (slider->_area.getHeight()-slider->getHeight())); + y += slider->_area.getHeight() - int(vper * float(slider->_area.getHeight() - slider->getHeight())); #if 0 // DEBUG glColor3i(160, 90, 161); @@ -1175,8 +1175,8 @@ void OpenGLExtUI::d_onMotion(int x, int y) if (movX != 0) { - int d = (d_uiGetModifiers() & MODIFIER_SHIFT) ? 2000 : 200; - float value = knob->_value + (knob->_max - knob->_min) / d * movX; + float d = (d_uiGetModifiers() & MODIFIER_SHIFT) ? 2000 : 200; + float value = knob->_value + float(knob->_max - knob->_min) / d * float(movX); if (value < knob->_min) value = knob->_min; @@ -1198,8 +1198,8 @@ void OpenGLExtUI::d_onMotion(int x, int y) if (movY != 0) { - int d = (d_uiGetModifiers() & MODIFIER_SHIFT) ? 2000 : 200; - float value = knob->_value + (knob->_max - knob->_min) / d * movY; + float d = (d_uiGetModifiers() & MODIFIER_SHIFT) ? 2000 : 200; + float value = knob->_value + float(knob->_max - knob->_min) / d * float(movY); if (value < knob->_min) value = knob->_min; @@ -1241,10 +1241,10 @@ void OpenGLExtUI::d_onMotion(int x, int y) if (horizontal) // horizontal - vper = float(x - slider->_area.getX()) / slider->_area.getWidth(); + vper = float(x - slider->_area.getX()) / float(slider->_area.getWidth()); else // vertical - vper = float(y - slider->_area.getY()) / slider->_area.getHeight(); + vper = float(y - slider->_area.getY()) / float(slider->_area.getHeight()); float value = slider->_max - vper * (slider->_max - slider->_min); @@ -1397,10 +1397,10 @@ void OpenGLExtUI::d_onMouse(int button, bool press, int x, int y) if (slider->_endPos.getX() > slider->_startPos.getX()) // horizontal - vper = float(x - slider->_area.getX()) / slider->_area.getWidth(); + vper = float(x - slider->_area.getX()) / float(slider->_area.getWidth()); else // vertical - vper = float(y - slider->_area.getY()) / slider->_area.getHeight(); + vper = float(y - slider->_area.getY()) / float(slider->_area.getHeight()); float value = slider->_max - vper * (slider->_max - slider->_min); diff --git a/source/libs/pugl/pugl.h b/source/libs/pugl/pugl.h index 5ec611dbd..4c4366fa1 100644 --- a/source/libs/pugl/pugl.h +++ b/source/libs/pugl/pugl.h @@ -122,7 +122,7 @@ typedef enum { PUGL_KEY_SHIFT, PUGL_KEY_CTRL, PUGL_KEY_ALT, - PUGL_KEY_SUPER, + PUGL_KEY_SUPER } PuglKey; /** @@ -132,7 +132,7 @@ typedef enum { PUGL_MOD_SHIFT = 1, /**< Shift key */ PUGL_MOD_CTRL = 1 << 1, /**< Control key */ PUGL_MOD_ALT = 1 << 2, /**< Alt/Option key */ - PUGL_MOD_SUPER = 1 << 3, /**< Mod4/Command/Windows key */ + PUGL_MOD_SUPER = 1 << 3 /**< Mod4/Command/Windows key */ } PuglMod; /** @@ -225,7 +225,7 @@ puglCreate(PuglNativeWindow parent, int height, bool resizable, bool addToDesktop = true, - const char* x11Display = NULL); + const char* x11Display = nullptr); /** Set the handle to be passed to all callbacks. diff --git a/source/libs/pugl/pugl_x11.c b/source/libs/pugl/pugl_x11.c index 3697734ad..759cd8801 100644 --- a/source/libs/pugl/pugl_x11.c +++ b/source/libs/pugl/pugl_x11.c @@ -64,7 +64,7 @@ puglCreate(PuglNativeWindow parent, PuglView* view = (PuglView*)calloc(1, sizeof(PuglView)); PuglInternals* impl = (PuglInternals*)calloc(1, sizeof(PuglInternals)); if (!view || !impl) { - return NULL; + return nullptr; } view->impl = impl; @@ -88,7 +88,7 @@ puglCreate(PuglNativeWindow parent, glXQueryVersion(impl->display, &glxMajor, &glxMinor); printf("GLX-Version %d.%d\n", glxMajor, glxMinor); - impl->ctx = glXCreateContext(impl->display, vi, 0, GL_TRUE); + impl->ctx = glXCreateContext(impl->display, vi, nullptr, GL_TRUE); Window xParent = parent ? (Window)parent @@ -108,7 +108,7 @@ puglCreate(PuglNativeWindow parent, impl->win = XCreateWindow( impl->display, xParent, - 0, 0, view->width, view->height, 0, vi->depth, InputOutput, vi->visual, + 0, 0, (unsigned int)view->width, (unsigned int)view->height, 0, vi->depth, InputOutput, vi->visual, CWBorderPixel | CWColormap | CWEventMask, &attr); XSizeHints sizeHints; @@ -267,13 +267,13 @@ puglProcessEvents(PuglView* view) view->redisplay = false; break; case MotionNotify: - setModifiers(view, event.xmotion.state); + setModifiers(view, (int)event.xmotion.state); if (view->motionFunc) { view->motionFunc(view, event.xmotion.x, event.xmotion.y); } break; case ButtonPress: - setModifiers(view, event.xbutton.state); + setModifiers(view, (int)event.xbutton.state); if (event.xbutton.button >= 4 && event.xbutton.button <= 7) { if (view->scrollFunc) { float dx = 0, dy = 0; @@ -289,23 +289,23 @@ puglProcessEvents(PuglView* view) } // nobreak case ButtonRelease: - setModifiers(view, event.xbutton.state); + setModifiers(view, (int)event.xbutton.state); if (view->mouseFunc && (event.xbutton.button < 4 || event.xbutton.button > 7)) { view->mouseFunc(view, - event.xbutton.button, event.type == ButtonPress, + (int)event.xbutton.button, event.type == ButtonPress, event.xbutton.x, event.xbutton.y); } break; case KeyPress: { - setModifiers(view, event.xkey.state); + setModifiers(view, (int)event.xkey.state); KeySym sym; char str[5]; - int n = XLookupString(&event.xkey, str, 4, &sym, NULL); + int n = XLookupString(&event.xkey, str, 4, &sym, nullptr); PuglKey key = keySymToSpecial(sym); if (!key && view->keyboardFunc) { if (n == 1) { - view->keyboardFunc(view, true, str[0]); + view->keyboardFunc(view, true, (uint32_t)str[0]); } else { fprintf(stderr, "warning: Unknown key %X\n", (int)sym); } @@ -314,7 +314,7 @@ puglProcessEvents(PuglView* view) } } break; case KeyRelease: { - setModifiers(view, event.xkey.state); + setModifiers(view, (int)event.xkey.state); bool repeated = false; if (view->ignoreKeyRepeat && XEventsQueued(view->impl->display, QueuedAfterReading)) { @@ -330,10 +330,10 @@ puglProcessEvents(PuglView* view) if (!repeated && view->keyboardFunc) { KeySym sym = XKeycodeToKeysym( - view->impl->display, event.xkey.keycode, 0); + view->impl->display, (KeyCode)event.xkey.keycode, 0); PuglKey special = keySymToSpecial(sym); if (!special) { - view->keyboardFunc(view, false, sym); + view->keyboardFunc(view, false, (uint32_t)sym); } else if (view->specialFunc) { view->specialFunc(view, false, special); } @@ -369,7 +369,7 @@ puglPostRedisplay(PuglView* view) PuglNativeWindow puglGetNativeWindow(PuglView* view) { - return view->impl->win; + return static_cast(view->impl->win); } PuglInternals* diff --git a/source/utils/carla_backend_utils.hpp b/source/utils/carla_backend_utils.hpp index a2a708bc8..dc3ec06e2 100644 --- a/source/utils/carla_backend_utils.hpp +++ b/source/utils/carla_backend_utils.hpp @@ -152,6 +152,8 @@ const char* InternalParametersIndex2Str(const InternalParametersIndex& index) return "PARAMETER_BALANCE_RIGHT"; case PARAMETER_PANNING: return "PARAMETER_PANNING"; + case PARAMETER_MAX: + return "PARAMETER_MAX"; } qWarning("CarlaBackend::InternalParametersIndex2Str(%i) - invalid index", index); @@ -300,7 +302,7 @@ const char* ProcessMode2Str(const ProcessMode& mode) // ------------------------------------------------- static inline -uintptr_t getAddressFromPointer(void* const ptr) +uintptr_t getAddressFromPointer(void* ptr) { qDebug("CarlaBackend::getAddressFromPointer(%p)", ptr); CARLA_ASSERT(ptr != nullptr); @@ -310,7 +312,7 @@ uintptr_t getAddressFromPointer(void* const ptr) } static inline -void* getPointerFromAddress(const uintptr_t& addr) +void* getPointerFromAddress(uintptr_t& addr) { CARLA_ASSERT(addr != 0); diff --git a/source/utils/carla_osc_utils.hpp b/source/utils/carla_osc_utils.hpp index 1faaabcca..7d4d3b405 100644 --- a/source/utils/carla_osc_utils.hpp +++ b/source/utils/carla_osc_utils.hpp @@ -2,17 +2,17 @@ * Carla OSC utils * Copyright (C) 2012-2013 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 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 COPYING file + * For a full copy of the GNU General Public License see the GPL.txt file */ #ifndef __CARLA_OSC_UTILS_HPP__ @@ -42,14 +42,13 @@ struct CarlaOscData { void free() { - if (path) - ::free((void*)path); + std::free((void*)path); if (source) - ::lo_address_free(source); + lo_address_free(source); if (target) - ::lo_address_free(target); + lo_address_free(target); path = nullptr; source = nullptr; diff --git a/source/utils/carla_utils.hpp b/source/utils/carla_utils.hpp index 60f4ed550..c669c547e 100644 --- a/source/utils/carla_utils.hpp +++ b/source/utils/carla_utils.hpp @@ -2,17 +2,17 @@ * Carla common utils * Copyright (C) 2011-2013 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 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 COPYING file + * For a full copy of the GNU General Public License see the GPL.txt file */ #ifndef __CARLA_UTILS_HPP__ @@ -103,8 +103,8 @@ void carla_usleep(const unsigned int usecs) static inline void carla_setenv(const char* const key, const char* const value) { - CARLA_ASSERT(key); - CARLA_ASSERT(value); + CARLA_ASSERT(key != nullptr); + CARLA_ASSERT(value != nullptr); #ifdef Q_OS_WIN SetEnvironmentVariableA(key, value); @@ -119,7 +119,7 @@ void carla_setenv(const char* const key, const char* const value) static inline void carla_setprocname(const char* const name) { - CARLA_ASSERT(name); + CARLA_ASSERT(name != nullptr); #if defined(Q_OS_HAIKU) if ((thread_id this_thread = find_thread(nullptr)) != B_NAME_NOT_FOUND) @@ -145,9 +145,12 @@ template static inline void carla_fill(T* data, const unsigned int size, const T v) { - CARLA_ASSERT(data); + CARLA_ASSERT(data != nullptr); CARLA_ASSERT(size > 0); + if (data == nullptr) + return; + for (unsigned int i=0; i < size; i++) *data++ = v; } @@ -170,7 +173,10 @@ void carla_zeroFloat(float* data, const unsigned size) static inline void carla_zeroMem(void* const memory, const size_t numBytes) { - CARLA_ASSERT(memory); + CARLA_ASSERT(memory != nullptr); + + if (memory == nullptr) + return; std::memset(memory, 0, numBytes); } @@ -278,8 +284,6 @@ private: // ------------------------------------------------- // CarlaString class -// TODO - use "size_t bufferLen" - class CarlaString { public: @@ -288,94 +292,77 @@ public: explicit CarlaString() { - buffer = ::strdup(""); - bufferLen = 0; + _init(); + _dup(nullptr); } explicit CarlaString(char* const strBuf) { - if (strBuf) - { - buffer = ::strdup(strBuf); - bufferLen = ::strlen(buffer); - } - else - { - buffer = ::strdup(""); - bufferLen = 0; - } + _init(); + _dup(strBuf); } explicit CarlaString(const char* const strBuf) { - if (strBuf) - { - buffer = ::strdup(strBuf); - bufferLen = ::strlen(buffer); - } - else - { - buffer = ::strdup(""); - bufferLen = 0; - } + _init(); + _dup(strBuf); } explicit CarlaString(const int value) { - const size_t strBufSize = ::abs(value/10) + 3; + const size_t strBufSize = (unsigned int)std::abs(value/10) + 3; char strBuf[strBufSize]; - ::snprintf(strBuf, strBufSize, "%d", value); + std::snprintf(strBuf, strBufSize, "%d", value); - buffer = ::strdup(strBuf); - bufferLen = ::strlen(buffer); + _init(); + _dup(strBuf, strBufSize); } explicit CarlaString(const unsigned int value, const bool hexadecimal = false) { const size_t strBufSize = value/10 + 2 + (hexadecimal ? 2 : 0); char strBuf[strBufSize]; - ::snprintf(strBuf, strBufSize, hexadecimal ? "%u" : "0x%x", value); + std::snprintf(strBuf, strBufSize, hexadecimal ? "0x%x" : "%u", value); - buffer = ::strdup(strBuf); - bufferLen = ::strlen(buffer); + _init(); + _dup(strBuf, strBufSize); } explicit CarlaString(const long int value) { - const size_t strBufSize = ::labs(value/10) + 3; + const size_t strBufSize = (unsigned long)std::abs(value/10) + 3; char strBuf[strBufSize]; - ::snprintf(strBuf, strBufSize, "%ld", value); + std::snprintf(strBuf, strBufSize, "%ld", value); - buffer = ::strdup(strBuf); - bufferLen = ::strlen(buffer); + _init(); + _dup(strBuf, strBufSize); } explicit CarlaString(const unsigned long int value, const bool hexadecimal = false) { const size_t strBufSize = value/10 + 2 + (hexadecimal ? 2 : 0); char strBuf[strBufSize]; - ::snprintf(strBuf, strBufSize, hexadecimal ? "%lu" : "0x%lx", value); + std::snprintf(strBuf, strBufSize, hexadecimal ? "0x%lx" : "%lu", value); - buffer = ::strdup(strBuf); - bufferLen = ::strlen(buffer); + _init(); + _dup(strBuf, strBufSize); } explicit CarlaString(const float value) { char strBuf[0xff]; - ::snprintf(strBuf, 0xff, "%f", value); + std::snprintf(strBuf, 0xff, "%f", value); - buffer = ::strdup(strBuf); - bufferLen = ::strlen(buffer); + _dup(strBuf); } explicit CarlaString(const double value) { char strBuf[0xff]; - ::snprintf(strBuf, 0xff, "%g", value); + std::snprintf(strBuf, 0xff, "%g", value); - buffer = ::strdup(strBuf); - bufferLen = ::strlen(buffer); + _init(); + _dup(strBuf); } // --------------------------------------------- @@ -383,8 +370,8 @@ public: CarlaString(const CarlaString& str) { - buffer = ::strdup(str.buffer); - bufferLen = ::strlen(buffer); + _init(); + _dup(str.buffer); } // --------------------------------------------- @@ -393,7 +380,8 @@ public: ~CarlaString() { CARLA_ASSERT(buffer); - ::free(buffer); + + delete[] buffer; } // --------------------------------------------- @@ -414,31 +402,35 @@ public: return (bufferLen != 0); } -#ifdef __USE_GNU +#if __USE_GNU && 0 bool contains(const char* const strBuf, const bool ignoreCase = false) const -#else - bool contains(const char* const strBuf) const -#endif { - if (! strBuf) + if (strBuf == nullptr) return false; if (bufferLen == 0) return false; -#ifdef __USE_GNU if (ignoreCase) - return (::strcasestr(buffer, strBuf) != nullptr); + return (std::strcasestr(buffer, strBuf) != nullptr); else -#endif - return (::strstr(buffer, strBuf) != nullptr); + return (std::strstr(buffer, strBuf) != nullptr); } -#ifdef __USE_GNU bool contains(const CarlaString& str, const bool ignoreCase = false) const { return contains(str.buffer, ignoreCase); } #else + bool contains(const char* const strBuf) const + { + if (strBuf == nullptr) + return false; + if (bufferLen == 0) + return false; + + return (std::strstr(buffer, strBuf) != nullptr); + } + bool contains(const CarlaString& str) const { return contains(str.buffer); @@ -460,14 +452,14 @@ public: void replace(const char before, const char after) { - if (after == 0) + if (after == '\0') return; for (size_t i=0; i < bufferLen; i++) { if (buffer[i] == before) buffer[i] = after; - else if (buffer[i] == 0) + else if (buffer[i] == '\0') break; } } @@ -475,7 +467,7 @@ public: void truncate(const size_t n) { for (size_t i=n; i < bufferLen; i++) - buffer[i] = 0; + buffer[i] = '\0'; } void toBasic() @@ -497,19 +489,23 @@ public: void toLower() { + static const char charDiff = 'a' - 'A'; + for (size_t i=0; i < bufferLen; i++) { if (buffer[i] >= 'A' && buffer[i] <= 'Z') - buffer[i] += 32; + buffer[i] += charDiff; } } void toUpper() { + static const char charDiff = 'a' - 'A'; + for (size_t i=0; i < bufferLen; i++) { if (buffer[i] >= 'a' && buffer[i] <= 'z') - buffer[i] -= 32; + buffer[i] -= charDiff; } } @@ -528,7 +524,7 @@ public: bool operator==(const char* const strBuf) const { - return (strBuf && ::strcmp(buffer, strBuf) == 0); + return (strBuf != nullptr && std::strcmp(buffer, strBuf) == 0); } bool operator==(const CarlaString& str) const @@ -548,18 +544,7 @@ public: CarlaString& operator=(const char* const strBuf) { - ::free(buffer); - - if (strBuf) - { - buffer = ::strdup(strBuf); - bufferLen = ::strlen(buffer); - } - else - { - buffer = ::strdup(""); - bufferLen = 0; - } + _dup(strBuf); return *this; } @@ -571,15 +556,13 @@ public: CarlaString& operator+=(const char* const strBuf) { - const size_t newBufSize = ::strlen(buffer) + (strBuf ? ::strlen(strBuf) : 0) + 1; + const size_t newBufSize = std::strlen(buffer) + ((strBuf != nullptr) ? std::strlen(strBuf) : 0) + 1; char newBuf[newBufSize]; - ::strcpy(newBuf, buffer); - ::strcat(newBuf, strBuf); - ::free(buffer); + std::strcpy(newBuf, buffer); + std::strcat(newBuf, strBuf); - buffer = ::strdup(newBuf); - bufferLen = ::strlen(buffer); + _dup(newBuf, newBufSize); return *this; } @@ -591,11 +574,11 @@ public: CarlaString operator+(const char* const strBuf) { - const size_t newBufSize = ::strlen(buffer) + (strBuf ? ::strlen(strBuf) : 0) + 1; + const size_t newBufSize = std::strlen(buffer) + ((strBuf != nullptr) ? std::strlen(strBuf) : 0) + 1; char newBuf[newBufSize]; - ::strcpy(newBuf, buffer); - ::strcat(newBuf, strBuf); + std::strcpy(newBuf, buffer); + std::strcat(newBuf, strBuf); return CarlaString(newBuf); } @@ -610,10 +593,58 @@ public: private: char* buffer; size_t bufferLen; + bool firstInit; + + void _init() + { + buffer = nullptr; + bufferLen = 0; + firstInit = true; + } - void _recalcLen() + // allocate string strBuf if not null + // size > 0 only if strBuf is valid + void _dup(const char* const strBuf, const size_t size = 0) { - bufferLen = ::strlen(buffer); + if (strBuf != nullptr) + { + // don't recreate string if contents match + if (firstInit || std::strcmp(buffer, strBuf) != 0) + { + if (! firstInit) + { + CARLA_ASSERT(buffer); + delete[] buffer; + } + + bufferLen = (size > 0) ? size : std::strlen(strBuf); + buffer = new char[bufferLen]; + + std::strcpy(buffer, strBuf); + + firstInit = false; + } + } + else + { + CARLA_ASSERT(size == 0); + + // don't recreate null string + if (firstInit || bufferLen != 0) + { + if (! firstInit) + { + CARLA_ASSERT(buffer); + delete[] buffer; + } + + bufferLen = 0; + buffer = new char[1]; + buffer[0] = 0; + + firstInit = false; + } + } } CARLA_LEAK_DETECTOR(CarlaString) @@ -624,11 +655,11 @@ static inline CarlaString operator+(const char* const strBufBefore, const CarlaString& strAfter) { const char* const strBufAfter = (const char*)strAfter; - const size_t newBufSize = (strBufBefore ? ::strlen(strBufBefore) : 0) + ::strlen(strBufAfter) + 1; + const size_t newBufSize = ((strBufBefore != nullptr) ? std::strlen(strBufBefore) : 0) + std::strlen(strBufAfter) + 1; char newBuf[newBufSize]; - ::strcpy(newBuf, strBufBefore); - ::strcat(newBuf, strBufAfter); + std::strcpy(newBuf, strBufBefore); + std::strcat(newBuf, strBufAfter); return CarlaString(newBuf); }