Package com.MIDI

Class MIDIPlayer

java.lang.Object
com.MIDI.MIDIPlayer

public final class MIDIPlayer
extends java.lang.Object
Class that knows how to play notes using the midi standard Copyright 2004 Georgia Institute of Technology
  • Field Summary

    Fields 
    Modifier and Type Field Description
    protected javax.sound.midi.MidiChannel channel  
    protected javax.sound.midi.MidiChannel[] channels  
    protected javax.sound.midi.Soundbank soundbank  
    protected javax.sound.midi.Synthesizer synth  
  • Constructor Summary

    Constructors 
    Constructor Description
    MIDIPlayer()
    Construct a MIDIPlayer object
  • Method Summary

    Modifier and Type Method Description
    void finalize()
    Can be called by the destructor to close the MIDI interface.
    static void main​(java.lang.String[] args)
    Placeholder main function for library testing.
    void playChord​(int[] notes, int duration, int intensity)
    Play a chord on the default channel
    void playChords​(int[] channelIndices, int[][] notes, int[] durations, int[][] intensities)
    Method to play an array of chords with the given durations and intensities
    void playNote​(int note, int duration, int intensity)
    Play a note on the default channel
    void playNotes​(int[] channelIndices, int[] notes, int[] durations, int[] intensities)
    Method to play an array of notes with the given durations and intensities
    static void rest​(int duration)
    Method to rest for a specified number of milliseconds
    void setChannel​(int i)
    Set a particular MIDI channel as the default for playing notes through this interface that do not request a channel parameter
    void setInstrument​(int num)
    Method to set the instrument to play on the default channel
    void setInstrument​(int num, int index)
    Method to set the instrument to play on a particular channel

    Methods inherited from class java.lang.Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • synth

      protected javax.sound.midi.Synthesizer synth
    • soundbank

      protected javax.sound.midi.Soundbank soundbank
    • channels

      protected javax.sound.midi.MidiChannel[] channels
    • channel

      protected javax.sound.midi.MidiChannel channel
  • Constructor Details

    • MIDIPlayer

      public MIDIPlayer()
      Construct a MIDIPlayer object
  • Method Details

    • setChannel

      public void setChannel​(int i)
      Set a particular MIDI channel as the default for playing notes through this interface that do not request a channel parameter
      Parameters:
      i - the index of the channel to set as the default
    • finalize

      public void finalize()
      Can be called by the destructor to close the MIDI interface.
      Overrides:
      finalize in class java.lang.Object
    • playNote

      public void playNote​(int note, int duration, int intensity)
      Play a note on the default channel
      Parameters:
      note - index of the note from the Notes class (60 is middle C)
      duration - duration of the note (i.e., Notes.NOTE_WHOLE or Notes.NOTE_QUARTER)
      intensity - intensity of the note
    • playChord

      public void playChord​(int[] notes, int duration, int intensity)
      Play a chord on the default channel
      Parameters:
      notes - an array of notes for the chord
      intensity - the intensity of the sound
      duration - the duration of the chord
    • playNotes

      public void playNotes​(int[] channelIndices, int[] notes, int[] durations, int[] intensities)
      Method to play an array of notes with the given durations and intensities
      Parameters:
      channelIndices - the array channel indices to use
      notes - the array of notes to play (0-127)
      durations - the array of durations to use for playing the notes in milliseconds
      intensities - the array of intensities (loudness)
    • playChords

      public void playChords​(int[] channelIndices, int[][] notes, int[] durations, int[][] intensities)
      Method to play an array of chords with the given durations and intensities
      Parameters:
      channelIndices - the array channel indices to use
      notes - the 2D array of chords to play (0-127)
      durations - the array of durations to use for playing the notes in milliseconds
      intensities - the 2D array of intensities (loudness)
    • rest

      public static void rest​(int duration)
      Method to rest for a specified number of milliseconds
      Parameters:
      duration - the amount to rest in milliseconds
    • setInstrument

      public void setInstrument​(int num, int index)
      Method to set the instrument to play on a particular channel
      Parameters:
      num - a number from 0 to 127 that represents the instrument
      index - the channel number
    • setInstrument

      public void setInstrument​(int num)
      Method to set the instrument to play on the default channel
      Parameters:
      num - a number from 0 to 127 that represents the instrument
    • main

      public static void main​(java.lang.String[] args)
      Placeholder main function for library testing. Do not call this method.
      Parameters:
      args - an array of command line argument strings