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
- MotionVector Effect: Object “disappears” when paused
- [GreaseMonkey] Unity Forum Fixer
- UnityHub: Make Hub application background Translucent
- Customize SpriteShapeRenderer quality (but has issues)
- Editor tool: Copy selected gameobject’s names into clipboard as rows (for Excel)
- Editor tool: Replace string in selected gameobject’s names
- UnityHub: Enable built-in Login Dialog (no more browser login/logout issues!)
- Use TikTok-TTS in Unity (with WebRequest)
- Create Scene Thumbnail Image using OnSceneSaved & OnPreviewGUI
- webgl+javascript TTS
- Using Moonsharp (LUA) + Unity Webgl
- Using 3D gameobject prefabs with Unity Tilemap + NavMesh Surface
Recent Comments
- [Asset Store] Point Cloud Viewer & Tools on
- [Asset Store] Point Cloud Viewer & Tools on
- Vector3 maths for dummies! on
- UnityHub: Make Hub application background Translucent on
- UnityHub: Make Hub application background Translucent on
- Install Android SDK+JDK+NDK for Unity (without AndroidStudio or Unity Hub) on
- Install Android SDK+JDK+NDK for Unity (without AndroidStudio or Unity Hub) on
- [Asset Store] Point Cloud Viewer & Tools on