Skip to content

Commit

Permalink
display blank entries in gray color
Browse files Browse the repository at this point in the history
  • Loading branch information
jpcima committed Nov 11, 2018
1 parent c9d3234 commit 9003fb1
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 70 deletions.
36 changes: 28 additions & 8 deletions src/bank_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ BankEditor::BankEditor(QWidget *parent) :
ui->setupUi(this);
this->setWindowIcon(makeWindowIcon());
m_recentMelodicNote = ui->noteToTest->value();
m_bank.Ins_Melodic_box.fill(FmBank::blankInst());
m_bank.Ins_Percussion_box.fill(FmBank::blankInst());
setMelodic();
connect(ui->melodic, SIGNAL(clicked(bool)), this, SLOT(setMelodic()));
connect(ui->percussion, SIGNAL(clicked(bool)), this, SLOT(setDrums()));
Expand Down Expand Up @@ -607,6 +609,17 @@ void BankEditor::syncInstrumentName()
(m_recentPerc ? getMidiInsNameP(m_recentNum) : getMidiInsNameM(m_recentNum))
);
}
syncInstrumentBlankness();
}

void BankEditor::syncInstrumentBlankness()
{
QListWidgetItem *curInstr = ui->instruments->currentItem();
if(m_curInst && curInstr)
{
curInstr->setForeground(m_curInst->is_blank ?
Qt::gray : Qt::black);
}
}

void BankEditor::on_actionNew_triggered()
Expand Down Expand Up @@ -1301,6 +1314,8 @@ void BankEditor::setMelodic()
QString::fromUtf8(m_bank.Ins_Melodic[i].name) : getMidiInsNameM(i));
setInstrumentMetaInfo(item, i);
item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
item->setForeground(m_bank.Ins_Melodic[i].is_blank ?
Qt::gray : Qt::black);
ui->instruments->addItem(item);
}
on_bank_no_currentIndexChanged(ui->bank_no->currentIndex());
Expand All @@ -1318,6 +1333,8 @@ void BankEditor::setDrums()
QString::fromUtf8(m_bank.Ins_Percussion[i].name) : getMidiInsNameP(i));
setInstrumentMetaInfo(item, i);
item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
item->setForeground(m_bank.Ins_Percussion[i].is_blank ?
Qt::gray : Qt::black);
ui->instruments->addItem(item);
}
on_bank_no_currentIndexChanged(ui->bank_no->currentIndex());
Expand All @@ -1339,6 +1356,8 @@ void BankEditor::reloadInstrumentNames()
items[i]->setText(m_bank.Ins_Percussion[index].name[0] != '\0' ?
QString::fromUtf8(m_bank.Ins_Percussion[index].name) :
getMidiInsNameP(index));
items[i]->setForeground(m_bank.Ins_Percussion[i].is_blank ?
Qt::gray : Qt::black);
}
}
}
Expand All @@ -1355,6 +1374,8 @@ void BankEditor::reloadInstrumentNames()
items[i]->setText(m_bank.Ins_Melodic[index].name[0] != '\0' ?
QString::fromUtf8(m_bank.Ins_Melodic[index].name) :
getMidiInsNameM(index));
items[i]->setForeground(m_bank.Ins_Melodic[i].is_blank ?
Qt::gray : Qt::black);
}
}
}
Expand All @@ -1376,7 +1397,6 @@ void BankEditor::on_actionAddInst_triggered()
}
else
{
FmBank::Instrument ins = FmBank::emptyInst();
m_bank.Ins_Percussion_box.push_back(ins);
m_bank.Ins_Percussion = m_bank.Ins_Percussion_box.data();
ins = m_bank.Ins_Percussion_box.last();
Expand Down Expand Up @@ -1413,7 +1433,7 @@ void BankEditor::on_actionClearInstrument_triggered()
return;
}

memset(m_curInst, 0, sizeof(FmBank::Instrument));
*m_curInst = FmBank::blankInst();
loadInstrument();
syncInstrumentName();
}
Expand Down Expand Up @@ -1587,17 +1607,17 @@ void BankEditor::on_actionClearBank_triggered()
{
if(needToShoot_end >= m_bank.Ins_Percussion_box.size())
needToShoot_end = m_bank.Ins_Percussion_box.size();
memset(m_bank.Ins_Percussion + needToShoot_begin,
0,
sizeof(FmBank::Instrument) * size_t(needToShoot_end - needToShoot_begin));
std::fill(m_bank.Ins_Percussion + needToShoot_begin,
m_bank.Ins_Percussion + needToShoot_end,
FmBank::blankInst());
}
else
{
if(needToShoot_end >= m_bank.Ins_Melodic_box.size())
needToShoot_end = m_bank.Ins_Melodic_box.size();
memset(m_bank.Ins_Melodic + needToShoot_begin,
0,
sizeof(FmBank::Instrument) * size_t(needToShoot_end - needToShoot_begin));
std::fill(m_bank.Ins_Melodic + needToShoot_begin,
m_bank.Ins_Melodic + needToShoot_end,
FmBank::blankInst());
}
reloadInstrumentNames();
loadInstrument();
Expand Down
11 changes: 10 additions & 1 deletion src/bank_editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,13 @@ class BankEditor : public QMainWindow
*/
void flushInstrument();
/**
* @brief Syncronize instrument name in the list widget with actual instrument name in the data store
* @brief Synchronize instrument name in the list widget with actual instrument name in the data store
*/
void syncInstrumentName();
/**
* @brief Synchronize instrument blank state in the list widget with actual instrument name in the data store
*/
void syncInstrumentBlankness();
/**
* @brief Sets current instrument to editand test
* @param num Number of instrument (from 0 to 127)
Expand Down Expand Up @@ -522,6 +526,11 @@ private slots:

void on_holdButton_toggled(bool checked);

/**
* @brief Update after a change of any control value
*/
void afterChangeControlValue();

/**
* @brief Adjusts the size of the window after it has been shown
*/
Expand Down
Loading

0 comments on commit 9003fb1

Please sign in to comment.