Crates.io | midi_fundsp |
lib.rs | midi_fundsp |
version | 0.6.0 |
source | src |
created_at | 2022-12-05 02:29:32.856903 |
updated_at | 2024-10-05 22:47:42.165204 |
description | Enables creation of live MIDI synthesizer software. |
homepage | https://github.com/gjf2a/midi_fundsp |
repository | https://github.com/gjf2a/midi_fundsp |
max_upload_size | |
id | 729935 |
size | 112,976 |
This crate assembles and integrates code from the midir, midi-msg, and cpal crates to enable the easy creation of live synthesizer software using fundsp for sound synthesis.
Using the crate involves setting up the following:
SegQueue
that enables those threads to communicatePutting these pieces together yields the following introductory example program:
use std::sync::{Arc, Mutex};
use crossbeam_queue::SegQueue;
use crossbeam_utils::atomic::AtomicCell;
use midi_fundsp::{
io::{get_first_midi_device, start_input_thread, start_output_thread},
sounds::options,
};
use midir::MidiInput;
use read_input::{shortcut::input, InputBuild};
fn main() -> anyhow::Result<()> {
let mut midi_in = MidiInput::new("midir reading input")?;
let in_port = get_first_midi_device(&mut midi_in)?;
let midi_msgs = Arc::new(SegQueue::new());
let quit = Arc::new(AtomicCell::new(false));
start_input_thread(midi_msgs.clone(), midi_in, in_port, quit.clone());
start_output_thread::<10>(midi_msgs, Arc::new(Mutex::new(options())));
input::<String>().msg("Press any key to exit\n").get();
Ok(())
}
The first four lines set up:
The next two lines call start_input_thread()
and start_output_thread()
to
start the corresponding threads. The table of fundsp
sounds comes from midi_fundsp::sounds::options()
, but a user can easily assemble their
own custom table of sounds as well.
Once the threads start, the program continues until the user enters a key, handling any incoming MIDI events as they arrive.
Other example programs show how to send different sounds to the left and right stereo channels and how to change the selection of synthesizer sound and MIDI input device while running.
--release
. Sound quality is poor when compiled with --debug
.ProgramTable
Licensed under either of
at your option.
I am very interested in receiving contributions to this library. Here are types of contributions I envision, and how I would like contributors to proceed:
Fn(&SharedMidiState) -> Box<dyn AudioUnit64>
to sounds.rs
. Add your function and a suitable description to the table generated by options()
in that same file. Then make a pull request to include it.Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.