Skip to content

Music Playback API

Coen Valk edited this page Aug 9, 2018 · 4 revisions

Introduction

The music playback API is used to add functionality for music playback at different speeds, dynamics and timbre. The intention of the music playback API is to be able to interface with the hand tracking API to alter all of these values based on hand movements, but it should be easily used to alter music playback with other inputs (for instance, keyboard shortcuts or with software that makes use of the API, such as in the test scripts.)

Documentation

Constructors

P = Playback():

Creates an empty object of type playback.

NOTE: this constructor mus be initialized before playback can start.

Params

N/A

Returns

P: New object of type Playback.

P = Playback(File, port=None):

Creates a Playback object and initializes it with file given.

Params

File: String path to .mid file to be read and played back.

port: String name of port to be used for music playback. Defaults to the first available midi through port

Returns

P: New object of type Playback.

Throws

IOError if file doesn't exist or is in the wrong format.

Initialization

Playback.init(File, port=None):

Initializes playback. Must occur before starting to play.

Params

File: String path to .mid file to be read and played back.

port: String name of port to be used for music playback.

Returns

N/A.

Throws

IOError: if file doesn't exist or is in the wrong format.

Playback.change_file(File):

Changes the input file for playback. starts playback at the beginning of the file.

Params

File: String path to .mid file to be read and played back.

Returns

N/A

Throws

IOError: if file doesn't exist or is in the wrong format.

Playback.change_port(port):

Changes port for music playback. Continues where previous playback left off.

Params

port: String name of port to be used for music playback.

Returns

N/A

Playback

Playback.start():

Starts playback of a correctly initialized Playback object in a new thread.

Params

N/A

Returns

N/A

Throws

IOError: If the playback object is not initialized with a mid. file.

Playback.stop():

Stops playback of a playback object

Params

N/A

Returns

N/A

Playback Manipulation

Playback.set_ticks_per_beat(ticks):

Sets the value of ticks per beat for playback of the midi file (explained in detail here)

Params

ticks: Integer value of ticks per beat.

Returns

N/A

Playback.set_dynamics(dynamic):

Sets the dynamics for playback of the midi file

Params

dynamic: Float between 0 and 1 for dynamics. 0 is silent and 1 is maximum volume.

Returns

N/A

Playback.next_beat(keep_tempo=False):

Skips to next beat for playback.

Params

keep_tempo: Boolean value whether to adopt the new tempo of playback (amount of time between the call and the previous beat). By default adopts new tempo, keep_tempo = True retains the old tempo.

Returns

N/A

Throws

EOFError: If the playback is finished.

ValueError: If playback has not started or is stopped.

Playback.next_measure(keep_tempo=False):

Skips to next measure for playback.

Params

keep_tempo: Boolean value whether to adopt the new tempo of playback (amount of time between the call and the start of the measure). By default adopts new tempo, keep_tempo = True retains the old tempo.

Returns

N/A

Throws

EOFError: If the playback is finished.

ValueError: If playback has not started or is stopped.