Skip to content

API Sampler

LenweSaralonde edited this page Sep 17, 2022 · 5 revisions

Sampler engine

Functions

Musician.Sampler.Init

Init sampler engine

Musician.Sampler.Init()

Musician.Sampler.NoteName

Return the note name corresponding its MIDI key

name = Musician.Sampler.NoteName(key)

Arguments

  • key (int) MIDI key index

Returns

  • name (string) from Musician.NOTE_NAMES

Musician.Sampler.NoteKey

Return the MIDI key of the note name

key = Musician.Sampler.NoteKey(noteName)

Arguments

  • noteName (string) from Musician.NOTE_NAMES

Returns

  • key (int)

Musician.Sampler.GetInstrumentName

Return instrument name from its MIDI ID and key number

instrumentName = Musician.Sampler.GetInstrumentName(instrument, key)

Arguments

  • instrument (int) MIDI instrument ID
  • key (int) Only needed to get the final instrument name for traditional percussions (optional)

Returns

  • instrumentName (string) used as key in Musician.INSTRUMENTS

Musician.Sampler.GetLocalizedMIDIInstrumentName

Return localized General MIDI instrument name

localizedInstrumentName = Musician.Sampler.GetLocalizedMIDIInstrumentName(instrument)

Arguments

  • instrument (int)

Returns

  • localizedInstrumentName (string)

Musician.Sampler.GetInstrumentData

Return instrument data for given MIDI key number

instrumentData = Musician.Sampler.GetInstrumentData(instrumentName, key)

Arguments

  • instrumentName (string)
  • key (int) MIDI key number

Returns

  • instrumentData (table) from Musician.INSTRUMENTS

Musician.Sampler.GetSoundFile

Get the path to a sound file for an instrument and a key.

Also returns the instrument data from Musician.INSTRUMENTS

and all other suitable sound file paths for randomization.

soundFile, instrumentData, soundFiles = Musician.Sampler.GetSoundFile(instrument, key)

Arguments

  • instrument (int|string|table) MIDI instrument index, instrument name or instrument data
  • key (int) MIDI key

Returns

  • soundFile (string|nil) file path to be played
  • instrumentData (table|nil) from Musician.INSTRUMENTS
  • soundFiles (table|nil) all possible file paths for this instrument and note, when applicable

Musician.Sampler.IsInstrumentPlucked

Returns true if the provided instrument is "plucked".

isPlucked = Musician.Sampler.IsInstrumentPlucked(instrument)

Arguments

  • instrument (int) MIDI instrument ID

Returns

  • isPlucked (boolean)

Musician.Sampler.PlayNote

Start playing a note

handle, willPlay = Musician.Sampler.PlayNote(instrument, key, loopNote, track, player)

Arguments

  • instrument (int|string|table) MIDI instrument index, instrument name or instrument data
  • key (int) Note MIDI key
  • loopNote (boolean) The note sample should be looped (long note or live note)
  • track (table) The track the note comes from (optional)
  • player (string) The normalized name of the player who plays the note (optional)

Returns

  • handle (int)
  • willPlay (boolean)

Musician.Sampler.StopNote

Stop playing note

Musician.Sampler.StopNote(handle, decay)

Arguments

  • handle (int) The note handle returned by PlayNote()
  • decay (number) Override instrument decay (optional)

Musician.Sampler.OnUpdate

Main on frame update function

Musician.Sampler.OnUpdate()

Musician.Sampler.StopOldestNote

Stop playing the oldest note to release a polyphony slot

Musician.Sampler.StopOldestNote()

Musician.Sampler.GetSampleId

Return sample ID for note and instrument data

sampleId = Musician.Sampler.GetSampleId(instrumentData, key)

Arguments

  • instrumentData (table) as returned by Musician.Sampler.GetInstrumentData()
  • key (int) MIDI key number

Returns

  • sampleId (string)

Musician.Sampler.SetMuted

Set global mute state

Musician.Sampler.SetMuted(isMuted)

Arguments

  • isMuted (boolean)

Musician.Sampler.GetMuted

Return global mute state

isMuted = Musician.Sampler.GetMuted()

Returns

  • isMuted (boolean)

Clone this wiki locally