1 个不稳定版本
0.1.0 | 2019 年 9 月 28 日 |
---|
#81 in #io-read
35KB
707 代码行
open-sound-module
一个非官方库,提供用于与 Rebel Tech 的 Open Sound Module 一起工作的工具。
cv
cv 模块提供了创建和操作控制电压消息的类型。
extern crate open_sound_module;
use std::io::Read;
use open_sound_module::{CvMessage, CvAddress};
fn main() -> Result<(), failure::Error> {
let mut msg = CvMessage::new(CvAddress::A, -0.3);
let bytes = msg.to_vec();
let mut buf: [u8; 1024] = [0; 1024];
let n = msg.read(&mut buf)?;
assert!(n == 20);
Ok(())
}
trigger
trigger 模块提供了创建和操作触发消息的类型。
extern crate open_sound_module;
use std::io::Read;
use open_sound_module::{TriggerMessage, TriggerAddress};
fn main() -> Result<(), failure::Error> {
let mut msg = TriggerMessage::new(TriggerAddress::B, 1);
let bytes = msg.to_vec();
let mut buf: [u8; 1024] = [0; 1024];
let n = msg.read(&mut buf)?;
assert!(n == 20);
Ok(())
}
sequencer
sequencer 模块提供了一个基于 Iterator 的 OscMessageSequencer trait,可以用于发送一系列控制电压和触发消息。它还包括使用 sample::signal 的几个实现,这些实现代表了一些有用的波形。
extern crate open_sound_module;
use open_sound_module::OscMessageSequence;
use open_sound_module::SineSequence;
use open_sound_module::CvAddress;
use std::time;
fn main() -> Result<(), failure::Error> {
let rate = 4.0;
let hz = 1.0;
let seconds = time::Duration::from_secs(30);
let mut noise = SineSequence::new(CvAddress::A, rate, hz, seconds);
let _msg = noise.next();
let _delay = noise.delay();
Ok(())
}
client
client 模块提供了一个 Client 类型,用于简化在 Open Sound Control 协议中通过 UDP 发送 cv 和触发消息。
extern crate open_sound_module;
use open_sound_module::Client;
use open_sound_module::CvAddress;
use open_sound_module::OscMessage;
use open_sound_module::NoiseSequence;
use std::time;
fn main() -> Result<(), failure::Error> {
let client = Client::new("127.0.0.1:8888".to_string())?;
let msg = CvMessage::new(CvAddress::B, -1.0);
client.send_osc_message(OscMessage::CvMessage(msg))?;
let seed = 0;
let rate = 4.0;
let seconds = time::Duration::from_secs(1);
let mut noise = NoiseSequence::new(CvAddress::A, seed, rate, seconds);
client.send_sequence(&mut noise)?;
Ok(())
}
依赖关系
~4.5MB
~69K SLoC