Cantalia
Code sample
This method belongs to the Piece class (Piece = Seed).
It gets called whenever a change of musical scale is wanted (eg. minor to major).
Players can override this global scale change by choosing a scale of their own.
That could be interesting - if the Player ScaleMenus are well chosen!
public void newScale()
{
if (!scales.isEmpty())
{
int scaleIndex = dice.roll(scales);
Vector items = scales.getItems();
PitchMenu chosenScale = (PitchMenu)items.elementAt(scaleIndex);
if (scales.getAvoidRepeats() && currentScale != null)
{
if (scales.getCount() > 1)
while (chosenScale == currentScale)
{
scaleIndex = dice.roll(scales);
items = scales.getItems();
chosenScale = (PitchMenu)items.elementAt(scaleIndex);
}
}
currentScale = chosenScale;
}
else
{
currentScale = (PitchMenu)Defaults.scales.getValueAt(0, 0);
currentScale = (PitchMenu)currentScale.deepCopy();
currentScale.setHideNameFromPiece(true);
currentScale.expand();
}
if (getVisualFeedback()) fireTableCellUpdated(0, 2);
Debug.println("TM", "new piece scale = " + currentScale.toString());
Debug.println();
band.newScale(currentScale);
}