Skip to content

Commit

Permalink
Merge branch 'bug1962'
Browse files Browse the repository at this point in the history
  • Loading branch information
tedfelix committed Jun 21, 2024
2 parents bff3ebd + 257a68c commit 56f02ae
Show file tree
Hide file tree
Showing 12 changed files with 471 additions and 410 deletions.
2 changes: 1 addition & 1 deletion src/base/Instrument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ Instrument::isProgramValid() const
oBankIter != validBanks.end();
++oBankIter)
{
if (oBankIter->partialCompare(m_program.getBank())) {
if (oBankIter->compareKey(m_program.getBank())) {
bankValid = true;
break;
}
Expand Down
8 changes: 4 additions & 4 deletions src/base/MidiDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ MidiDevice::getPrograms(const MidiBank &bank) const

for (ProgramList::const_iterator it = m_programList.begin();
it != m_programList.end(); ++it) {
if (it->getBank().partialCompare(bank)) programs.push_back(*it);
if (it->getBank().compareKey(bank)) programs.push_back(*it);
}

return programs;
Expand Down Expand Up @@ -497,7 +497,7 @@ MidiDevice::getBankName(const MidiBank &bank) const
{
for (BankList::const_iterator it = m_bankList.begin();
it != m_bankList.end(); ++it) {
if ((*it).partialCompare(bank)) return it->getName();
if ((*it).compareKey(bank)) return it->getName();
}
return "";
}
Expand Down Expand Up @@ -606,7 +606,7 @@ MidiDevice::toXmlString() const
//
for (pt = m_programList.begin(); pt != m_programList.end(); ++pt)
{
if (pt->getBank().partialCompare(*it))
if (pt->getBank().compareKey(*it))
{
midiDevice << " <program "
<< "id=\"" << (int)pt->getProgram() << "\" "
Expand Down Expand Up @@ -740,7 +740,7 @@ MidiDevice::mergeBankList(const BankList &bankList)
{
for (oIt = m_bankList.begin(); oIt != m_bankList.end(); ++oIt)
{
if ((*it).partialCompare(*oIt))
if ((*it).compareKey(*oIt))
{
clash = true;
break;
Expand Down
4 changes: 2 additions & 2 deletions src/base/MidiProgram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ MidiBank::operator==(const MidiBank &rhs) const
}

bool
MidiBank::partialCompare(const MidiBank &rhs) const
MidiBank::compareKey(const MidiBank &rhs) const
{
return (m_percussion == rhs.m_percussion &&
m_msb == rhs.m_msb &&
Expand Down Expand Up @@ -95,7 +95,7 @@ MidiProgram::MidiProgram(const MidiBank &bank, MidiByte program, const std::stri
bool
MidiProgram::partialCompare(const MidiProgram &rhs) const
{
return m_bank.partialCompare(rhs.m_bank) && m_program == rhs.m_program;
return m_bank.compareKey(rhs.m_bank) && m_program == rhs.m_program;
}

bool
Expand Down
49 changes: 45 additions & 4 deletions src/base/MidiProgram.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,45 @@ class MidiBank

/// A full comparison of all fields.
/**
* This probably isn't what you want. See partialCompare().
* MIDIInstrumentParameterPanel::updateBankComboBox() uses this to
* detect changes that might require a repopulation of the bank combobox.
*
* See MidiBank::compareKey().
*/
bool operator==(const MidiBank &rhs) const;
bool operator!=(const MidiBank &rhs) const { return !operator==(rhs); }
/// Compare all fields except name.
/// Compare MSB:LSB:Percussion.
/**
* Since MidiProgram stores a partial MidiBank object (without name),
* a partial comparison such as this is frequently needed.
*
* ??? Should this really compare percussion? I think that's wrong
* right now. See if we can cause bugs with it. Then fix it.
*/
bool partialCompare(const MidiBank &rhs) const;
bool compareKey(const MidiBank &rhs) const;

// Only compares (percussion), msb, and lsb.
// Most useful for sorting and searching.
// This is specifically NOT operator<() because it does not compare
// all fields.
bool lessKey(const MidiBank &rhs) const
{
// ??? We'll need percussion soon.
//if (m_percussion == rhs.m_percussion) {
if (m_msb == rhs.m_msb)
return (m_lsb < rhs.m_lsb);
return (m_msb < rhs.m_msb);
//}
//return (m_percussion < rhs.m_percussion);
}

private:
bool m_percussion;
// Key fields.
bool m_percussion; // Not a key field yet. But soon.
MidiByte m_msb;
MidiByte m_lsb;

// Data fields.
std::string m_name;
};

Expand Down Expand Up @@ -96,13 +120,30 @@ class MidiProgram
// m_keyMapping.
bool partialCompareWithName(const MidiProgram &rhs) const;

// This only compares bank and program.
// Most useful for sorting and searching.
// Currently this is only used by MidiProgramsEditor for sorting.
bool lessKey(const MidiProgram &rhs) const
{
if (m_bank.compareKey(rhs.m_bank))
return (m_program < rhs.m_program);
return m_bank.lessKey(rhs.m_bank);
}

private:
// Key fields.
MidiBank m_bank;
MidiByte m_program;

// Data fields.
std::string m_name;
std::string m_keyMapping;
};

// ??? std::vector? This means all throughout rg we have to do linear
// searches. Wouldn't a std::set<> indexed by MSB:LSB:Percussion:PC
// make a *lot* more sense in the long run? Should reduce CPU usage
// and complexity significantly.
typedef std::vector<MidiProgram> ProgramList;

inline bool
Expand Down
3 changes: 2 additions & 1 deletion src/gui/editors/parameters/MIDIInstrumentParameterPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,8 @@ MIDIInstrumentParameterPanel::updateBankComboBox()

// Find the selected bank in the MIDI Device's bank list.
for (unsigned int i = 0; i < banks.size(); ++i) {
if (getSelectedInstrument()->getProgram().getBank().partialCompare(banks[i])) {
if (getSelectedInstrument()->getProgram().getBank().compareKey(
banks[i])) {
currentBank = i;
break;
}
Expand Down
10 changes: 5 additions & 5 deletions src/gui/studio/BankEditorDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1172,10 +1172,10 @@ BankEditorDialog::slotDelete()
it != m_programList.end();
++it) {
// If this program isn't in the bank that is being deleted,
// add it to the new program list. We use partialCompare()
// add it to the new program list. We use compareKey()
// because the MidiBank objects in the program list do not
// have their name fields filled in.
if (!it->getBank().partialCompare(bank))
if (!it->getBank().compareKey(bank))
newProgramList.push_back(*it);
}

Expand Down Expand Up @@ -1691,7 +1691,7 @@ BankEditorDialog::slotEditPaste()
// Remove programs that will be overwritten
//
for (it = m_programList.begin(); it != m_programList.end(); ++it) {
if (!(it->getBank().partialCompare(m_lastBank)))
if (!(it->getBank().compareKey(m_lastBank)))
tempProg.push_back(*it);
}
m_programList = tempProg;
Expand All @@ -1704,7 +1704,7 @@ BankEditorDialog::slotEditPaste()
// Add the new programs
//
for (it = tempProg.begin(); it != tempProg.end(); ++it) {
if (it->getBank().partialCompare(sourceBank)) {
if (it->getBank().compareKey(sourceBank)) {
// Insert with new MSB and LSB
//
MidiProgram copyProgram(m_lastBank,
Expand Down Expand Up @@ -1895,7 +1895,7 @@ bool BankEditorDialog::tracksUsingBank(const MidiBank& bank,

const MidiProgram& program = instrument->getProgram();
const MidiBank& ibank = program.getBank();
if (bank.partialCompare(ibank)) {
if (bank.compareKey(ibank)) {
// Found a Track using this bank
trackPositions.push_back(track->getPosition());
}
Expand Down
22 changes: 2 additions & 20 deletions src/gui/studio/MidiKeyMappingEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

#define RG_MODULE_STRING "[MidiKeyMappingEditor]"
#define RG_NO_DEBUG_PRINT

#include "MidiKeyMappingEditor.h"
#include "NameSetEditor.h"
Expand Down Expand Up @@ -69,8 +70,6 @@ MidiKeyMappingEditor::makeAdditionalWidget(QWidget */* parent */)
void
MidiKeyMappingEditor::clearAll()
{
blockAllSignals(true);

for (size_t i = 0; i < m_names.size(); ++i)
m_names[i]->clear();

Expand All @@ -79,9 +78,6 @@ MidiKeyMappingEditor::clearAll()
m_librarian->clear();
m_librarianEmail->clear();
setEnabled(false);

blockAllSignals(false);

}

void
Expand Down Expand Up @@ -126,8 +122,6 @@ MidiKeyMappingEditor::reset()
m_mapping = *m;


blockAllSignals(true);

// Librarian details
//
m_librarian->setText(strtoqstr(m_device->getLibrarianName()));
Expand All @@ -145,14 +139,11 @@ MidiKeyMappingEditor::reset()

if ( (int)i == index) {
QString name = strtoqstr(it->second);
m_completions << name;
m_names[i]->setText(name);
m_names[i]->setCursorPosition(0);
}
}
}

blockAllSignals(false);
}

void
Expand All @@ -177,17 +168,8 @@ MidiKeyMappingEditor::slotNameChanged(const QString &name)

void
MidiKeyMappingEditor::slotKeyMapButtonPressed()
{}

void MidiKeyMappingEditor::blockAllSignals(bool block)
{
QList<LineEdit *> allChildren =
findChildren<LineEdit*>((QRegularExpression)"[0-9]+");
QList<LineEdit *>::iterator it;

for (it = allChildren.begin(); it != allChildren.end(); ++it) {
(*it)->blockSignals(block);
}
}


}
1 change: 0 additions & 1 deletion src/gui/studio/MidiKeyMappingEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public slots:

protected:
virtual QWidget *makeAdditionalWidget(QWidget *parent);
void blockAllSignals(bool block);

//--------------- Data members ---------------------------------

Expand Down
Loading

0 comments on commit 56f02ae

Please sign in to comment.