diff --git a/plugin/components/ide_view.cpp b/plugin/components/ide_view.cpp index c26bb50..28e0a65 100644 --- a/plugin/components/ide_view.cpp +++ b/plugin/components/ide_view.cpp @@ -24,7 +24,7 @@ class YSFXCodeEditor : public juce::CodeEditorComponent { public: - YSFXCodeEditor(juce::CodeDocument& document, juce::CodeTokeniser* codeTokeniser, std::function keyPressCallback): CodeEditorComponent(document, codeTokeniser), m_keyPressCallback{keyPressCallback} {}; + YSFXCodeEditor(juce::CodeDocument& doc, juce::CodeTokeniser* tokenizer, std::function keyPressCallback): CodeEditorComponent(doc, tokenizer), m_keyPressCallback{keyPressCallback} {} bool keyPressed(const juce::KeyPress &key) override { diff --git a/plugin/components/parameters_panel.cpp b/plugin/components/parameters_panel.cpp index 2013d1d..7fa4626 100644 --- a/plugin/components/parameters_panel.cpp +++ b/plugin/components/parameters_panel.cpp @@ -15,6 +15,7 @@ // SPDX-License-Identifier: Apache-2.0 // +#include #include "lookandfeel.h" #include "parameters_panel.h" #include "../parameter.h" @@ -115,7 +116,7 @@ class YsfxBooleanParameterComponent final : public juce::Component, private Ysfx bool isParameterOn() const { - return getParameter().getValue() != 0.0f; + return getParameter().getValue() > 0.00001f; /* Same threshold used in JSFX */ } juce::ToggleButton button; @@ -187,7 +188,7 @@ class YsfxSwitchParameterComponent final : public juce::Component, private YsfxP bool isParameterOn() const { - return getParameter().getValue() != 0.0f; + return getParameter().getValue() > 0.00001f; /* Same threshold used in JSFX */ } juce::TextButton buttons[2]; @@ -332,7 +333,7 @@ class YsfxSliderParameterComponent final : public juce::Component, private YsfxP { auto newVal = (float)slider.getValue(); - if (getParameter().getValue() != newVal) { + if (std::abs(getParameter().getValue() - newVal) > 1e-12) { if (!isDragging) getParameter().beginChangeGesture(); @@ -362,12 +363,10 @@ class YsfxSliderParameterComponent final : public juce::Component, private YsfxP const auto charptr = textValue.getCharPointer(); auto ptr = charptr; auto newVal = juce::CharacterFunctions::readDoubleValue(ptr); - size_t chars_read = ptr - charptr; + size_t chars_read = static_cast(ptr - charptr); if (chars_read == textValue.getNumBytesAsUTF8()) { - if (getParameter().getValue() != newVal) { - getParameter().setValueNotifyingHost(getParameter().convertFromYsfxValue(newVal)); - } + getParameter().setValueNotifyingHost(getParameter().convertFromYsfxValue(newVal)); } else { updateTextDisplay(); } diff --git a/plugin/components/rpl_view.cpp b/plugin/components/rpl_view.cpp index 989f3a3..744d6c3 100644 --- a/plugin/components/rpl_view.cpp +++ b/plugin/components/rpl_view.cpp @@ -37,19 +37,19 @@ class BankItemsListBoxModel final : public juce::ListBox, public juce::ListBoxMo m_items = items; } - void setDropCallback(std::function, juce::WeakReference)> dropCallback) { + void setDropCallback(std::function, juce::WeakReference)> dropCallback) { m_dropCallback = dropCallback; } - void setDeleteCallback(std::function)> deleteCallback) { + void setDeleteCallback(std::function)> deleteCallback) { m_deleteCallback = deleteCallback; } - void setDoubleClickCallback(std::function dblClickCallback) { + void setDoubleClickCallback(std::function dblClickCallback) { m_dblClickCallback = dblClickCallback; } - void setRenameCallback(std::function renameCallback) { + void setRenameCallback(std::function renameCallback) { m_renameCallback = renameCallback; } @@ -59,8 +59,8 @@ class BankItemsListBoxModel final : public juce::ListBox, public juce::ListBoxMo std::vector m_items; std::function m_renameCallback; std::function m_dblClickCallback; - std::function, juce::WeakReference)> m_dropCallback; - std::function)> m_deleteCallback; + std::function, juce::WeakReference)> m_dropCallback; + std::function)> m_deleteCallback; int getNumRows() override { @@ -69,15 +69,17 @@ class BankItemsListBoxModel final : public juce::ListBox, public juce::ListBoxMo void paintListBoxItem (int rowNumber, juce::Graphics& g, int width, int height, bool rowIsSelected) override { + if (rowNumber < 0) return; + if (rowIsSelected) g.fillAll (juce::Colours::lightblue); g.setColour(juce::LookAndFeel::getDefaultLookAndFeel().findColour(juce::Label::textColourId)); g.setFont((float) height * 0.7f); - g.drawText(m_items[rowNumber], 5, 0, width, height, juce::Justification::centredLeft, true); + g.drawText(m_items[static_cast(rowNumber)], 5, 0, width, height, juce::Justification::centredLeft, true); } - juce::var getDragSourceDescription(const juce::SparseSet& selectedRows) + juce::var getDragSourceDescription(const juce::SparseSet& selectedRows) override { juce::Array juceArray; for (int i = 0; i < selectedRows.size(); ++i) @@ -112,7 +114,8 @@ class BankItemsListBoxModel final : public juce::ListBox, public juce::ListBoxMo return; juce::Array *payload = dragSourceDetails.description.getArray(); - std::vector elements{(*payload).begin(), (*payload).end()}; + std::vector elements; + for (const auto& value : *payload) elements.push_back(static_cast(static_cast(value))); if (!elements.empty()) { m_dropCallback(elements, dragSourceDetails.sourceComponent); @@ -123,10 +126,10 @@ class BankItemsListBoxModel final : public juce::ListBox, public juce::ListBoxMo { (void) arg; - std::vector elements; + std::vector elements; auto selection = getSelectedRows(); for (int i = 0; i < selection.size(); ++i) - elements.push_back(selection[i]); + elements.push_back(static_cast(selection[i])); if (!elements.empty()) { m_deleteCallback(elements); @@ -224,7 +227,7 @@ class LoadedBank : public juce::Component, public juce::DragAndDropContainer { return m_bank; } - void transferPresets(std::vector indices, juce::WeakReference ref) + void transferPresets(std::vector indices, juce::WeakReference ref) { if (!m_bank) return; @@ -237,13 +240,13 @@ class LoadedBank : public juce::Component, public juce::DragAndDropContainer { transferPresetRecursive(indices, src_bank, false); } - void deletePresets(std::vector indices) + void deletePresets(std::vector indices) { if (!m_bank) return; // Grab the names first. std::vector names; - for (uint32_t idx : indices) + for (auto idx : indices) { if (idx < m_bank->preset_count) { names.push_back(std::string(m_bank->presets[idx].name)); @@ -316,8 +319,8 @@ class LoadedBank : public juce::Component, public juce::DragAndDropContainer { addAndMakeVisible(*m_btnLoadFile); } m_listBox->setOutlineThickness(1); - m_listBox->setDropCallback([this](std::vector indices, juce::WeakReference ref) { this->transferPresets(indices, ref); }); - m_listBox->setDeleteCallback([this](std::vector indices) { this->deletePresets(indices); }); + m_listBox->setDropCallback([this](std::vector indices, juce::WeakReference ref) { this->transferPresets(indices, ref); }); + m_listBox->setDeleteCallback([this](std::vector indices) { this->deletePresets(indices); }); m_listBox->setRenameCallback([this](int row) { this->renamePreset(row); }); m_listBox->setDoubleClickCallback([this](int idx) { if (m_loadPresetCallback) m_loadPresetCallback(std::string{m_bank->presets[idx].name}); }); addAndMakeVisible(*m_listBox); @@ -372,9 +375,9 @@ class LoadedBank : public juce::Component, public juce::DragAndDropContainer { private: std::unique_ptr m_confirmDialog; - void transferPresetRecursive(std::vector indices, ysfx_bank_shared src_bank, bool force_accept) + void transferPresetRecursive(std::vector indices, ysfx_bank_shared src_bank, bool force_accept) { - uint32_t idx = indices.back(); + auto idx = indices.back(); indices.pop_back(); auto copy_lambda = [this, indices, src_bank, idx, force_accept](int result){ diff --git a/plugin/components/searchable_popup.h b/plugin/components/searchable_popup.h index 7df4dac..17e0877 100644 --- a/plugin/components/searchable_popup.h +++ b/plugin/components/searchable_popup.h @@ -86,7 +86,7 @@ { juce::Label search_label; juce::TextEditor editor; - PopupMenuQuickSearch* owner; + PopupMenuQuickSearch* m_owner; // the hierarchy of submenus in the PopupMenu (used when disambiguating duplicated label) struct MenuTree @@ -120,7 +120,7 @@ QuickSearchItem e; bool m_highlighted = false; PopupMenuQuickSearch* m_owner; - MenuItemComponent (PopupMenuQuickSearch* owner) : m_owner (owner) {} + MenuItemComponent (PopupMenuQuickSearch* owner) : m_owner(owner) {} void paint (juce::Graphics& g) override { getLookAndFeel().drawPopupMenuItem ( @@ -159,9 +159,9 @@ float m_scaleFactor{1.0f}; public: - QuickSearchComponent (PopupMenuQuickSearch* owner, juce::String& initial_string, float scale_factor) : owner (owner), m_scaleFactor(scale_factor) + QuickSearchComponent (PopupMenuQuickSearch* owner, juce::String& initial_string, float scale_factor) : m_owner(owner), m_scaleFactor(scale_factor) { - jassert(owner->target_component_weak_ref.get()); + jassert(m_owner->target_component_weak_ref.get()); auto target_screen_area = getTargetScreenArea(); setOpaque (true); @@ -171,7 +171,7 @@ setAlwaysOnTop (true); creation_time = juce::Time::getCurrentTime(); - readPopupMenuItems (menu_tree, owner->menu); + readPopupMenuItems (menu_tree, m_owner->menu); handleDuplicatedLabels(); /* compute the width and item height */ @@ -181,7 +181,7 @@ if (q.label.length() > longest_string.length()) longest_string = q.label; } - getLookAndFeel().getIdealPopupMenuItemSize (longest_string, false /* isSeparator */, owner->options.getStandardItemHeight(), item_width, item_height); + getLookAndFeel().getIdealPopupMenuItemSize (longest_string, false /* isSeparator */, m_owner->options.getStandardItemHeight(), item_width, item_height); if (item_width < target_screen_area.getWidth() && target_screen_area.getWidth() < 300) { @@ -230,7 +230,7 @@ } juce::Rectangle getTargetScreenArea() { - auto target_screen_area = owner->options.getTargetScreenArea(); + auto target_screen_area = m_owner->options.getTargetScreenArea(); target_screen_area.setX((int) (target_screen_area.getX() / m_scaleFactor)); target_screen_area.setY((int) (target_screen_area.getY() / m_scaleFactor)); return target_screen_area; @@ -261,8 +261,8 @@ q.label = item.text; q.menu = &tree; q.popup_menu_item = &item; - auto it = owner->options.itemsToIgnoreOrRenameInQuickSearch.find (q.id); - if (it != owner->options.itemsToIgnoreOrRenameInQuickSearch.end()) + auto it = m_owner->options.itemsToIgnoreOrRenameInQuickSearch.find (q.id); + if (it != m_owner->options.itemsToIgnoreOrRenameInQuickSearch.end()) { q.label = it->second; // the label is renamed, or just set to empty string if we want to // ignore this entry. @@ -276,7 +276,7 @@ void handleDuplicatedLabels() { - if (! owner->options.mergeEntriesWithSameLabel) + if (!m_owner->options.mergeEntriesWithSameLabel) { // use name of parent menu to disambiguate duplicates std::vector parents (quick_search_items.size()); @@ -380,7 +380,7 @@ updateMatches(); int nb_visible_matches = - std::min (owner->options.maxNumberOfMatchesDisplayed, (int) matches.size()); + std::min (m_owner->options.maxNumberOfMatchesDisplayed, (int) matches.size()); int h = item_height; jassert (h); @@ -409,16 +409,17 @@ editor.setBounds (editor.getX(), total_h - h, editor.getWidth(), h); } - best_items.resize (nb_visible_matches); - for (size_t i = 0; i < nb_visible_matches; ++i) + size_t best_item_size = static_cast(nb_visible_matches); + best_items.resize(best_item_size); + for (size_t i = 0; i < best_item_size; ++i) { if (best_items.at (i) == nullptr) { - best_items[i] = std::make_unique (owner); + best_items[i] = std::make_unique(m_owner); addAndMakeVisible (*best_items[i]); } - size_t ii = first_displayed_match + i; - best_items[i]->updateWith (quick_search_items.at (matches.at (ii)), ii == highlighted_match); + size_t ii = static_cast(first_displayed_match) + i; + best_items[i]->updateWith (quick_search_items.at (matches.at (ii)), ii == static_cast(highlighted_match)); if (displayed_over_or_under == 1) { best_items[i]->setBounds (0, (h + separator_height) + (int) i * h, item_width, h); @@ -534,15 +535,16 @@ { if (! matches.empty()) { - auto& q = quick_search_items.at (matches.at (highlighted_match)); + jassert(highlighted_match >= 0); + auto& q = quick_search_items.at (matches.at(static_cast(highlighted_match))); if (q.popup_menu_item->isEnabled) { - owner->quickSearchFinished (q.id); + m_owner->quickSearchFinished (q.id); } } } - void textEditorEscapeKeyPressed (juce::TextEditor&) override { owner->quickSearchFinished (0); } + void textEditorEscapeKeyPressed (juce::TextEditor&) override { m_owner->quickSearchFinished (0); } void textEditorTextChanged (juce::TextEditor&) override { updateContent(); } @@ -555,7 +557,7 @@ if (key == '\t') { // async because it will destroy the QuickSearchComponent and this is causing issues if done in the keyPressed callback - juce::MessageManager::getInstance()->callAsync([this, ref=juce::WeakReference(this)]() { if (ref) { owner->showPopupMenu(); } }); + juce::MessageManager::getInstance()->callAsync([this, ref=juce::WeakReference(this)]() { if (ref) { m_owner->showPopupMenu(); } }); } bool up = (key == juce::KeyPress::upKey), down = (key == juce::KeyPress::downKey); @@ -582,7 +584,8 @@ first_displayed_match = highlighted_match - (int) best_items.size() + 1; jassert (first_displayed_match >= 0); } - auto& q = quick_search_items.at (matches.at (highlighted_match)); + jassert(highlighted_match >= 0); + auto& q = quick_search_items.at (matches.at(static_cast(highlighted_match))); if (! q.popup_menu_item->isEnabled) highlighted_match = 0; updateContent(); @@ -606,7 +609,7 @@ double dt = (juce::Time::getCurrentTime() - creation_time).inSeconds(); if (dt > 0.2) { - owner->quickSearchFinished (0); + m_owner->quickSearchFinished (0); } } diff --git a/plugin/components/tokenizer.h b/plugin/components/tokenizer.h index 4ec0b54..5b6fbc4 100644 --- a/plugin/components/tokenizer.h +++ b/plugin/components/tokenizer.h @@ -31,6 +31,6 @@ class JSFXTokenizer : public juce::CPlusPlusCodeTokeniser }; private: - int readNextToken(juce::CodeDocument::Iterator& source); + int readNextToken(juce::CodeDocument::Iterator& source) override; juce::CodeEditorComponent::ColourScheme m_colourScheme; }; diff --git a/plugin/editor.cpp b/plugin/editor.cpp index 10d04f7..3ddeb04 100644 --- a/plugin/editor.cpp +++ b/plugin/editor.cpp @@ -34,6 +34,8 @@ #include "ysfx.h" #include #include "json.hpp" +#include +#include struct YsfxEditor::Impl { YsfxEditor *m_self = nullptr; @@ -188,8 +190,8 @@ void YsfxEditor::readTheme() setColors(getLookAndFeel(), getDefaultColors()); setParams(getLookAndFeel(), getDefaultParams()); m_impl->m_ideView->setColourScheme(getDefaultColors()); - } catch (nlohmann::json::exception e) { - // Log: std::cout << "Failed to write theme: " << e.what() << std::endl; + } catch (const nlohmann::json::exception& e) { + std::cerr << "Failed to write theme: " << e.what() << std::endl; } } else { juce::FileInputStream stream(file); @@ -218,8 +220,8 @@ void YsfxEditor::readTheme() setParams(getLookAndFeel(), readParams); m_impl->m_ideView->setColourScheme(readTheme); writeThemeFile(file, readTheme, readParams); - } catch (nlohmann::json::exception e) { - // Log: std::cout << "Failed to read theme: " << e.what() << std::endl; + } catch (const nlohmann::json::exception& e) { + std::cerr << "Failed to read theme: " << e.what() << std::endl; } } } @@ -308,7 +310,7 @@ void YsfxEditor::Impl::grabInfoAndUpdate() YsfxCurrentPresetInfo::Ptr presetInfo = m_proc->getCurrentPresetInfo(); ysfx_bank_shared bank = m_proc->getCurrentBank(); - if (m_graphicsView->getTotalScaling() != m_currentScaling) { + if (std::abs(m_graphicsView->getTotalScaling() - m_currentScaling) > 1e-6) { relayoutUILater(); m_currentScaling = m_graphicsView->getTotalScaling(); } @@ -414,13 +416,13 @@ void YsfxEditor::Impl::updateInfo() ); m_rplView->setLoadPresetCallback( [this](std::string preset) { - YsfxInfo::Ptr info = m_info; + YsfxInfo::Ptr ysfx_info = m_info; ysfx_bank_shared bank = m_bank; if (!bank) return; auto index = ysfx_preset_exists(bank.get(), preset.c_str()); if (index > 0) { - m_proc->loadJsfxPreset(info, bank, (uint32_t)(index - 1), PresetLoadMode::load, true); + m_proc->loadJsfxPreset(ysfx_info, bank, (uint32_t)(index - 1), PresetLoadMode::load, true); } } ); @@ -430,8 +432,8 @@ void YsfxEditor::Impl::updateInfo() juce::File file{juce::CharPointer_UTF8{ysfx_get_file_path(fx)}}; m_mustResizeToGfx = true; + loadScaling(); - relayoutUILater(); } @@ -631,10 +633,10 @@ void YsfxEditor::Impl::popupRecentOpts() if (index == 1000) { clearRecentFiles(); } else if (index != 0) { - juce::RecentlyOpenedFilesList recent = loadRecentFiles(); - juce::File file = recent.getFile(index - 100); - recent.removeFile(file); - saveRecentFiles(recent); + juce::RecentlyOpenedFilesList recent_files = loadRecentFiles(); + juce::File file = recent_files.getFile(index - 100); + recent_files.removeFile(file); + saveRecentFiles(recent_files); } }); } @@ -1108,7 +1110,8 @@ void YsfxEditor::Impl::relayoutUI() if (m_btnSwitchEditor->getToggleState() && (fx && ysfx_has_section(fx, ysfx_section_gfx))) { int maxParamArea = m_self->getHeight(); maxParamArea -= nonParameterSpace; - m_divider->setSizes(std::min(parameterHeight, std::max(200, maxParamArea)), 0, m_miniParametersPanel->getRecommendedHeight(0)); + auto recommended = m_miniParametersPanel->getRecommendedHeight(0); + m_divider->setSizes(std::min(parameterHeight, std::max(200, maxParamArea)), recommended > 0 ? 5 : 0, recommended); const juce::Rectangle paramArea = centerArea.withHeight(m_divider->m_position); const juce::Rectangle gfxArea = centerArea.withTrimmedTop(m_divider->m_position); diff --git a/plugin/editor.h b/plugin/editor.h index 5de698f..a75db0e 100644 --- a/plugin/editor.h +++ b/plugin/editor.h @@ -38,3 +38,5 @@ class YsfxEditor : public juce::AudioProcessorEditor, public juce::FileDragAndDr struct Impl; std::unique_ptr m_impl; }; + +void writeThemeFile(juce::File file, std::map> colors, std::map params); diff --git a/plugin/lookandfeel.cpp b/plugin/lookandfeel.cpp index 879174c..7995929 100644 --- a/plugin/lookandfeel.cpp +++ b/plugin/lookandfeel.cpp @@ -101,7 +101,7 @@ void setColors(juce::LookAndFeel& lnf, std::mapsecond[0]), int(it->second[1]), int(it->second[2])); + return juce::Colour(juce::uint8{it->second[0]}, juce::uint8{it->second[1]}, juce::uint8{it->second[2]}); } else { return juce::Colour(255, 200, 200); } diff --git a/plugin/parameter.cpp b/plugin/parameter.cpp index 6189812..a93b80e 100644 --- a/plugin/parameter.cpp +++ b/plugin/parameter.cpp @@ -16,6 +16,7 @@ // #include "parameter.h" +#include YsfxParameter::YsfxParameter(ysfx_t *fx, int sliderIndex) : RangedAudioParameter( @@ -36,7 +37,7 @@ void YsfxParameter::setEffect(ysfx_t *fx) ysfx_add_ref(fx); { juce::ScopedLock nameLock(m_nameSection); - m_displayName = juce::String(ysfx_slider_get_name(fx, m_sliderIndex)); + m_displayName = juce::String(ysfx_slider_get_name(fx, static_cast(m_sliderIndex))); } } } @@ -97,7 +98,7 @@ ysfx_real YsfxParameter::convertToYsfxValue(float normValue) const float YsfxParameter::convertFromYsfxValue(ysfx_real actualValue) const { ysfx_slider_curve_t curve = getSliderCurve(); - if (curve.min == curve.max) + if (std::abs(curve.max - curve.min) < 1e-12) return 0.0f; // NOTE: if enumerated, round value into an index @@ -170,7 +171,6 @@ juce::String YsfxParameter::getText(float normalisedValue, int) const float YsfxParameter::getValueForText(const juce::String &text) const { - ysfx_slider_range_t range = getSliderRange(); ysfx_real actualValue{}; bool foundEnum = false; diff --git a/plugin/processor.cpp b/plugin/processor.cpp index c67a72f..1400aeb 100644 --- a/plugin/processor.cpp +++ b/plugin/processor.cpp @@ -28,6 +28,7 @@ #include #include #include +#include struct YsfxProcessor::Impl : public juce::AudioProcessorListener { YsfxProcessor *m_self = nullptr; @@ -409,9 +410,7 @@ void YsfxProcessor::cyclePreset(int direction) // Look up current preset or default to last (since we consider it new) auto currentPreset = m_impl->m_currentPresetInfo->m_lastChosenPreset; auto bank = m_impl->m_bank.get(); - auto max_preset = bank->preset_count; - - if (max_preset < 1) return; + if (bank->preset_count < 1) return; uint32_t preset_index; if (currentPreset.isEmpty()) { @@ -423,14 +422,15 @@ void YsfxProcessor::cyclePreset(int direction) } } + int preset_count = static_cast(bank->preset_count); int next_preset = static_cast(preset_index) + direction; if (next_preset < 0) { - next_preset = bank->preset_count - 1; - } else if (next_preset >= static_cast(bank->preset_count)) { + next_preset = preset_count - 1; + } else if (next_preset >= preset_count) { next_preset = 0; } - loadJsfxPreset(m_impl->m_info, m_impl->m_bank, next_preset, PresetLoadMode::load, true); + loadJsfxPreset(m_impl->m_info, m_impl->m_bank, static_cast(next_preset), PresetLoadMode::load, true); } YsfxInfo::Ptr YsfxProcessor::getCurrentInfo() @@ -728,7 +728,7 @@ void YsfxProcessor::Impl::processSliderChanges() YsfxParameter *param = m_self->getYsfxParameter(i); if (param->existsAsSlider()) { float normValue = param->convertFromYsfxValue(ysfx_slider_get_value(fx, (uint32_t)i)); - if (param->getValue() != normValue) { + if (std::abs(param->getValue() - normValue) > 1e-9) { param->setValueNoNotify(normValue); // This should not trigger @slider } }