gearmulator

Emulation of classic VA synths of the late 90s/2000s that are based on Motorola 56300 family DSPs
Log | Files | Refs | Submodules | README | LICENSE

commit 038bc5719df9ad1947ca7e2fab926678aa7dcf8f
parent 41a9ff2c701dfdb737e761761167ffb41ae68bc4
Author: dsp56300 <dsp56300@users.noreply.github.com>
Date:   Thu, 30 May 2024 13:37:41 +0200

move text operations to separate clipboard class

Diffstat:
Msource/jucePluginEditorLib/patchmanager/patchmanager.cpp | 67+++----------------------------------------------------------------
Msource/jucePluginLib/CMakeLists.txt | 1+
Asource/jucePluginLib/clipboard.cpp | 85+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asource/jucePluginLib/clipboard.h | 15+++++++++++++++
4 files changed, 104 insertions(+), 64 deletions(-)

diff --git a/source/jucePluginEditorLib/patchmanager/patchmanager.cpp b/source/jucePluginEditorLib/patchmanager/patchmanager.cpp @@ -13,6 +13,7 @@ #include "../pluginEditor.h" #include "../../jucePluginLib/types.h" +#include "../../jucePluginLib/clipboard.h" #include "../../synthLib/os.h" @@ -879,52 +880,7 @@ namespace jucePluginEditorLib::patchManager std::vector<pluginLib::patchDB::PatchPtr> PatchManager::getPatchesFromString(const std::string& _text) { - if(_text.empty()) - return {}; - - auto text = synthLib::lowercase(_text); - - while(true) - { - const auto pos = text.find_first_of(" \n\r\t"); - if(pos == std::string::npos) - break; - text = text.substr(0,pos) + text.substr(pos+1); - } - - const auto posF0 = text.find("f0"); - if(posF0 == std::string::npos) - return {}; - - const auto posF7 = text.rfind("f7"); - if(posF7 == std::string::npos) - return {}; - - if(posF7 <= posF0) - return {}; - - const auto dataString = text.substr(posF0, posF7 + 2 - posF0); - - if(dataString.size() & 1) - return {}; - - std::vector<uint8_t> data; - data.reserve(dataString.size()>>1); - - for(size_t i=0; i<dataString.size(); i+=2) - { - char temp[3]{0,0,0}; - temp[0] = dataString[i]; - temp[1] = dataString[i+1]; - - const auto c = strtoul(temp, nullptr, 16); - if(c < 0 || c > 255) - return {}; - data.push_back(static_cast<uint8_t>(c)); - } - - pluginLib::patchDB::DataList results; - parseFileData(results, data); + pluginLib::patchDB::DataList results = pluginLib::Clipboard::getSysexFromString(_text); if(results.empty()) return {}; @@ -967,23 +923,6 @@ namespace jucePluginEditorLib::patchManager const auto data = prepareSave(_patch); - if(data.empty()) - return {}; - - std::stringstream ss; - - for(size_t i=0; i<data.size();) - { - if(i) - ss << '\n'; - for(size_t j=0; j<_bytesPerLine && i<data.size(); ++j, ++i) - { - if(j) - ss << ' '; - ss << HEXN(static_cast<uint32_t>(data[i]), 2); - } - } - - return ss.str(); + return pluginLib::Clipboard::midiDataToString(data, _bytesPerLine); } } diff --git a/source/jucePluginLib/CMakeLists.txt b/source/jucePluginLib/CMakeLists.txt @@ -5,6 +5,7 @@ configure_file(${CMAKE_CURRENT_LIST_DIR}/version.h.in ${CMAKE_CURRENT_LIST_DIR}/ set(SOURCES createVersionDateTime.cmake + clipboard.cpp clipboard.h controller.cpp controller.h dummydevice.cpp dummydevice.h event.cpp event.h diff --git a/source/jucePluginLib/clipboard.cpp b/source/jucePluginLib/clipboard.cpp @@ -0,0 +1,85 @@ +#include "clipboard.h" + +#include "../synthLib/midiToSysex.h" +#include "../synthLib/os.h" + +#include <sstream> + +#include "dsp56kEmu/logging.h" + +namespace pluginLib +{ + std::string Clipboard::midiDataToString(const std::vector<uint8_t>& _data, const uint32_t _bytesPerLine/* = 32*/) + { + if(_data.empty()) + return {}; + + std::stringstream ss; + + for(size_t i=0; i<_data.size();) + { + if(i) + ss << '\n'; + for(size_t j=0; j<_bytesPerLine && i<_data.size(); ++j, ++i) + { + if(j) + ss << ' '; + ss << HEXN(static_cast<uint32_t>(_data[i]), 2); + } + } + + return ss.str(); + } + + std::vector<std::vector<uint8_t>> Clipboard::getSysexFromString(const std::string& _text) + { + if(_text.empty()) + return {}; + + auto text = synthLib::lowercase(_text); + + while(true) + { + const auto pos = text.find_first_of(" \n\r\t"); + if(pos == std::string::npos) + break; + text = text.substr(0,pos) + text.substr(pos+1); + } + + const auto posF0 = text.find("f0"); + if(posF0 == std::string::npos) + return {}; + + const auto posF7 = text.rfind("f7"); + if(posF7 == std::string::npos) + return {}; + + if(posF7 <= posF0) + return {}; + + const auto dataString = text.substr(posF0, posF7 + 2 - posF0); + + if(dataString.size() & 1) + return {}; + + std::vector<uint8_t> data; + data.reserve(dataString.size()>>1); + + for(size_t i=0; i<dataString.size(); i+=2) + { + char temp[3]{0,0,0}; + temp[0] = dataString[i]; + temp[1] = dataString[i+1]; + + const auto c = strtoul(temp, nullptr, 16); + if(c < 0 || c > 255) + return {}; + data.push_back(static_cast<uint8_t>(c)); + } + + std::vector<std::vector<uint8_t>> results; + synthLib::MidiToSysex::extractSysexFromData(results, data); + + return results; + } +} diff --git a/source/jucePluginLib/clipboard.h b/source/jucePluginLib/clipboard.h @@ -0,0 +1,15 @@ +#pragma once + +#include <cstdint> +#include <string> +#include <vector> + +namespace pluginLib +{ + class Clipboard + { + public: + static std::string midiDataToString(const std::vector<uint8_t>& _data, uint32_t _bytesPerLine = 32); + static std::vector<std::vector<uint8_t>> getSysexFromString(const std::string& _text); + }; +}