Maestro - Midi Player Tool Kit for Unity Version 2.18.2
Loading...
Searching...
No Matches
MidiPlayerTK.MPTKScaleLib

Build scales and play them with MidiStreamPlayer.
. More...

Static Public Member Functions

static MPTKScaleLib CreateScale (MPTKScaleName index, bool log=false)
 Gets a scale from an index. Scales are read from GammeDefinition.csv in Resources/GeneratorTemplate.

Public Attributes

int Index
 Position in the list (from the library).
string Name
 Long name of the scale.
string Short
 Short name of the scale.
string Flag
 Some indicator when available.
bool Main
 True for a common scale; otherwise, exotic.
int Count
 Number of notes in the scale.

Properties

int this[int index] [get]
 Indexer on an instance of this class.
Provides access to each interval in semitones from the tonic.
For a Major Melodic scale, each index returns 0, 2, 4, 5, 7, 9, 11. The first position (index=0) always returns 0 because it is the interval count from the tonic.
static int RangeCount [get]
 Number of available scales in the GammeDefinition.csv library in Resources/GeneratorTemplate.

Detailed Description

Build scales and play them with MidiStreamPlayer.
.

Version
Maestro Pro

See example in TestMidiStream.cs and ExtStreamPlayerPro.cs

// Need a reference to the prefab MidiStreamPlayer you have added in your scene hierarchy.
public MidiStreamPlayer midiStreamPlayer;
new void Start()
{
// Find the MidiStreamPlayer. It can also be set directly from the inspector.
midiStreamPlayer = FindFirstObjectByType<MidiStreamPlayer>();
}
private void PlayScale()
{
// Get the currently selected scale
MPTKRangeLib range = MPTKRangeLib.Range(CurrentScale, true);
for (int ecart = 0; ecart < range.Count; ecart++)
{
NotePlaying = new MPTKEvent()
{
Command = MPTKCommand.NoteOn, // MIDI command
Value = CurrentNote + range[ecart], // from 0 to 127, 48 for C3, 60 for C4, ...
Channel = StreamChannel, // from 0 to 15, 9 reserved for drum
Duration = DelayPlayScale, // note duration in milliseconds, -1 to play indefinitely, MPTK_StopEvent to stop
Velocity = Velocity, // from 0 to 127, sound can vary depending on the velocity
Delay = ecart * DelayPlayScale, // delay in milliseconds before playing the note
};
midiStreamPlayer.MPTK_PlayEvent(NotePlaying);
}
}
Represents a MIDI event used throughout MPTK. This class is central to script-based MIDI workflows in...
Definition MPTKEvent.cs:59
[MPTK PRO] Build Scale and Play with MidiStreamPlayer.
Definition MPTKRangeLib.cs:46
static MPTKRangeLib Range(int index, bool log=false)
Get a scale from an index. Scales are read from GammeDefinition.csv in folder Resources/GeneratorTemp...
Definition MPTKRangeLib.cs:120
int Count
Count of notes in the range.
Definition MPTKRangeLib.cs:78
Builds and plays real-time music in response to user actions or algorithmic logic....
Definition MidiStreamPlayer.cs:44
void MPTK_PlayEvent(MPTKEvent mptkEvent)
Plays one MIDI event from an instance of MPTKEvent. Runs in a thread so the call returns immediately....
Definition MidiStreamPlayer.cs:121
MPTKCommand
MIDI command codes. Defines the action performed by the message: note on/off, patch change,...
Definition MPTKEnum.cs:16

Member Function Documentation

◆ CreateScale()

MPTKScaleLib MidiPlayerTK.MPTKScaleLib.CreateScale ( MPTKScaleName index,
bool log = false )
static

Gets a scale from an index. Scales are read from GammeDefinition.csv in Resources/GeneratorTemplate.

Parameters
indexScale
log
Returns

Gets a scale from an index. Scales are read from GammeDefinition.csv in Resources/GeneratorTemplate.

Parameters
index
log
Returns

Member Data Documentation

◆ Flag

string MidiPlayerTK.MPTKScaleLib.Flag

Some indicator when available.

  • M = major scale
  • m = minor scale
  • _ = undetermined

Property Documentation

◆ this[int index]

int MidiPlayerTK.MPTKScaleLib.this[int index]
get

Indexer on an instance of this class.
Provides access to each interval in semitones from the tonic.
For a Major Melodic scale, each index returns 0, 2, 4, 5, 7, 9, 11. The first position (index=0) always returns 0 because it is the interval count from the tonic.

Parameters
indexIndex in the scale. If greater than interval count in the scale, the interval in semitones is taken from the next octave.
Returns
Interval in semitones from the tonic.
// Create a scale from the first scale found in the library: "Major melodic"
// Log enabled to display the content of the scale.
mptkScale = MPTKRangeLib.Range(indexScale:0, log:true);
Debug.Log(mptkScale[0]) // display 0
Debug.Log(mptkScale[4]) // display 7