Skip to content

Commit

Permalink
Advance to next track in playlist, add loop capability (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sammy1Am committed Aug 23, 2020
1 parent 92667bf commit 62dfdbd
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
<Component id="jScrollPane1" max="32767" attributes="0"/>
<Group type="102" attributes="0">
<Component id="autoResetCB" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="repeatCheckbox" min="-2" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
<Component id="removeFileButton" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
Expand All @@ -62,6 +64,7 @@
<Component id="loadFileButton" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="removeFileButton" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="autoResetCB" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="repeatCheckbox" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Component id="controlsPane" min="-2" max="-2" attributes="0"/>
Expand Down Expand Up @@ -353,5 +356,11 @@
<AuxValue name="JavaCodeGenerator_CreateCodePost" type="java.lang.String" value="autoResetCB.setSelected(MoppyPreferences.getConfiguration().isAutoReset());&#xd;&#xa;"/>
</AuxValues>
</Component>
<Component class="javax.swing.JCheckBox" name="repeatCheckbox">
<Properties>
<Property name="text" type="java.lang.String" value="Repeat"/>
<Property name="toolTipText" type="java.lang.String" value="Repeats playlist after the last (or only) song has finished."/>
</Properties>
</Component>
</SubComponents>
</Form>
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,23 @@ private void loadSequence(int playlistIndex) {
}
}
}

/**
* Advanced the loaded sequence to the next in the playlist (or wraps back to 0)
*/
private void advanceSequence() {
if (++loadedIndex >= playlistFilesModel.size() ) {
loadSequence(0);
if (repeatCheckbox.isSelected()) {
midiSequencer.play();
} else {
midiSequencer.stop();
}
} else {
loadSequence(loadedIndex);
midiSequencer.play();
}
}

private class PlaylistCellRenderer extends DefaultListCellRenderer {

Expand Down Expand Up @@ -153,6 +170,7 @@ private void initComponents() {
removeFileButton = new javax.swing.JButton();
autoResetCB = new javax.swing.JCheckBox();
autoResetCB.setSelected(MoppyPreferences.getConfiguration().isAutoReset());
repeatCheckbox = new javax.swing.JCheckBox();

sequenceFileChooser.setCurrentDirectory(new File(MoppyPreferences.getConfiguration().getFileLoadDirectory()));
sequenceFileChooser.setDialogTitle("Select MIDI File");
Expand Down Expand Up @@ -346,6 +364,9 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
}
});

repeatCheckbox.setText("Repeat");
repeatCheckbox.setToolTipText("Repeats playlist after the last (or only) song has finished.");

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
Expand All @@ -357,6 +378,8 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
.addComponent(jScrollPane1)
.addGroup(layout.createSequentialGroup()
.addComponent(autoResetCB)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(repeatCheckbox)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(removeFileButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
Expand All @@ -372,7 +395,8 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(loadFileButton)
.addComponent(removeFileButton)
.addComponent(autoResetCB))
.addComponent(autoResetCB)
.addComponent(repeatCheckbox))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(controlsPane, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
);
Expand Down Expand Up @@ -516,6 +540,7 @@ private void playlistFilesListMouseClicked(java.awt.event.MouseEvent evt) {//GEN
private javax.swing.JButton playButton;
private javax.swing.JList<File> playlistFilesList;
private javax.swing.JButton removeFileButton;
private javax.swing.JCheckBox repeatCheckbox;
private javax.swing.JLabel sequenceCurrentTimeLabel;
private javax.swing.JFileChooser sequenceFileChooser;
private javax.swing.JSlider sequenceSlider;
Expand All @@ -540,6 +565,9 @@ public void receiveUpdate(StatusUpdate update) {
removeFileButton.setEnabled(false);
break;
case SEQUENCE_END:
advanceSequence();
break;
case SEQUENCE_STOPPED:
sequenceSlider.setValue(0);
sequenceCurrentTimeLabel.setText(String.format(TIME_CODE_FORMAT, 0, 0));
case SEQUENCE_PAUSE:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ public void receiveUpdate(StatusUpdate update) {
enableMapperEditing(false);
saveMappersToConfig(); // Go ahead and proactively save the mappers when we start playing
break;
case SEQUENCE_STOPPED:
case SEQUENCE_END:
case SEQUENCE_PAUSE:
enableMapperEditing(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public static List<MoppyMessage> mapStatusUpdate(StatusUpdate statusUpdate) {
return Arrays.asList(MoppyMessage.SYS_START);
case SEQUENCE_PAUSE:
return Arrays.asList(MoppyMessage.SYS_STOP);
case SEQUENCE_STOPPED:
case SEQUENCE_END:
if ((boolean)statusUpdate.getData().orElse(false)) {
// If doReset, add reset message.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void pause() {
public void stop() {
seq.stop();
seq.setTickPosition(0);
statusBus.receiveUpdate(StatusUpdate.sequenceEnd(true)); // Always reset when stop button is pressed
statusBus.receiveUpdate(StatusUpdate.SEQUENCE_STOPPED);
}

public boolean isPlaying() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ public enum StatusType {
SEQUENCE_LOAD,
SEQUENCE_START,
SEQUENCE_PAUSE,
SEQUENCE_END,
SEQUENCE_STOPPED, // Sequence playback was stopped manually
SEQUENCE_END, // Sequence playback stopped because it reached the end of the sequence
SEQUENCE_TEMPO_CHANGE,

// Network statuses
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public Optional<Object> getData() {

public static StatusUpdate SEQUENCE_START = new StatusUpdate(StatusType.SEQUENCE_START, Optional.empty());
public static StatusUpdate SEQUENCE_PAUSE = new StatusUpdate(StatusType.SEQUENCE_PAUSE, Optional.empty());
public static StatusUpdate SEQUENCE_STOPPED = new StatusUpdate(StatusType.SEQUENCE_STOPPED, Optional.of(true)); // Always reset when stopped

public static StatusUpdate sequenceEnd(boolean doReset) {
return new StatusUpdate(StatusType.SEQUENCE_END, Optional.of(doReset));
Expand Down

0 comments on commit 62dfdbd

Please sign in to comment.