23
2015
Play Midi Sounds with midi-dot-net dll

Instructions:
– Download midi-dot-net from https://code.google.com/p/midi-dot-net/ (from downloads section, midi-dot-net_1.1.0.zip)
– Unzip and copy “Midi.dll” into your unity project folder, Assets/Plugins/
– Create c# script and use the source below for testing
– Attach the script to gameobject in scene and hit play, should hear 1 note sound
– See the midi-dot-net examples & API for more info
Note:
– This library doesn’t support loading MIDI files!
– (probably works in Windows only)
Source:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // usage: copy Midi.dll to Assets/Plugins/ folder | |
| // Get it from https://code.google.com/p/midi-dot-net/ | |
| using UnityEngine; | |
| using System.Collections; | |
| using Midi; // needs this | |
| public class MidiSound : MonoBehaviour | |
| { | |
| OutputDevice outputDevice; | |
| void Start () | |
| { | |
| outputDevice = OutputDevice.InstalledDevices[0]; | |
| if (outputDevice.IsOpen) outputDevice.Close(); | |
| if (!outputDevice.IsOpen) outputDevice.Open(); | |
| // play note | |
| outputDevice.SendNoteOn(Channel.Channel1, Pitch.C4, 80); // Middle C, velocity 80 | |
| outputDevice.SendPitchBend(Channel.Channel1, 7000); // 8192 is centered, so 7000 is bent down | |
| } | |
| void OnDestroy () | |
| { | |
| if (outputDevice != null && outputDevice.IsOpen) outputDevice.Close(); | |
| } | |
| void OnDisable () | |
| { | |
| if (outputDevice != null && outputDevice.IsOpen) outputDevice.Close(); | |
| } | |
| } |
Related Posts
Leave a comment
Recent posts
- Editor Tool: Scene Size Analyzer
- LudumDare 60: Old Tech
- uBasic Scripting Language for Unity
- GreaseMonkey+Editor Plugin: 1-Click Copy script from ChatGPT (Web) to Unity Editor (as script)
- Editor Tool: Property Watcher
- .unityignore : Hide files from Project window
- PostBuild Script to Create Single exe Standalone File
- Game Loop Designer
- Favorites in PackageManager
- LudumDare59 : Signal
- Unity Editor: Tree Generator
- Leaf/Foliage Generator Tools (Runs in Browser)
Recent Comments
Coin:
CUgDSbRqFcAumDSAcdKDvuXsw26VdkJe8C8WGUQHBAGS
An article by











