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 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
- webgl+javascript TTS
- Using Moonsharp (LUA) + Unity Webgl
- Using 3D gameobject prefabs with Unity Tilemap + NavMesh Surface
- Custom Unity Hub Project Template Preview Image/Video (using HTML+CSS in package description)
- Check if point is inside polygon 2D (using line intersection)
- UnityHub: Enable Create Project Button (without having to select Cloud Organization)
- UI: Make Tooltip background fit Text content length
- Pong-Wars in Unity
- Install Android SDK+JDK+NDK for Unity (without AndroidStudio or Unity Hub)
- UnityHub: Add support for custom project title (instead of folder name) or use ProductName
- Testing Unity MUSE AI
- QR Code Generator Online