Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/heyfrench/as3midilib
ActionScript 3.0 library for working with MIDI data.
https://github.com/heyfrench/as3midilib
Last synced: 2 months ago
JSON representation
ActionScript 3.0 library for working with MIDI data.
- Host: GitHub
- URL: https://github.com/heyfrench/as3midilib
- Owner: heyfrench
- Created: 2015-07-13T15:29:21.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-07-13T18:41:32.000Z (over 9 years ago)
- Last Synced: 2024-08-04T05:02:39.550Z (6 months ago)
- Language: ActionScript
- Homepage:
- Size: 1.01 MB
- Stars: 8
- Watchers: 1
- Forks: 1
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-actionscript-sorted - as3midilib - AS3 library for working with MIDI data. Can parse a stream of MIDI data into objects, or it can be used to connect to a MIDI socket server and receive live performance MIDI. It can also be used to parse MIDI files or stream them for performance syncing. (Networking / Protocols)
README
# Introduction
This is a library for working with MIDI in ActionScript 3.0. It can be manually used to parse a stream of MIDI data into objects, or it can be used to connect to a MIDI socket server and receive live performance MIDI. It can also be used to parse MIDI files or stream them for performance syncing.
## Receiving live performance MIDI
```as3
import com.newgonzo.midi.io.*;
import com.newgonzo.midi.*;
import com.newgonzo.midi.events.*;
import com.newgonzo.midi.messages.*;
import com.newgonzo.midi.filters.*;var connection:IMIDIConnection = new MIDISocketConnection();
// Only receive VoiceMessages
var voiceReceiver:MIDIReceiver = new MIDIReceiver(receiver, new VoiceFilter());
// add event listener...// Only receive messages on Channel 1
var channelReceiver:MIDIReceiver = new MIDIReceiver(receiver, new ChannelFilter([1]));
// add event listener...// Only receive TIMING_CLOCK SystemMessages
var clockReceiver:MIDIReceiver = new MIDIReceiver(receiver, new SystemFilter([SystemMessageType.TIMING_CLOCK]));
// add event listener...// Only receive NOTE_OFF VoiceMessages on Channel 3
var channel3NoteOffVoices:MIDIReceiver = new MIDIReceiver(receiver, new ChannelFilter([3], new StatusFilter(MessageStatus.NOTE_OFF, new VoiceFilter())));// listen to receivers for message events
channel3NoteOffVoices.addEventListener(MessageEvent.MESSAGE, messageReceived);// connect to the MIDI2.jar socket server
connection.connect("localhost", 10000);private function messageReceived(event:MessageEvent):void
{
trace(event.message); // [Message(status=...]
}
```## Syncing to MIDI clock
```as3
import com.newgonzo.midi.io.*;
import com.newgonzo.midi.messages.*;
import com.newgonzo.midi.events.*;var connection:IMIDIConnection = new MIDISocketConnection();
var clock:MIDIClock = new MIDIClock(connection);clock.addEventListener(ClockEvent.BEAT, midiBeat);
clock.addEventListener(ClockEvent.POSITION, midiPosition);
clock.addEventListener(ClockEvent.START, midiStartStop);
clock.addEventListener(ClockEvent.STOP, midiStartStop);// connect to MIDI2.jar socket server
connection.connect("127.0.0.1", 10000);// event handling functions
```## Reading a MIDI file
```as3
import com.newgonzo.midi.MIDIDecoder;
import com.newgonzo.midi.file.*;// assuming you've loaded your MIDI file into a
// ByteArray via URLLoader, FileStream (AIR), etc.
var midiData:ByteArray;var decoder:MIDIDecoder = new MIDIDecoder();
var file:MIDIFile = decoder.decodeFile(midiData);// a MIDI file has an array of tracks that each contain an array of track events
var track:MIDITrack;
var event:MIDITrackEvent;
for each(track in file.tracks)
{
for each(event in track.events)
{
trace("event.time: " + event.time);
trace("event.message: " + event.message); // [Message(status=...]
}
}
```