B4J Library jSimpleMidiPlayer

Here is a Simple Midi Player for use with B4j.


jSimpleMidiPlayer
Author:
Steve Laming
Version: 1.0

  • Methods:
    • Close
      Closes the device, indication it should now release any system resources it is using.

      GetDivisionType As Float
      Obtains the timing division type for this sequence.
      Can be one of:
      PPQ The tempo-based timing type, for which the resolution is expressed in pulses (ticks) per quarter note.
      SMPTE_24 The SMPTE-based timing type with 24 frames per second (resolution is expressed in ticks per frame).
      SMPTE_25 The SMPTE-based timing type with 25 frames per second (resolution is expressed in ticks per frame).
      SMPTE_30 The SMPTE-based timing type with 30 frames per second (resolution is expressed in ticks per frame).
      SMPTE_30DROP The SMPTE-based timing type with 29.97 frames per second (resolution is expressed in ticks per frame).


      GetLoopEndPoint As long
      Obtains the end position of the loop, in MIDI ticks.

      GetLoopStartPoint As long
      Obtains the start position of the loop, in MIDI ticks.

      GetMicrosecondLength As long
      Obtains the length of the current sequence, expressed in microseconds.

      GetMicrosecondPosition As long
      Obtains the current position in the sequence, expressed in microseconds.

      GetResolution As Int
      Obtains the timing resolution for this sequence.

      GetTempoInBPM As Float
      Obtains the current tempo, expressed in beats per minute.

      Initialize(FilePath As String, FileName As String) As Boolean


      Isinitialized As Boolean


      IsRunning As Boolean
      Indicates whether the Sequencer is currently running.

      LastErrorMessage As String
      Get the message for the last error the player encountered

      SetLoopCount(count As Int)
      Sets the number of repetitions of the loop for playback.

      SetLoopEndPoint(tick As long)
      Sets the last MIDI tick that will be played in the loop.

      SetLoopStartPoint(tick As long)
      Sets the first MIDI tick that will be played in the loop.

      SetMicrosecondPosition(microseconds As long)
      Sets the current position in the sequence, expressed in microseconds

      Start
      Starts playback of the MIDI data in the currently loaded sequence.

      Stop
      Stops recording, if active, and playback of the currently loaded sequence, if any[/B]
At it's simplest the code to play a midi file would be:

B4X:
SMP.Initialize(InitialFilePath,MidiFileName)
SMP.Start

It's useful to build in some error handling, so the practical code would be:

B4X:
    SMP.Initialize(InitialFilePath,MidiFileName)
    If SMP.Isinitialized = False Then
        msgbox.Show(SMP.LastErrorMessage,"Midi Initialization Error")
    Else
        SMP.Start
End If

The demo app implements looping and shows how to convert time into midi ticks, and depends on:

JavaObject
jMsgBoxes

The library has no external dependencies.

V1.1 Added Close Method
 

Attachments

  • jSimpleMidiPLayerLibV1-1.zip
    4.1 KB · Views: 533
  • SimpleMidiPlayerV1-1.zip
    3 KB · Views: 523
Last edited:

stevel05

Expert
Licensed User
Longtime User
V1.1 available for download added the all important Close method.
 
Top