Crate lyrica

source ·
Expand description

Phantasmically simple MIDI file handling.

Quoth Merriam-Webster:

Definition of phantasm

1: a product of fantasy: such as

a: delusive appearance : ILLUSION

This crate provides the illusion of MIDI being really easy to work with rather than a pain in your rear. As a tradeoff, it’s fairly inflexible, and only works with MIDI files.

Here’s what Lyrica can do with your MIDI files:

  • Play
  • Pause!
  • Loop!!
  • Switch to a different file!!!

… all without blocking the thread! Now how much do you think Lyrica is worth? Don’t answer!

Example

use lyrica::{MidiFile, MidiOutput, MidiPlayer}
use std::{fs, thread, time::Duration};

let midi_output = MidiOutput::new("lyrica-example")?;
// NOTE: it's entirely possible that there could be no ports at all (eg. on Wine).
// This is glossed over for the sake of exposition.
let port = midi_output.ports()[0];
let connection = midi_output.connect(&port, "lyrica-example")?;
let midi_bytes = fs::read("phantom_ensemble.midi")?;
let midi_file = MidiFile::from_bytes(&midi_bytes)?;
let mut player = MidiPlayer::new(connection);
player.set_midi_file(midi_file)?;

while !player.is_finished() {
    player.update()?;
}

Re-exports

Modules

Structs

  • An instance of MidiOutput is required for anything related to MIDI output. Create one with MidiOutput::new.
  • Represents an open connection to a MIDI output port.
  • An object representing a single output port. How the port is identified internally is backend-dependent. If the backend allows it, port objects remain valid when other ports in the system change (i.e. it is not just an index).

Enums