Midi Playback
You can play back MIDI data along with an audio track to control anything you want in your Udon world. You can jump to the Example Scene to get started right away.
Assets: MidiFile and AudioClip
Files with the extension .mid are processed as MIDI assets. To get started with your own MIDI and Audio files:
- Drag and drop them somewhere into your Assets folder. The MIDI file must have the extension .mid, the audio file can be of any type supported by Unity (.aif, .wav, .mp3, .ogg).
- Select the MIDI file and set its AudioClip to the matching audio file.
- It's imperative that the BPM for your MIDI file is set correctly. If the data seems like it doesn't match the audio, this is likely the issue. You can override the BPM here by toggling on "Override Bpm" and supplying the right value. Even better would be to edit your MIDI file and add the correct BPM.
Component: VRCMidiPlayer
This is the brains of the operation. It works similarly to an Audio Source but uses a Midi Asset instead. It sends MIDI Note On and Note Off events to all target UdonBehaviours.
Inspector Fields
- Midi File
- The MIDI file in SMF format whose data you want to trigger.
- Audio Source
- The AudioSource component with the audio clip corresponding to your MIDI data.
- Target Behaviours
- An array of UdonBehaviours which will have MIDI Note On and Note Off events sent to them
- Display Debug Blocks
- When enabled, you can see a display of all the notes in your current MIDI file in the Scene View of the Unity Editor while the VRCMidiPlayer is selected. Helpful for a quick view into your data.
Methods
- Play()
- Starts the playback of MIDI events and the Audio Source.
- Stop()
- Stops the playback of MIDI events and the Audio Source.
Properties
float
time- Set and Get the current time of both the MIDI and Audio sources.
MidiData
midiData- Get a MidiData object containing all data about the current MIDI track. Can be used before playback to set things up.
Example: MidiPlaybackScene
The SDK includes a simple MIDI playback example. You can load it from the menu bar under VRChat SDK > Samples > MidiPlayback.
After loading the scene, press 'Play' in Unity to see and hear the MIDI playback! As the short loop plays, differently colored images will flash in time with the music.
The important objects in the scene are the VRCMidiPlayer and the MidiGrid.
VRCMidiPlayer
This GameObject has a VRCMidiPlayer component as well as an AudioSource, and they're all set up with an example MIDI File and AudioClip. It has the MidiGrid set as its one and only targetBehaviour.
MidiGrid
This GameObject has an UdonBehaviour for receiving MIDI Events, and several Canvases as children.
Each Canvas has a "Grid" with 12 child Image components. These Images will be enabled and disabled when MIDI notes are played. An octave has 12 notes in it, so this allows visualizing each note as a separate Image.