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 faa48be
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 72 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
47 changes: 25 additions & 22 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 @@ -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<size_t>(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<MenuItemComponent> (owner);
best_items[i] = std::make_unique<MenuItemComponent>(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<size_t>(first_displayed_match) + i;
best_items[i]->updateWith (quick_search_items.at (matches.at (ii)), ii == static_cast<size_t>(highlighted_match));
if (displayed_over_or_under == 1)
{
best_items[i]->setBounds (0, (h + separator_height) + (int) i * h, item_width, h);
Expand Down Expand Up @@ -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<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 +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<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 +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<size_t>(highlighted_match)));
if (! q.popup_menu_item->isEnabled)
highlighted_match = 0;
updateContent();
Expand All @@ -606,7 +609,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;
};
Loading

0 comments on commit faa48be

Please sign in to comment.