Skip to content

Commit

Permalink
fix #276456: Moving soundfont in the soundfonts list creates duplicat…
Browse files Browse the repository at this point in the history
…e list entries (Fluid)

Call removeSoundfonts() before rebuilding the list.
Refactor code in Up/Down methods for both Fluid and Zerberus.
  • Loading branch information
anatoly-os committed Dec 12, 2018
1 parent 20b6e83 commit 87ed9ac
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 30 deletions.
36 changes: 21 additions & 15 deletions fluid/fluidgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,24 +140,37 @@ void FluidGui::synthesizerChanged()
}

//---------------------------------------------------------
// soundFontUpClicked
// moveSoundfontInTheList
//---------------------------------------------------------

void FluidGui::soundFontUpClicked()
void FluidGui::moveSoundfontInTheList(int currentIdx, int targetIdx)
{
int row = soundFonts->currentRow();
if (row <= 0)
return;
QStringList sfonts = fluid()->soundFonts();
sfonts.swap(row, row - 1);
for (auto sfName : sfonts)
fluid()->removeSoundFont(sfName);

sfonts.swap(currentIdx, targetIdx);
fluid()->loadSoundFonts(sfonts);
sfonts = fluid()->soundFonts();
soundFonts->clear();
soundFonts->addItems(sfonts);
soundFonts->setCurrentRow(row - 1);
soundFonts->setCurrentRow(targetIdx);
emit sfChanged();
}

//---------------------------------------------------------
// soundFontUpClicked
//---------------------------------------------------------

void FluidGui::soundFontUpClicked()
{
int row = soundFonts->currentRow();
if (row <= 0)
return;

moveSoundfontInTheList(row, row - 1);
}

//---------------------------------------------------------
// soundFontDownClicked
//---------------------------------------------------------
Expand All @@ -169,14 +182,7 @@ void FluidGui::soundFontDownClicked()
if (row + 1 >= rows)
return;

QStringList sfonts = fluid()->soundFonts();
sfonts.swap(row, row + 1);
fluid()->loadSoundFonts(sfonts);
sfonts = fluid()->soundFonts();
soundFonts->clear();
soundFonts->addItems(sfonts);
soundFonts->setCurrentRow(row + 1);
emit sfChanged();
moveSoundfontInTheList(row, row + 1);
}

//---------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions fluid/fluidgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class FluidGui : public Ms::SynthesizerGui, Ui::FluidGui {
QTimer * _progressTimer;
std::list<struct SfNamePath> _sfToLoad;
void loadSf();
void moveSoundfontInTheList(int currentIdx, int targetIdx);

private slots:
void soundFontUpClicked();
Expand Down
39 changes: 25 additions & 14 deletions zerberus/zerberusgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,35 +109,46 @@ ZerberusGui::ZerberusGui(Ms::Synthesizer* s)
updateButtons();
}

//---------------------------------------------------------
// moveSoundfontInTheList
//---------------------------------------------------------

void ZerberusGui::moveSoundfontInTheList(int currentIdx, int targetIdx)
{
QStringList sfonts = zerberus()->soundFonts();
sfonts.swap(currentIdx, targetIdx);
zerberus()->removeSoundFonts(zerberus()->soundFonts());

loadSoundFontsAsync(sfonts);
files->setCurrentRow(targetIdx);
emit sfChanged();
}

//---------------------------------------------------------
// soundFontUpClicked
//---------------------------------------------------------

void ZerberusGui::soundFontUpClicked()
{
int row = files->currentRow();
if (row <= 0)
return;

QStringList sfonts = zerberus()->soundFonts();
sfonts.swap(row, row-1);
zerberus()->removeSoundFonts(zerberus()->soundFonts());

loadSoundFontsAsync(sfonts);
files->setCurrentRow(row-1);
emit sfChanged();
moveSoundfontInTheList(row, row - 1);
}

//---------------------------------------------------------
// soundFontDownClicked
//---------------------------------------------------------

void ZerberusGui::soundFontDownClicked()
{
int rows = files->count();
int row = files->currentRow();
if (row + 1 >= rows)
return;

QStringList sfonts = zerberus()->soundFonts();
sfonts.swap(row, row + 1);
zerberus()->removeSoundFonts(zerberus()->soundFonts());

loadSoundFontsAsync(sfonts);
files->setCurrentRow(row + 1);
emit sfChanged();
moveSoundfontInTheList(row, row + 1);
}

//---------------------------------------------------------
Expand Down
3 changes: 2 additions & 1 deletion zerberus/zerberusgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ class ZerberusGui : public Ms::SynthesizerGui, Ui::ZerberusGui {

void loadSfz();
void loadSoundFontsAsync(QStringList sfonts);

void moveSoundfontInTheList(int currentIdx, int targetIdx);

private slots:
void soundFontUpClicked();
void soundFontDownClicked();
Expand Down

0 comments on commit 87ed9ac

Please sign in to comment.