minuit ~master

Midi library


To use this package, run the following command in your project's root directory:

Minuit

Minuit is a simple midi library for Windows and Linux in D.

Fetch port list

To get a list of all available midi ports, use mnFetchOutputs for midi output ports or mnFetchInputs for midi input ports.

import std.stdio;
import minuit;

void main(string[] args) {
  MnOutputPort[] outputPorts = mnFetchOutputs();

  writeln("List of output ports:");
  foreach(MnOutputPort port; outputPorts) {
    writeln(port.name);
  }
  
  MnInputPort[] inputPorts = mnFetchInputs();

  writeln("List of input ports:");
  foreach(MnInputPort port; inputPorts) {
    writeln(port.name);
  }
}

You can also directly fetch the names of the ports with mnFetchOutputsName and mnFetchInputsName.

import std.stdio;
import minuit;

void main(string[] args) {
  writeln("List of output ports: ", mnFetchOutputsName());
  writeln("List of input ports: ", mnFetchInputsName());
}

Open and close a port

Simply use mnOpenInput or mnOpenOutput with your port, it'll return you an handle to use the port. You can close it with mnCloseInput or mnCloseOutput by passing it the handle.

import minuit;

void main(string[] args) {
  MnOutputPort[] outputPorts = mnFetchOutputs();
  if(!outputPorts.length)
    return;
  //Open the port.
  MnOutputHandle output = mnOpenOutput(outputPorts[0]);
  
  //Use the output here...
  
  //Then close it.
  mnCloseOutput(output);
}

You can also open a port with its name or its index with the same function like:

MnOutputHande output1 = mnOpenOutput("SD-90 PART A");
MnOutputHande output2 = mnOpenOutput(0);
MnInputHandle input1 = mnOpenInput("Focusrite USB MIDI");
MnInputHandle input2 = mnOpenInput(0);

Send a message

Note (Version 0.1.1): On Linux, you cannot receive on a MnInputHandle yet (working on it). Note (Version 0.1.1): On Windows, you won't be able to receive messages more than 4 bytes long (like SysEx) (working on it).

Use mnSendOutput with your handle and up to 4 bytes of data, or an array of bytes.

MnOutputHandle output = mnOpenOutput(0);

//Note On
mnSendOutput(output, 0x90, 0x41, 0x64); //Up to 4 bytes

//Note Off
mnSendOutput(output, [0x80, 0x41, 0x64]); //Or an array (no limit)

Receive a message

To receive, you can use mnCanReceiveInput to check whether there is messages to be read. Then you can use mnReceiveInput to get the actual message.

MnInputHandle input = mnOpenInput(0);

while(true) {
  if(mnCanReceiveInput(input)) {
    writeln(mnReceiveInput(input));
  }
  //sleep...
}

MnInput and MnOutput

These are classes that do everything above but within a class. The methods are open, close, send, canReceive, receive, etc.

Authors:
  • Enalye
Sub packages:
minuit:test
Dependencies:
none
Versions:
0.1.1 2019-Sep-01
0.1.0 2019-Aug-26
0.0.2 2018-May-29
0.0.1 2018-May-09
~master 2019-Sep-09
Show all 5 versions
Download Stats:
  • 2 downloads today

  • 6 downloads this week

  • 10 downloads this month

  • 15 downloads total

Score:
0.1
Short URL:
minuit.dub.pm