/* * Carla Backend 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 distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * For a full copy of the GNU General Public License see the doc/GPL.txt file. */ #ifndef CARLA_BACKEND_UTILS_HPP_INCLUDED #define CARLA_BACKEND_UTILS_HPP_INCLUDED #include "CarlaBackend.h" #include "CarlaString.hpp" CARLA_BACKEND_START_NAMESPACE // ----------------------------------------------------------------------- static inline const char* PluginOption2Str(const unsigned int option) { switch (option) { case PLUGIN_OPTION_FIXED_BUFFERS: return "PLUGIN_OPTION_FIXED_BUFFERS"; case PLUGIN_OPTION_FORCE_STEREO: return "PLUGIN_OPTION_FORCE_STEREO"; case PLUGIN_OPTION_MAP_PROGRAM_CHANGES: return "PLUGIN_OPTION_MAP_PROGRAM_CHANGES"; case PLUGIN_OPTION_USE_CHUNKS: return "PLUGIN_OPTION_USE_CHUNKS"; case PLUGIN_OPTION_SEND_CONTROL_CHANGES: return "PLUGIN_OPTION_SEND_CONTROL_CHANGES"; case PLUGIN_OPTION_SEND_CHANNEL_PRESSURE: return "PLUGIN_OPTION_SEND_CHANNEL_PRESSURE"; case PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH: return "PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH"; case PLUGIN_OPTION_SEND_PITCHBEND: return "PLUGIN_OPTION_SEND_PITCHBEND"; case PLUGIN_OPTION_SEND_ALL_SOUND_OFF: return "PLUGIN_OPTION_SEND_ALL_SOUND_OFF"; } carla_stderr("CarlaBackend::PluginOption2Str(%i) - invalid option", option); return nullptr; } // ----------------------------------------------------------------------- static inline const char* BinaryType2Str(const BinaryType type) { switch (type) { case BINARY_NONE: return "BINARY_NONE"; case BINARY_POSIX32: return "BINARY_POSIX32"; case BINARY_POSIX64: return "BINARY_POSIX64"; case BINARY_WIN32: return "BINARY_WIN32"; case BINARY_WIN64: return "BINARY_WIN64"; case BINARY_OTHER: return "BINARY_OTHER"; } carla_stderr("CarlaBackend::BinaryType2Str(%i) - invalid type", type); return nullptr; } static inline const char* PluginType2Str(const PluginType type) { switch (type) { case PLUGIN_NONE: return "PLUGIN_NONE"; case PLUGIN_INTERNAL: return "PLUGIN_INTERNAL"; case PLUGIN_LADSPA: return "PLUGIN_LADSPA"; case PLUGIN_DSSI: return "PLUGIN_DSSI"; case PLUGIN_LV2: return "PLUGIN_LV2"; case PLUGIN_VST: return "PLUGIN_VST"; case PLUGIN_AU: return "PLUGIN_AU"; case PLUGIN_CSOUND: return "PLUGIN_CSOUND"; case PLUGIN_GIG: return "PLUGIN_GIG"; case PLUGIN_SF2: return "PLUGIN_SF2"; case PLUGIN_SFZ: return "PLUGIN_SFZ"; } carla_stderr("CarlaBackend::PluginType2Str(%i) - invalid type", type); return nullptr; } static inline const char* PluginCategory2Str(const PluginCategory category) { switch (category) { case PLUGIN_CATEGORY_NONE: return "PLUGIN_CATEGORY_NONE"; case PLUGIN_CATEGORY_SYNTH: return "PLUGIN_CATEGORY_SYNTH"; case PLUGIN_CATEGORY_DELAY: return "PLUGIN_CATEGORY_DELAY"; case PLUGIN_CATEGORY_EQ: return "PLUGIN_CATEGORY_EQ"; case PLUGIN_CATEGORY_FILTER: return "PLUGIN_CATEGORY_FILTER"; case PLUGIN_CATEGORY_DISTORTION: return "PLUGIN_CATEGORY_DISTORTION"; case PLUGIN_CATEGORY_DYNAMICS: return "PLUGIN_CATEGORY_DYNAMICS"; case PLUGIN_CATEGORY_MODULATOR: return "PLUGIN_CATEGORY_MODULATOR"; case PLUGIN_CATEGORY_UTILITY: return "PLUGIN_CATEGORY_UTILITY"; case PLUGIN_CATEGORY_OTHER: return "PLUGIN_CATEGORY_OTHER"; } carla_stderr("CarlaBackend::PluginCategory2Str(%i) - invalid category", category); return nullptr; } static inline const char* InternalParameterIndex2Str(const InternalParameterIndex index) { switch (index) { case PARAMETER_NULL: return "PARAMETER_NULL"; case PARAMETER_ACTIVE: return "PARAMETER_ACTIVE"; case PARAMETER_DRYWET: return "PARAMETER_DRYWET"; case PARAMETER_VOLUME: return "PARAMETER_VOLUME"; case PARAMETER_BALANCE_LEFT: return "PARAMETER_BALANCE_LEFT"; case PARAMETER_BALANCE_RIGHT: return "PARAMETER_BALANCE_RIGHT"; case PARAMETER_PANNING: return "PARAMETER_PANNING"; case PARAMETER_CTRL_CHANNEL: return "PARAMETER_CTRL_CHANNEL"; case PARAMETER_MAX: return "PARAMETER_MAX"; } carla_stderr("CarlaBackend::InternalParameterIndex2Str(%i) - invalid index", index); return nullptr; } static inline const char* EngineCallbackOpcode2Str(const EngineCallbackOpcode opcode) { switch (opcode) { case ENGINE_CALLBACK_DEBUG: return "ENGINE_CALLBACK_DEBUG"; case ENGINE_CALLBACK_PLUGIN_ADDED: return "ENGINE_CALLBACK_PLUGIN_ADDED"; case ENGINE_CALLBACK_PLUGIN_REMOVED: return "ENGINE_CALLBACK_PLUGIN_REMOVED"; case ENGINE_CALLBACK_PLUGIN_RENAMED: return "ENGINE_CALLBACK_PLUGIN_RENAMED"; case ENGINE_CALLBACK_PLUGIN_UNAVAILABLE: return "ENGINE_CALLBACK_PLUGIN_UNAVAILABLE"; case ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED: return "ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED"; case ENGINE_CALLBACK_PARAMETER_DEFAULT_CHANGED: return "ENGINE_CALLBACK_PARAMETER_DEFAULT_CHANGED"; case ENGINE_CALLBACK_PARAMETER_MIDI_CHANNEL_CHANGED: return "ENGINE_CALLBACK_PARAMETER_MIDI_CHANNEL_CHANGED"; case ENGINE_CALLBACK_PARAMETER_MIDI_CC_CHANGED: return "ENGINE_CALLBACK_PARAMETER_MIDI_CC_CHANGED"; case ENGINE_CALLBACK_PROGRAM_CHANGED: return "ENGINE_CALLBACK_PROGRAM_CHANGED"; case ENGINE_CALLBACK_MIDI_PROGRAM_CHANGED: return "ENGINE_CALLBACK_MIDI_PROGRAM_CHANGED"; case ENGINE_CALLBACK_UI_STATE_CHANGED: return "ENGINE_CALLBACK_UI_STATE_CHANGED"; case ENGINE_CALLBACK_NOTE_ON: return "ENGINE_CALLBACK_NOTE_ON"; case ENGINE_CALLBACK_NOTE_OFF: return "ENGINE_CALLBACK_NOTE_OFF"; case ENGINE_CALLBACK_UPDATE: return "ENGINE_CALLBACK_UPDATE"; case ENGINE_CALLBACK_RELOAD_INFO: return "ENGINE_CALLBACK_RELOAD_INFO"; case ENGINE_CALLBACK_RELOAD_PARAMETERS: return "ENGINE_CALLBACK_RELOAD_PARAMETERS"; case ENGINE_CALLBACK_RELOAD_PROGRAMS: return "ENGINE_CALLBACK_RELOAD_PROGRAMS"; case ENGINE_CALLBACK_RELOAD_ALL: return "ENGINE_CALLBACK_RELOAD_ALL"; case ENGINE_CALLBACK_PATCHBAY_CLIENT_ADDED: return "ENGINE_CALLBACK_PATCHBAY_CLIENT_ADDED"; case ENGINE_CALLBACK_PATCHBAY_CLIENT_REMOVED: return "ENGINE_CALLBACK_PATCHBAY_CLIENT_REMOVED"; case ENGINE_CALLBACK_PATCHBAY_CLIENT_RENAMED: return "ENGINE_CALLBACK_PATCHBAY_CLIENT_RENAMED"; case ENGINE_CALLBACK_PATCHBAY_CLIENT_ICON_CHANGED: return "ENGINE_CALLBACK_PATCHBAY_CLIENT_ICON_CHANGED"; case ENGINE_CALLBACK_PATCHBAY_PORT_ADDED: return "ENGINE_CALLBACK_PATCHBAY_PORT_ADDED"; case ENGINE_CALLBACK_PATCHBAY_PORT_REMOVED: return "ENGINE_CALLBACK_PATCHBAY_PORT_REMOVED"; case ENGINE_CALLBACK_PATCHBAY_PORT_RENAMED: return "ENGINE_CALLBACK_PATCHBAY_PORT_RENAMED"; case ENGINE_CALLBACK_PATCHBAY_CONNECTION_ADDED: return "ENGINE_CALLBACK_PATCHBAY_CONNECTION_ADDED"; case ENGINE_CALLBACK_PATCHBAY_CONNECTION_REMOVED: return "ENGINE_CALLBACK_PATCHBAY_CONNECTION_REMOVED"; case ENGINE_CALLBACK_ENGINE_STARTED: return "ENGINE_CALLBACK_ENGINE_STARTED"; case ENGINE_CALLBACK_ENGINE_STOPPED: return "ENGINE_CALLBACK_ENGINE_STOPPED"; case ENGINE_CALLBACK_PROCESS_MODE_CHANGED: return "ENGINE_CALLBACK_PROCESS_MODE_CHANGED"; case ENGINE_CALLBACK_TRANSPORT_MODE_CHANGED: return "ENGINE_CALLBACK_TRANSPORT_MODE_CHANGED"; case ENGINE_CALLBACK_BUFFER_SIZE_CHANGED: return "ENGINE_CALLBACK_BUFFER_SIZE_CHANGED"; case ENGINE_CALLBACK_SAMPLE_RATE_CHANGED: return "ENGINE_CALLBACK_SAMPLE_RATE_CHANGED"; case ENGINE_CALLBACK_INFO: return "ENGINE_CALLBACK_INFO"; case ENGINE_CALLBACK_ERROR: return "ENGINE_CALLBACK_ERROR"; case ENGINE_CALLBACK_QUIT: return "ENGINE_CALLBACK_QUIT"; } carla_stderr("CarlaBackend::EngineCallbackOpcode2Str(%i) - invalid opcode", opcode); return nullptr; } static inline const char* EngineOption2Str(const EngineOption option) { switch (option) { case ENGINE_OPTION_DEBUG: return "ENGINE_OPTION_DEBUG"; case ENGINE_OPTION_PROCESS_MODE: return "ENGINE_OPTION_PROCESS_MODE"; case ENGINE_OPTION_TRANSPORT_MODE: return "ENGINE_OPTION_TRANSPORT_MODE"; case ENGINE_OPTION_FORCE_STEREO: return "ENGINE_OPTION_FORCE_STEREO"; case ENGINE_OPTION_PREFER_PLUGIN_BRIDGES: return "ENGINE_OPTION_PREFER_PLUGIN_BRIDGES"; case ENGINE_OPTION_PREFER_UI_BRIDGES: return "ENGINE_OPTION_PREFER_UI_BRIDGES"; case ENGINE_OPTION_UIS_ALWAYS_ON_TOP: return "ENGINE_OPTION_UIS_ALWAYS_ON_TOP"; case ENGINE_OPTION_MAX_PARAMETERS: return "ENGINE_OPTION_MAX_PARAMETERS"; case ENGINE_OPTION_UI_BRIDGES_TIMEOUT: return "ENGINE_OPTION_UI_BRIDGES_TIMEOUT"; case ENGINE_OPTION_AUDIO_NUM_PERIODS: return "ENGINE_OPTION_AUDIO_NUM_PERIODS"; case ENGINE_OPTION_AUDIO_BUFFER_SIZE: return "ENGINE_OPTION_AUDIO_BUFFER_SIZE"; case ENGINE_OPTION_AUDIO_SAMPLE_RATE: return "ENGINE_OPTION_AUDIO_SAMPLE_RATE"; case ENGINE_OPTION_AUDIO_DEVICE: return "ENGINE_OPTION_AUDIO_DEVICE"; case ENGINE_OPTION_PATH_BINARIES: return "ENGINE_OPTION_PATH_BINARIES"; case ENGINE_OPTION_PATH_RESOURCES: return "ENGINE_OPTION_PATH_RESOURCES"; } carla_stderr("CarlaBackend::EngineOption2Str(%i) - invalid option", option); return nullptr; } static inline const char* EngineProcessMode2Str(const EngineProcessMode mode) { switch (mode) { case ENGINE_PROCESS_MODE_SINGLE_CLIENT: return "ENGINE_PROCESS_MODE_SINGLE_CLIENT"; case ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS: return "ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS"; case ENGINE_PROCESS_MODE_CONTINUOUS_RACK: return "ENGINE_PROCESS_MODE_CONTINUOUS_RACK"; case ENGINE_PROCESS_MODE_PATCHBAY: return "ENGINE_PROCESS_MODE_PATCHBAY"; case ENGINE_PROCESS_MODE_BRIDGE: return "ENGINE_PROCESS_MODE_BRIDGE"; } carla_stderr("CarlaBackend::EngineProcessMode2Str(%i) - invalid mode", mode); return nullptr; } static inline const char* EngineTransportMode2Str(const EngineTransportMode mode) { switch (mode) { case ENGINE_TRANSPORT_MODE_INTERNAL: return "ENGINE_TRANSPORT_MODE_INTERNAL"; case ENGINE_TRANSPORT_MODE_JACK: return "ENGINE_TRANSPORT_MODE_JACK"; case ENGINE_TRANSPORT_MODE_PLUGIN: return "ENGINE_TRANSPORT_MODE_PLUGIN"; case ENGINE_TRANSPORT_MODE_BRIDGE: return "ENGINE_TRANSPORT_MODE_BRIDGE"; } carla_stderr("CarlaBackend::EngineTransportMode2Str(%i) - invalid mode", mode); return nullptr; } // ----------------------------------------------------------------------- static inline uintptr_t getAddressFromPointer(void* ptr) { CARLA_SAFE_ASSERT_RETURN(ptr != nullptr, 0); uintptr_t* const addr((uintptr_t*)&ptr); return *addr; } template static inline T* getPointerFromAddress(uintptr_t& addr) { CARLA_SAFE_ASSERT_RETURN(addr != 0, nullptr); T** const ptr((T**)&addr); return *ptr; } // ----------------------------------------------------------------------- static inline const char* getPluginTypeAsString(const PluginType type) { carla_debug("CarlaBackend::getPluginTypeAsString(%i:%s)", type, PluginType2Str(type)); switch (type) { case PLUGIN_NONE: return "NONE"; case PLUGIN_INTERNAL: return "INTERNAL"; case PLUGIN_LADSPA: return "LADSPA"; case PLUGIN_DSSI: return "DSSI"; case PLUGIN_LV2: return "LV2"; case PLUGIN_VST: return "VST"; case PLUGIN_AU: return "AU"; case PLUGIN_CSOUND: return "CSOUND"; case PLUGIN_GIG: return "GIG"; case PLUGIN_SF2: return "SF2"; case PLUGIN_SFZ: return "SFZ"; } carla_stderr("CarlaBackend::getPluginTypeAsString(%i) - invalid type", type); return "NONE"; } static inline PluginType getPluginTypeFromString(const char* const ctype) { CARLA_SAFE_ASSERT_RETURN(ctype != nullptr && ctype[0] != '\0', PLUGIN_NONE); carla_debug("CarlaBackend::getPluginTypeFromString(\"%s\")", ctype); CarlaString stype(ctype); stype.toLower(); if (stype.isEmpty() || stype == "none") return PLUGIN_NONE; if (stype == "internal") return PLUGIN_INTERNAL; if (stype == "ladspa") return PLUGIN_LADSPA; if (stype == "dssi") return PLUGIN_DSSI; if (stype == "lv2") return PLUGIN_LV2; if (stype == "vst") return PLUGIN_VST; if (stype == "au") return PLUGIN_AU; if (stype == "csound") return PLUGIN_CSOUND; if (stype == "gig") return PLUGIN_GIG; if (stype == "sf2") return PLUGIN_SF2; if (stype == "sfz") return PLUGIN_SFZ; carla_stderr("CarlaBackend::getPluginTypeFromString(\"%s\") - invalid string type", ctype); return PLUGIN_NONE; } // ----------------------------------------------------------------------- static inline PluginCategory getPluginCategoryFromName(const char* const name) { CARLA_SAFE_ASSERT_RETURN(name != nullptr && name[0] != '\0', PLUGIN_CATEGORY_NONE); carla_debug("CarlaBackend::getPluginCategoryFromName(\"%s\")", name); CarlaString sname(name); if (sname.isEmpty()) return PLUGIN_CATEGORY_NONE; sname.toLower(); // generic tags first if (sname.contains("delay")) return PLUGIN_CATEGORY_DELAY; if (sname.contains("reverb")) return PLUGIN_CATEGORY_DELAY; // filter if (sname.contains("filter")) return PLUGIN_CATEGORY_FILTER; // distortion if (sname.contains("distortion")) return PLUGIN_CATEGORY_DISTORTION; // dynamics if (sname.contains("dynamics")) return PLUGIN_CATEGORY_DYNAMICS; if (sname.contains("amplifier")) return PLUGIN_CATEGORY_DYNAMICS; if (sname.contains("compressor")) return PLUGIN_CATEGORY_DYNAMICS; if (sname.contains("enhancer")) return PLUGIN_CATEGORY_DYNAMICS; if (sname.contains("exciter")) return PLUGIN_CATEGORY_DYNAMICS; if (sname.contains("gate")) return PLUGIN_CATEGORY_DYNAMICS; if (sname.contains("limiter")) return PLUGIN_CATEGORY_DYNAMICS; // modulator if (sname.contains("modulator")) return PLUGIN_CATEGORY_MODULATOR; if (sname.contains("chorus")) return PLUGIN_CATEGORY_MODULATOR; if (sname.contains("flanger")) return PLUGIN_CATEGORY_MODULATOR; if (sname.contains("phaser")) return PLUGIN_CATEGORY_MODULATOR; if (sname.contains("saturator")) return PLUGIN_CATEGORY_MODULATOR; // utility if (sname.contains("utility")) return PLUGIN_CATEGORY_UTILITY; if (sname.contains("analyzer")) return PLUGIN_CATEGORY_UTILITY; if (sname.contains("converter")) return PLUGIN_CATEGORY_UTILITY; if (sname.contains("deesser")) return PLUGIN_CATEGORY_UTILITY; if (sname.contains("mixer")) return PLUGIN_CATEGORY_UTILITY; // common tags if (sname.contains("verb")) return PLUGIN_CATEGORY_DELAY; if (sname.contains("eq")) return PLUGIN_CATEGORY_EQ; if (sname.contains("tool")) return PLUGIN_CATEGORY_UTILITY; return PLUGIN_CATEGORY_NONE; } // ----------------------------------------------------------------------- CARLA_BACKEND_END_NAMESPACE #endif // CARLA_BACKEND_UTILS_HPP_INCLUDED