Here are the examples of the java api org.jjazz.musiccontrol.MusicController.play() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
3 Examples
16
Source : Play.java
with GNU Lesser General Public License v3.0
from jjazzboss
with GNU Lesser General Public License v3.0
from jjazzboss
public synchronized void setSelected(boolean newState) {
if (newState == getBooleanState()) {
return;
}
// Notify all listeners eg UI button
setBooleanState(newState);
MusicController mc = MusicController.getInstance();
MusicController.State playBackState = mc.getState();
// NOI18N
LOGGER.fine("setSelected() newState=" + newState + " playBackState=" + playBackState);
switch(playBackState) {
case PAUSED:
if (newState) {
// Start from last position
// Otherwise button should be disabled //NOI18N
replacedert currentSong != null;
try {
mc.resume();
} catch (MusicGenerationException | PropertyVetoException ex) {
if (ex.getLocalizedMessage() != null) {
NotifyDescriptor d = new NotifyDescriptor.Message(ex.getLocalizedMessage(), NotifyDescriptor.ERROR_MESSAGE);
DialogDisplayer.getDefault().notify(d);
}
setBooleanState(!newState);
return;
}
} else {
// Nothing
}
break;
case STOPPED:
if (newState) {
// Start playback from initial position
// Otherwise button should be disabled //NOI18N
replacedert currentSong != null;
try {
// Can raise MidiUnavailableException
MidiMix midiMix = MidiMixManager.getInstance().findMix(currentSong);
MusicGenerationContext context = new MusicGenerationContext(currentSong, midiMix);
mc.setContext(context);
mc.play(0);
} catch (MusicGenerationException | PropertyVetoException | MidiUnavailableException ex) {
if (ex.getLocalizedMessage() != null) {
NotifyDescriptor d = new NotifyDescriptor.Message(ex.getLocalizedMessage(), NotifyDescriptor.ERROR_MESSAGE);
DialogDisplayer.getDefault().notify(d);
}
setBooleanState(!newState);
return;
}
} else {
// Nothing
}
break;
case PLAYING:
if (newState) {
// Nothing
} else {
// Pause playback, might actually be equivalent to a stop() if song was modified
mc.pause();
}
break;
case DISABLED:
if (newState) {
// Can't play if disabled, revert back
setBooleanState(!newState);
} else {
// Nothing
}
break;
default:
// NOI18N
throw new IllegalArgumentException("playBackState=" + playBackState + " newState=" + newState);
}
}
0
Source : PlayFromHere.java
with GNU Lesser General Public License v3.0
from jjazzboss
with GNU Lesser General Public License v3.0
from jjazzboss
@Override
public void actionPerformed(ActionEvent e) {
if (song == null) {
// NOI18N
LOGGER.severe("actionPerformed() unexpected value song=" + song);
return;
}
// Song must be active !
ActiveSongManager asm = ActiveSongManager.getInstance();
if (asm.getActiveSong() != song) {
String msg = ResUtil.getString(getClreplaced(), "ERR_NotActive");
NotifyDescriptor d = new NotifyDescriptor.Message(msg, NotifyDescriptor.ERROR_MESSAGE);
DialogDisplayer.getDefault().notify(d);
return;
}
ChordLeadSheet cls = song.getChordLeadSheet();
CL_EditorTopComponent clTc = CL_EditorTopComponent.get(cls);
// NOI18N
replacedert clTc != null;
CL_Editor clEditor = clTc.getCL_Editor();
CL_SelectionUtilities clSelection = new CL_SelectionUtilities(clEditor.getLookup());
SongStructure ss = song.getSongStructure();
SS_EditorTopComponent ssTc = SS_EditorTopComponent.get(ss);
// NOI18N
replacedert ssTc != null;
SS_Editor ssEditor = ssTc.getSS_Editor();
SS_SelectionUtilities ssSelection = new SS_SelectionUtilities(ssEditor.getLookup());
int playFromBar = -1;
if (lastValidActivatedTc == clTc && !clSelection.isEmpty()) {
// Focus in the CL_Editor
int clsBarIndex = clSelection.getMinBarIndexWithinCls();
if (clsBarIndex != -1) {
// Try to find a bar in a matching SongPart
// Can return -1
playFromBar = getSsBarIndex(clsBarIndex, cls, ss);
}
} else if (lastValidActivatedTc == ssTc && !ssSelection.isEmpty()) {
// Focus in the SS_Editor
SongPart firstSpt = ssSelection.getIndirectlySelectedSongParts().get(0);
playFromBar = firstSpt.getStartBarIndex() + getSelectedBarIndexRelativeToSection(firstSpt.getParentSection(), clSelection);
}
if (playFromBar == -1) {
String msg = ResUtil.getString(getClreplaced(), "ERR_CantPlayFromHere");
NotifyDescriptor d = new NotifyDescriptor.Message(msg, NotifyDescriptor.ERROR_MESSAGE);
DialogDisplayer.getDefault().notify(d);
return;
}
// Make sure playback is stopped
MusicController mc = MusicController.getInstance();
mc.stop();
// Configure and play
try {
// Can raise MidiUnavailableException
MidiMix midiMix = MidiMixManager.getInstance().findMix(song);
MusicGenerationContext context = new MusicGenerationContext(song, midiMix);
mc.setContext(context);
mc.play(playFromBar);
} catch (MusicGenerationException | PropertyVetoException | MidiUnavailableException ex) {
if (ex.getMessage() != null) {
NotifyDescriptor d = new NotifyDescriptor.Message(ex.getLocalizedMessage(), NotifyDescriptor.ERROR_MESSAGE);
DialogDisplayer.getDefault().notify(d);
}
}
}
0
Source : PlaySelection.java
with GNU Lesser General Public License v3.0
from jjazzboss
with GNU Lesser General Public License v3.0
from jjazzboss
@Override
public void actionPerformed(ActionEvent e) {
if (song == null) {
// NOI18N
LOGGER.severe("actionPerformed() unexpected value song=" + song);
return;
}
// Song must be active !
ActiveSongManager asm = ActiveSongManager.getInstance();
if (asm.getActiveSong() != song) {
String msg = ResUtil.getString(getClreplaced(), "ERR_NotActive");
NotifyDescriptor d = new NotifyDescriptor.Message(msg, NotifyDescriptor.ERROR_MESSAGE);
DialogDisplayer.getDefault().notify(d);
return;
}
ChordLeadSheet cls = song.getChordLeadSheet();
CL_EditorTopComponent clTc = CL_EditorTopComponent.get(cls);
// NOI18N
replacedert clTc != null;
CL_Editor clEditor = clTc.getCL_Editor();
CL_SelectionUtilities clSelection = new CL_SelectionUtilities(clEditor.getLookup());
SongStructure ss = song.getSongStructure();
SS_EditorTopComponent ssTc = SS_EditorTopComponent.get(ss);
// NOI18N
replacedert ssTc != null;
SS_Editor ssEditor = ssTc.getSS_Editor();
SS_SelectionUtilities ssSelection = new SS_SelectionUtilities(ssEditor.getLookup());
IntRange rg = null;
// By default
String errMsg = ResUtil.getString(getClreplaced(), "ERR_NeedContiguousSelection");
if (lastValidActivatedTc == clTc && clSelection.isContiguousBarboxSelectionWithinCls()) {
// Focus in the CL_Editor
// Can be null
rg = toSgsRange(ss, cls, new IntRange(clSelection.getMinBarIndexWithinCls(), clSelection.getMaxBarIndexWithinCls()));
if (rg == null) {
errMsg = ResUtil.getString(getClreplaced(), "ERR_BadSelection");
}
} else if (lastValidActivatedTc == ssTc && ssSelection.isOneSectionSptSelection()) {
// Focus in the SS_Editor
List<SongPart> spts = ssSelection.getIndirectlySelectedSongParts();
SongPart firstSpt = spts.get(0);
SongPart lastSpt = spts.get(spts.size() - 1);
rg = new IntRange(firstSpt.getStartBarIndex(), lastSpt.getBarRange().to);
}
if (rg == null) {
String msg = ResUtil.getString(getClreplaced(), "ERR_InvalidPlayableSelection", errMsg);
NotifyDescriptor d = new NotifyDescriptor.Message(msg, NotifyDescriptor.ERROR_MESSAGE);
DialogDisplayer.getDefault().notify(d);
return;
}
MusicController mc = MusicController.getInstance();
mc.stop();
// OK we can go
try {
// Can raise MidiUnavailableException
MidiMix midiMix = MidiMixManager.getInstance().findMix(song);
MusicGenerationContext context = new MusicGenerationContext(song, midiMix, rg);
mc.setContext(context);
mc.play(rg.from);
} catch (MusicGenerationException | PropertyVetoException | MidiUnavailableException ex) {
if (ex.getMessage() != null) {
NotifyDescriptor d = new NotifyDescriptor.Message(ex.getLocalizedMessage(), NotifyDescriptor.ERROR_MESSAGE);
DialogDisplayer.getDefault().notify(d);
}
}
}