Skip to content

Commit

Permalink
Remove deprecated code in GigPlayer
Browse files Browse the repository at this point in the history
Use `CountInstruments` and `GetInstrument` instead of the deprecated
methods `GetFirstInstrument` and `GetNextInstrument`.

Use `CountRegions` and `GetRegionAt` instead of the deprecated
`GetFirstRegion` and `GetNextRegion`.

Both changes turn `while` loops into `for` loops.
  • Loading branch information
michaelgregorius committed Oct 10, 2024
1 parent 378ff8b commit ded85ea
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 37 deletions.
42 changes: 15 additions & 27 deletions plugins/GigPlayer/GigPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,26 +260,19 @@ QString GigInstrument::getCurrentPatchName()
int iBankSelected = m_bankNum.value();
int iProgSelected = m_patchNum.value();

gig::Instrument * pInstrument = m_instance->gig.GetFirstInstrument();

while( pInstrument != nullptr )
for (size_t i = 0; i < m_instance->gig.CountInstruments(); ++i)
{
auto pInstrument = m_instance->gig.GetInstrument(i);

int iBank = pInstrument->MIDIBank;
int iProg = pInstrument->MIDIProgram;

if( iBank == iBankSelected && iProg == iProgSelected )
if (iBank == iBankSelected && iProg == iProgSelected)
{
QString name = QString::fromStdString( pInstrument->pInfo->Name );
QString name = QString::fromStdString(pInstrument->pInfo->Name);

if( name == "" )
{
name = "<no name>";
}

return name;
return name.isEmpty() ? "<no name>" : name;
}

pInstrument = m_instance->gig.GetNextInstrument();
}

return "";
Expand Down Expand Up @@ -719,10 +712,10 @@ void GigInstrument::addSamples( GigNote & gignote, bool wantReleaseSample )
m_instrument->DimensionKeyRange.low + 1 );
}

gig::Region* pRegion = m_instrument->GetFirstRegion();

while( pRegion != nullptr )
for (size_t i = 0; i < m_instrument->CountRegions(); ++i)
{
gig::Region* pRegion = m_instrument->GetRegionAt(i);

Dimension dim = getDimensions( pRegion, gignote.velocity, wantReleaseSample );
gig::DimensionRegion * pDimRegion = pRegion->GetDimensionRegionByValue( dim.DimValues );
gig::Sample * pSample = pDimRegion->pSample;
Expand Down Expand Up @@ -764,8 +757,6 @@ void GigInstrument::addSamples( GigNote & gignote, bool wantReleaseSample )
attenuation, m_interpolation, gignote.frequency ) );
}
}

pRegion = m_instrument->GetNextRegion();
}
}

Expand Down Expand Up @@ -863,22 +854,19 @@ void GigInstrument::getInstrument()

if( m_instance != nullptr )
{
gig::Instrument * pInstrument = m_instance->gig.GetFirstInstrument();

while( pInstrument != nullptr )
for (size_t i = 0; i < m_instance->gig.CountInstruments(); ++i)
{
gig::Instrument* pInstrument = m_instance->gig.GetInstrument(i);

int iBank = pInstrument->MIDIBank;
int iProg = pInstrument->MIDIProgram;

if( iBank == iBankSelected && iProg == iProgSelected )
if (iBank == iBankSelected && iProg == iProgSelected)
{
break;
m_instrument = pInstrument;
return;
}

pInstrument = m_instance->gig.GetNextInstrument();
}

m_instrument = pInstrument;
}
}

Expand Down
16 changes: 6 additions & 10 deletions plugins/GigPlayer/PatchesDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,10 @@ void PatchesDialog::setup( GigInstance * pSynth, int iChan,
int iBankDefault = -1;
int iProgDefault = -1;

gig::Instrument * pInstrument = m_pSynth->gig.GetFirstInstrument();

while( pInstrument )
for (size_t i = 0; i < m_pSynth->gig.CountInstruments(); ++i)
{
gig::Instrument * pInstrument = m_pSynth->gig.GetInstrument(i);

int iBank = pInstrument->MIDIBank;
int iProg = pInstrument->MIDIProgram;

Expand All @@ -165,8 +165,6 @@ void PatchesDialog::setup( GigInstance * pSynth, int iChan,
}
}
}

pInstrument = m_pSynth->gig.GetNextInstrument();
}

m_bankListView->setSortingEnabled( true );
Expand Down Expand Up @@ -341,10 +339,10 @@ void PatchesDialog::bankChanged()
m_progListView->clear();
QTreeWidgetItem * pProgItem = nullptr;

gig::Instrument * pInstrument = m_pSynth->gig.GetFirstInstrument();

while( pInstrument )
for (size_t i = 0; i < m_pSynth->gig.CountInstruments(); ++i)
{
gig::Instrument * pInstrument = m_pSynth->gig.GetInstrument(i);

QString name = QString::fromStdString( pInstrument->pInfo->Name );

if( name == "" )
Expand All @@ -365,8 +363,6 @@ void PatchesDialog::bankChanged()
pProgItem->setText( 1, name );
}
}

pInstrument = m_pSynth->gig.GetNextInstrument();
}

m_progListView->setSortingEnabled( true );
Expand Down

0 comments on commit ded85ea

Please sign in to comment.