Skip to content

Commit

Permalink
Track menu: group samplers >16 into submenus
Browse files Browse the repository at this point in the history
  • Loading branch information
ronso0 committed Jan 29, 2024
1 parent c72fce1 commit 5d299ef
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions src/widget/wtrackmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@

namespace {
const QString kAppGroup = QStringLiteral("[App]");

const QString samplerTrString(int i) {
return QObject::tr("Sampler %1").arg(i);
}

} // namespace

WTrackMenu::WTrackMenu(
Expand Down Expand Up @@ -818,19 +823,36 @@ void WTrackMenu::updateMenus() {
}
}

int iNumSamplers = static_cast<int>(m_pNumSamplers->get());
const int iNumSamplers = static_cast<int>(m_pNumSamplers->get());
const int maxSamplersPerMenu = 16;
if (iNumSamplers > 0) {
m_pSamplerMenu->clear();
QMenu* pMenu = m_pSamplerMenu;
int counter = 1;
for (int i = 1; i <= iNumSamplers; ++i) {
if (counter > maxSamplersPerMenu) {
counter = 1;
int limit = iNumSamplers > i + 16 ? i + 16 : iNumSamplers;
const QString label = samplerTrString(i) + QStringLiteral("- %1").arg(limit);
pMenu = new QMenu(label, m_pSamplerMenu);
m_pSamplerMenu->addSeparator();
m_pSamplerMenu->addMenu(pMenu);
}
counter++;
// PlayerManager::groupForSampler is 0-indexed.
QString samplerGroup = PlayerManager::groupForSampler(i - 1);
bool samplerPlaying = ControlObject::get(
ConfigKey(samplerGroup, "play")) > 0.0;
bool samplerEnabled = !samplerPlaying && singleTrackSelected;
QAction* pAction = new QAction(tr("Sampler %1").arg(i), m_pSamplerMenu);
QAction* pAction = new QAction(samplerTrString(i), pMenu);
pAction->setEnabled(samplerEnabled);
m_pSamplerMenu->addAction(pAction);
connect(pAction, &QAction::triggered, this, [this, samplerGroup] { loadSelectionToGroup(samplerGroup); });
pMenu->addAction(pAction);
connect(pAction,
&QAction::triggered,
this,
[this, samplerGroup] {
loadSelectionToGroup(samplerGroup);
});
}
}
}
Expand Down

0 comments on commit 5d299ef

Please sign in to comment.