Skip to content

Commit

Permalink
plugin: clean up some warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
JoepVanlier committed Dec 15, 2024
1 parent a5bdc23 commit 446f08f
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 62 deletions.
2 changes: 1 addition & 1 deletion plugin/components/ide_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
class YSFXCodeEditor : public juce::CodeEditorComponent
{
public:
YSFXCodeEditor(juce::CodeDocument& document, juce::CodeTokeniser* codeTokeniser, std::function<bool(const juce::KeyPress&)> keyPressCallback): CodeEditorComponent(document, codeTokeniser), m_keyPressCallback{keyPressCallback} {};
YSFXCodeEditor(juce::CodeDocument& doc, juce::CodeTokeniser* tokenizer, std::function<bool(const juce::KeyPress&)> keyPressCallback): CodeEditorComponent(doc, tokenizer), m_keyPressCallback{keyPressCallback} {}

bool keyPressed(const juce::KeyPress &key) override
{
Expand Down
10 changes: 4 additions & 6 deletions plugin/components/parameters_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,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;
Expand Down Expand Up @@ -187,7 +187,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];
Expand Down Expand Up @@ -362,12 +362,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<size_t>(ptr - charptr);

if (chars_read == textValue.getNumBytesAsUTF8()) {
if (getParameter().getValue() != newVal) {
getParameter().setValueNotifyingHost(getParameter().convertFromYsfxValue(newVal));
}
getParameter().setValueNotifyingHost(getParameter().convertFromYsfxValue(newVal));
} else {
updateTextDisplay();
}
Expand Down
39 changes: 21 additions & 18 deletions plugin/components/rpl_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,19 @@ class BankItemsListBoxModel final : public juce::ListBox, public juce::ListBoxMo
m_items = items;
}

void setDropCallback(std::function<void(std::vector<int>, juce::WeakReference<juce::Component>)> dropCallback) {
void setDropCallback(std::function<void(std::vector<uint32_t>, juce::WeakReference<juce::Component>)> dropCallback) {
m_dropCallback = dropCallback;
}

void setDeleteCallback(std::function<void(std::vector<int>)> deleteCallback) {
void setDeleteCallback(std::function<void(std::vector<uint32_t>)> deleteCallback) {
m_deleteCallback = deleteCallback;
}

void setDoubleClickCallback(std::function<void(int)> dblClickCallback) {
void setDoubleClickCallback(std::function<void(uint32_t)> dblClickCallback) {
m_dblClickCallback = dblClickCallback;
}

void setRenameCallback(std::function<void(int)> renameCallback) {
void setRenameCallback(std::function<void(uint32_t)> renameCallback) {
m_renameCallback = renameCallback;
}

Expand All @@ -59,8 +59,8 @@ class BankItemsListBoxModel final : public juce::ListBox, public juce::ListBoxMo
std::vector<juce::String> m_items;
std::function<void(int)> m_renameCallback;
std::function<void(int)> m_dblClickCallback;
std::function<void(std::vector<int>, juce::WeakReference<juce::Component>)> m_dropCallback;
std::function<void(std::vector<int>)> m_deleteCallback;
std::function<void(std::vector<uint32_t>, juce::WeakReference<juce::Component>)> m_dropCallback;
std::function<void(std::vector<uint32_t>)> m_deleteCallback;

int getNumRows() override
{
Expand All @@ -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<size_t>(rowNumber)], 5, 0, width, height, juce::Justification::centredLeft, true);
}

juce::var getDragSourceDescription(const juce::SparseSet<int>& selectedRows)
juce::var getDragSourceDescription(const juce::SparseSet<int>& selectedRows) override
{
juce::Array<juce::var> juceArray;
for (int i = 0; i < selectedRows.size(); ++i)
Expand Down Expand Up @@ -112,7 +114,8 @@ class BankItemsListBoxModel final : public juce::ListBox, public juce::ListBoxMo
return;

juce::Array<juce::var> *payload = dragSourceDetails.description.getArray();
std::vector<int> elements{(*payload).begin(), (*payload).end()};
std::vector<uint32_t> elements;
for (const auto& value : *payload) elements.push_back(static_cast<uint32_t>(static_cast<int>(value)));

if (!elements.empty()) {
m_dropCallback(elements, dragSourceDetails.sourceComponent);
Expand All @@ -123,10 +126,10 @@ class BankItemsListBoxModel final : public juce::ListBox, public juce::ListBoxMo
{
(void) arg;

std::vector<int> elements;
std::vector<uint32_t> elements;
auto selection = getSelectedRows();
for (int i = 0; i < selection.size(); ++i)
elements.push_back(selection[i]);
elements.push_back(static_cast<uint32_t>(selection[i]));

if (!elements.empty()) {
m_deleteCallback(elements);
Expand Down Expand Up @@ -224,7 +227,7 @@ class LoadedBank : public juce::Component, public juce::DragAndDropContainer {
return m_bank;
}

void transferPresets(std::vector<int> indices, juce::WeakReference<juce::Component> ref)
void transferPresets(std::vector<uint32_t> indices, juce::WeakReference<juce::Component> ref)
{
if (!m_bank) return;

Expand All @@ -237,13 +240,13 @@ class LoadedBank : public juce::Component, public juce::DragAndDropContainer {
transferPresetRecursive(indices, src_bank, false);
}

void deletePresets(std::vector<int> indices)
void deletePresets(std::vector<uint32_t> indices)
{
if (!m_bank) return;

// Grab the names first.
std::vector<std::string> 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));
Expand Down Expand Up @@ -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<int> indices, juce::WeakReference<juce::Component> ref) { this->transferPresets(indices, ref); });
m_listBox->setDeleteCallback([this](std::vector<int> indices) { this->deletePresets(indices); });
m_listBox->setDropCallback([this](std::vector<uint32_t> indices, juce::WeakReference<juce::Component> ref) { this->transferPresets(indices, ref); });
m_listBox->setDeleteCallback([this](std::vector<uint32_t> 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);
Expand Down Expand Up @@ -372,9 +375,9 @@ class LoadedBank : public juce::Component, public juce::DragAndDropContainer {
private:
std::unique_ptr<juce::AlertWindow> m_confirmDialog;

void transferPresetRecursive(std::vector<int> indices, ysfx_bank_shared src_bank, bool force_accept)
void transferPresetRecursive(std::vector<uint32_t> 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){
Expand Down
38 changes: 20 additions & 18 deletions plugin/components/searchable_popup.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 (
Expand Down Expand Up @@ -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);
Expand All @@ -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 */
Expand All @@ -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)
{
Expand Down Expand Up @@ -230,7 +230,7 @@
}

juce::Rectangle<int> 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;
Expand Down Expand Up @@ -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.
Expand All @@ -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<MenuTree*> parents (quick_search_items.size());
Expand Down Expand Up @@ -380,7 +380,7 @@
updateMatches();

int nb_visible_matches =
std::min<int> (owner->options.maxNumberOfMatchesDisplayed, (int) matches.size());
std::min<int> (m_owner->options.maxNumberOfMatchesDisplayed, (int) matches.size());

int h = item_height;
jassert (h);
Expand Down Expand Up @@ -414,7 +414,7 @@
{
if (best_items.at (i) == nullptr)
{
best_items[i] = std::make_unique<MenuItemComponent> (owner);
best_items[i] = std::make_unique<MenuItemComponent>(m_owner);
addAndMakeVisible (*best_items[i]);
}
size_t ii = first_displayed_match + i;
Expand Down Expand Up @@ -534,15 +534,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<size_t>(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(); }

Expand All @@ -555,7 +556,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<Component>(this)]() { if (ref) { owner->showPopupMenu(); } });
juce::MessageManager::getInstance()->callAsync([this, ref=juce::WeakReference<Component>(this)]() { if (ref) { m_owner->showPopupMenu(); } });
}

bool up = (key == juce::KeyPress::upKey), down = (key == juce::KeyPress::downKey);
Expand All @@ -582,7 +583,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<size_t>(highlighted_match)));
if (! q.popup_menu_item->isEnabled)
highlighted_match = 0;
updateContent();
Expand All @@ -606,7 +608,7 @@
double dt = (juce::Time::getCurrentTime() - creation_time).inSeconds();
if (dt > 0.2)
{
owner->quickSearchFinished (0);
m_owner->quickSearchFinished (0);
}
}

Expand Down
2 changes: 1 addition & 1 deletion plugin/components/tokenizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
14 changes: 7 additions & 7 deletions plugin/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,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();
}
Expand Down Expand Up @@ -414,13 +414,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);
}
}
);
Expand Down Expand Up @@ -631,10 +631,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);
}
});
}
Expand Down
2 changes: 2 additions & 0 deletions plugin/editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,5 @@ class YsfxEditor : public juce::AudioProcessorEditor, public juce::FileDragAndDr
struct Impl;
std::unique_ptr<Impl> m_impl;
};

void writeThemeFile(juce::File file, std::map<std::string, std::array<uint8_t, 3>> colors, std::map<std::string, float> params);
2 changes: 1 addition & 1 deletion plugin/lookandfeel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ void setColors(juce::LookAndFeel& lnf, std::map<std::string, std::array<uint8_t,
jassert(it != colormap.end()); // This color doesn't have a default!

if (it != colormap.end()) {
return juce::Colour(int(it->second[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);
}
Expand Down
5 changes: 2 additions & 3 deletions plugin/parameter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,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<uint32_t>(m_sliderIndex)));
}
}
}
Expand Down Expand Up @@ -97,7 +97,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
Expand Down Expand Up @@ -170,7 +170,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;
Expand Down
Loading

0 comments on commit 446f08f

Please sign in to comment.