gnu.javax.sound.midi.alsa

Class AlsaMidiSequencerDevice

Implemented Interfaces:
AutoCloseable, MidiDevice, Sequencer

public class AlsaMidiSequencerDevice
extends Object
implements Sequencer

The ALSA MIDI sequencer device. This is a singleton device.

Field Summary

static AlsaMidiSequencerDevice
instance

Method Summary

int[]
addControllerEventListener(ControllerEventListener listener, int[] controllers)
boolean
addMetaEventListener(MetaEventListener listener)
Add a meta event listening object to this sequencer.
void
close()
Close this MIDI device, and release any system resources we're using.
Info
getDeviceInfo()
Get the Info object describing this device.
static AlsaMidiSequencerDevice
getInstance()
Return the sequencer singleton.
SyncMode
getMasterSyncMode()
Get the source of timing information.
SyncMode[]
getMasterSyncModes()
Get an array of timing sources supported by this sequencer.
int
getMaxReceivers()
The maximum number of MIDI IN connections we can get as Receivers, or -1 if there is no maximum.
int
getMaxTransmitters()
The maximum number of MIDI OUT connections we can get as Transmitters, or -1 if there is no maximum.
long
getMicrosecondLength()
Get the length of the current sequence in microseconds.
long
getMicrosecondPosition()
Get the current playback position of the sequencer in microseconds.
Receiver
getReceiver()
Get a MIDI IN Receiver for this device.
Sequence
getSequence()
Get the current sequence object for this sequencer.
SyncMode
getSlaveSyncMode()
Get the current slave synchronization mode.
SyncMode[]
getSlaveSyncModes()
Get an array of slave sync modes supported by this sequencer.
float
getTempoFactor()
Get the current scaling factor for the playback tempo.
float
getTempoInBPM()
Get the current tempo in beats per minute.
float
getTempoInMPQ()
Get the current tempo in microseconds per quarter note.
long
getTickLength()
Get the length of the current sequence in MIDI ticks.
long
getTickPosition()
Get the current playback position of the sequencer in MIDI ticks.
boolean
getTrackMute(int track)
Get the mute state of a specific track.
boolean
getTrackSolo(int track)
Get the solo state for a specific track.
Transmitter
getTransmitter()
Get a MIDI OUT Transmitter for this device.
boolean
isOpen()
Returns true if this MIDI device is open and false otherwise.
boolean
isRecording()
Returns true if sequence is recording.
boolean
isRunning()
Returns true if the sequence is playing.
void
open()
Open this MIDI device and allocate any system resource we need.
void
recordDisable(Track track)
Disable recording for a specific track.
void
recordEnable(Track track, int channel)
Enable recording for a specific track using data from a specific channel.
int[]
removeControllerEventListener(ControllerEventListener listener, int[] controllers)
void
removeMetaEventListener(MetaEventListener listener)
Remove a meta event listener from this sequencer.
void
setMasterSyncMode(SyncMode sync)
void
setMicrosecondPosition(long microsecond)
Set the current playback position of the sequencer in microseconds.
void
setSequence(InputStream istream)
Set the sequence for this sequencer. istream reads on a valid MIDI file.
void
setSequence(Sequence seq)
Set the Sequence object for this sequencer.
void
setSlaveSyncMode(SyncMode sync)
void
setTempoFactor(float factor)
Set a scaling factor for the playback tempo, which is 1.0 by default.
void
setTempoInBPM(float bpm)
Sets the current tempo in beats per minute.
void
setTempoInMPQ(float mpq)
Sets the current tempo in microseconds per quarter note.
void
setTickPosition(long tick)
Set the current playback position of the sequencer in MIDI ticks.
void
setTrackMute(int track, boolean mute)
Sets the mute state for a specific track.
void
setTrackSolo(int track, boolean solo)
Sets the solo state for a specific track.
void
start()
Start playback of the current sequence.
void
startRecording()
Start playback and record of MIDI events.
void
stop()
Stop playback of the current sequence.
void
stopRecording()
Stop recording, although continue playing.

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Details

instance

public static final AlsaMidiSequencerDevice instance

Method Details

addControllerEventListener

public int[] addControllerEventListener(ControllerEventListener listener,
                                        int[] controllers)

addMetaEventListener

public boolean addMetaEventListener(MetaEventListener listener)
Add a meta event listening object to this sequencer. It will receive notification whenever the sequencer processes a meta event. A listener may fail to get added if this sequencer doesn't support meta events.
Specified by:
addMetaEventListener in interface Sequencer
Parameters:
listener - the listener to add
Returns:
true if listener was added, false othewise

close

public void close()
Close this MIDI device, and release any system resources we're using.
Specified by:
close in interface MidiDevice
close in interface AutoCloseable

getDeviceInfo

public Info getDeviceInfo()
Get the Info object describing this device.
Specified by:
getDeviceInfo in interface MidiDevice
Returns:
the Info object describing this device

getInstance

public static AlsaMidiSequencerDevice getInstance()
Return the sequencer singleton.
Returns:
the sequencer singleton

getMasterSyncMode

public SyncMode getMasterSyncMode()
Get the source of timing information.
Specified by:
getMasterSyncMode in interface Sequencer
Returns:
the current source of timing information

getMasterSyncModes

public SyncMode[] getMasterSyncModes()
Get an array of timing sources supported by this sequencer.
Specified by:
getMasterSyncModes in interface Sequencer
Returns:
an array of timing sources supported by this sequencer

getMaxReceivers

public int getMaxReceivers()
The maximum number of MIDI IN connections we can get as Receivers, or -1 if there is no maximum.
Specified by:
getMaxReceivers in interface MidiDevice
Returns:
-1 or the maximum number of Receivers we can get

getMaxTransmitters

public int getMaxTransmitters()
The maximum number of MIDI OUT connections we can get as Transmitters, or -1 if there is no maximum.
Specified by:
getMaxTransmitters in interface MidiDevice
Returns:
-1 or the maximum number of Transmitters we can get

getMicrosecondLength

public long getMicrosecondLength()
Get the length of the current sequence in microseconds.
Specified by:
getMicrosecondLength in interface Sequencer
Returns:
the length of the current sequence in microseconds

getMicrosecondPosition

public long getMicrosecondPosition()
Get the current playback position of the sequencer in microseconds.
Specified by:
getMicrosecondPosition in interface Sequencer
getMicrosecondPosition in interface MidiDevice
Returns:
the current playback position of the sequencer in microseconds

getReceiver

public Receiver getReceiver()
            throws MidiUnavailableException
Get a MIDI IN Receiver for this device.
Specified by:
getReceiver in interface MidiDevice
Returns:
a MIDI IN Receiver for this device
Throws:
MidiUnavailableException - if we can't get a Receiver

getSequence

public Sequence getSequence()
Get the current sequence object for this sequencer.
Specified by:
getSequence in interface Sequencer
Returns:
the current sequence object. May be null.

getSlaveSyncMode

public SyncMode getSlaveSyncMode()
Get the current slave synchronization mode.
Specified by:
getSlaveSyncMode in interface Sequencer
Returns:
the current slave synchronization mode

getSlaveSyncModes

public SyncMode[] getSlaveSyncModes()
Get an array of slave sync modes supported by this sequencer.
Specified by:
getSlaveSyncModes in interface Sequencer
Returns:
an array of slave sync modes supported by this sequencer

getTempoFactor

public float getTempoFactor()
Get the current scaling factor for the playback tempo.
Specified by:
getTempoFactor in interface Sequencer
Returns:
the current tempo scaling factor

getTempoInBPM

public float getTempoInBPM()
Get the current tempo in beats per minute.
Specified by:
getTempoInBPM in interface Sequencer
Returns:
the current tempo in beats per minute

getTempoInMPQ

public float getTempoInMPQ()
Get the current tempo in microseconds per quarter note.
Specified by:
getTempoInMPQ in interface Sequencer
Returns:
the current tempo in microseconds per quarter note.

getTickLength

public long getTickLength()
Get the length of the current sequence in MIDI ticks.
Specified by:
getTickLength in interface Sequencer
Returns:
the length of the current sequence in MIDI ticks

getTickPosition

public long getTickPosition()
Get the current playback position of the sequencer in MIDI ticks.
Specified by:
getTickPosition in interface Sequencer
Returns:
the current playback position of the sequencer in MIDI ticks

getTrackMute

public boolean getTrackMute(int track)
Get the mute state of a specific track.
Specified by:
getTrackMute in interface Sequencer
Parameters:
track - the track to query
Returns:
the mute state for track

getTrackSolo

public boolean getTrackSolo(int track)
Get the solo state for a specific track.
Specified by:
getTrackSolo in interface Sequencer
Parameters:
track - the track to query
Returns:
the solo state for track

getTransmitter

public Transmitter getTransmitter()
            throws MidiUnavailableException
Get a MIDI OUT Transmitter for this device.
Specified by:
getTransmitter in interface MidiDevice
Returns:
a MIDI OUT Transmitter for this device
Throws:
MidiUnavailableException - if we can't get a Transmitter

isOpen

public boolean isOpen()
Returns true if this MIDI device is open and false otherwise.
Specified by:
isOpen in interface MidiDevice
Returns:
true if this is open, false otherwise

isRecording

public boolean isRecording()
Returns true if sequence is recording.
Specified by:
isRecording in interface Sequencer
Returns:
true if the sequence is recording and false otherwise

isRunning

public boolean isRunning()
Returns true if the sequence is playing.
Specified by:
isRunning in interface Sequencer
Returns:
true if the sequence is playing and false otherwise

open

public void open()
            throws MidiUnavailableException
Open this MIDI device and allocate any system resource we need.
Specified by:
open in interface MidiDevice
Throws:
MidiUnavailableException - if we're not able to open for some reason

recordDisable

public void recordDisable(Track track)
Disable recording for a specific track.
Specified by:
recordDisable in interface Sequencer
Parameters:
track - the track to disable recording for

recordEnable

public void recordEnable(Track track,
                         int channel)
Enable recording for a specific track using data from a specific channel.
Specified by:
recordEnable in interface Sequencer
Parameters:
track - the track to enable for recording
channel - the channel from which to record

removeControllerEventListener

public int[] removeControllerEventListener(ControllerEventListener listener,
                                           int[] controllers)

removeMetaEventListener

public void removeMetaEventListener(MetaEventListener listener)
Remove a meta event listener from this sequencer.
Specified by:
removeMetaEventListener in interface Sequencer
Parameters:
listener - the listener to remove

setMasterSyncMode

public void setMasterSyncMode(SyncMode sync)

setMicrosecondPosition

public void setMicrosecondPosition(long microsecond)
Set the current playback position of the sequencer in microseconds.
Specified by:
setMicrosecondPosition in interface Sequencer
Parameters:
microsecond - the new playback position of the sequencer in microseconds

setSequence

public void setSequence(InputStream istream)
            throws IOException,
                   InvalidMidiDataException
Set the sequence for this sequencer. istream reads on a valid MIDI file.
Specified by:
setSequence in interface Sequencer
Parameters:
istream - an input stream for a valid MIDI file
Throws:
IOException - if an I/O exception happens
InvalidMidiDataException - if the MIDI file contains bad data

setSequence

public void setSequence(Sequence seq)
            throws InvalidMidiDataException
Set the Sequence object for this sequencer.
Specified by:
setSequence in interface Sequencer
Parameters:
seq - the Sequence to process
Throws:
InvalidMidiDataException - if the sequence is invalid for any reason

setSlaveSyncMode

public void setSlaveSyncMode(SyncMode sync)

setTempoFactor

public void setTempoFactor(float factor)
Set a scaling factor for the playback tempo, which is 1.0 by default.
Specified by:
setTempoFactor in interface Sequencer
Parameters:
factor - the new tempo scaling factor

setTempoInBPM

public void setTempoInBPM(float bpm)
Sets the current tempo in beats per minute.
Specified by:
setTempoInBPM in interface Sequencer
Parameters:
bpm - the new tempo in bears per minutes

setTempoInMPQ

public void setTempoInMPQ(float mpq)
Sets the current tempo in microseconds per quarter note.
Specified by:
setTempoInMPQ in interface Sequencer
Parameters:
mpq - the new tempo in microseconds per quarter note.

setTickPosition

public void setTickPosition(long tick)
Set the current playback position of the sequencer in MIDI ticks.
Specified by:
setTickPosition in interface Sequencer
Parameters:
tick - the new playback position of the sequencer in MIDI ticks

setTrackMute

public void setTrackMute(int track,
                         boolean mute)
Sets the mute state for a specific track.
Specified by:
setTrackMute in interface Sequencer
Parameters:
track - the track to modify
mute - the new mute state

setTrackSolo

public void setTrackSolo(int track,
                         boolean solo)
Sets the solo state for a specific track.
Specified by:
setTrackSolo in interface Sequencer
Parameters:
track - the track to modify
solo - the new solo state

start

public void start()
Start playback of the current sequence.
Specified by:
start in interface Sequencer

startRecording

public void startRecording()
Start playback and record of MIDI events. Any tracks enabled for recording will have their events replaced. Any newly recorded events, and all events from non-recording tracks will be sent to the sequencer's transmitter.
Specified by:
startRecording in interface Sequencer

stop

public void stop()
Stop playback of the current sequence.
Specified by:
stop in interface Sequencer

stopRecording

public void stopRecording()
Stop recording, although continue playing.
Specified by:
stopRecording in interface Sequencer

AlsaMidiSequencerDevice.java -- The ALSA MIDI sequencer device Copyright (C) 2005, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.