Compare commits
No commits in common. "mistress" and "mistress" have entirely different histories.
|
@ -1,5 +1,5 @@
|
|||
[package]
|
||||
name = "bwowww"
|
||||
name = "synth-notifications"
|
||||
version = "0.1.0"
|
||||
authors = ["Agatha Rose <agatharose@wantscuddl.es>"]
|
||||
edition = "2018"
|
||||
|
@ -7,7 +7,6 @@ edition = "2018"
|
|||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
clap = "2.33.3"
|
||||
dbus = "0.9.3"
|
||||
midi-control = "0.2.0"
|
||||
midir = "0.7.0"
|
||||
|
|
40
src/main.rs
40
src/main.rs
|
@ -3,7 +3,6 @@ use std::{
|
|||
time::Duration,
|
||||
};
|
||||
|
||||
use clap::clap_app;
|
||||
use dbus::blocking::Connection;
|
||||
use dbus::message::MatchRule;
|
||||
use dbus::Message;
|
||||
|
@ -11,39 +10,13 @@ use dbus::{arg::messageitem::MessageItem, channel::MatchingReceiver};
|
|||
use midi_control::*;
|
||||
use midir::*;
|
||||
|
||||
struct BwowwwConfig {
|
||||
browser: String,
|
||||
port: usize,
|
||||
}
|
||||
|
||||
fn parse_cli_opts() -> BwowwwConfig {
|
||||
let matches = clap_app!(bwowww =>
|
||||
(version: "1.0")
|
||||
(author: "Agatha Rose <agatharose@wantscuddl.es>")
|
||||
(@arg BROWSER: -b --browser +takes_value "Set a custom browser")
|
||||
(@arg PORT: -p --port +takes_value "Select a MIDI port")
|
||||
)
|
||||
.get_matches();
|
||||
|
||||
let browser = matches.value_of("BROWSER").unwrap_or("Nightly");
|
||||
let browser = browser.to_string();
|
||||
|
||||
let port = matches
|
||||
.value_of("PORT")
|
||||
.and_then(|s| s.parse().ok())
|
||||
.unwrap_or(1);
|
||||
|
||||
BwowwwConfig { browser, port }
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let conf = parse_cli_opts();
|
||||
|
||||
let midi_device = MidiOutput::new("synth output meow").expect("could not find device");
|
||||
let ports = midi_device.ports();
|
||||
// assumes that the device is connected on port 1
|
||||
// TODO: add port selection
|
||||
let midi_out = midi_device
|
||||
.connect(&ports[conf.port], "meow port")
|
||||
.connect(&ports[1], "meow port")
|
||||
.expect("oh dear");
|
||||
let midi_out = Arc::new(Mutex::new(midi_out));
|
||||
|
||||
|
@ -67,7 +40,7 @@ fn main() {
|
|||
conn.start_receive(
|
||||
rule,
|
||||
Box::new(move |msg, _| {
|
||||
midi_hook(&conf, midi_out.clone(), &msg);
|
||||
midi_hook(midi_out.clone(), &msg);
|
||||
true
|
||||
}),
|
||||
);
|
||||
|
@ -75,7 +48,7 @@ fn main() {
|
|||
// Start matching using old scheme
|
||||
rule.eavesdrop = true;
|
||||
conn.add_match(rule, move |_: (), _, msg| {
|
||||
midi_hook(&conf, midi_out.clone(), &msg);
|
||||
midi_hook(midi_out.clone(), &msg);
|
||||
true
|
||||
})
|
||||
.expect("add_match failed");
|
||||
|
@ -87,7 +60,7 @@ fn main() {
|
|||
// TODO: use the ctrlc crate to handle the midi connection closing
|
||||
}
|
||||
|
||||
fn midi_hook(conf: &BwowwwConfig, midi_out: Arc<Mutex<MidiOutputConnection>>, msg: &Message) {
|
||||
fn midi_hook(midi_out: Arc<Mutex<MidiOutputConnection>>, msg: &Message) {
|
||||
let args = msg.get_items();
|
||||
|
||||
// do nothing if args are empty
|
||||
|
@ -96,7 +69,8 @@ fn midi_hook(conf: &BwowwwConfig, midi_out: Arc<Mutex<MidiOutputConnection>>, ms
|
|||
}
|
||||
|
||||
// only apply to firefox notifications
|
||||
if args[0] == conf.browser.as_str().into() {
|
||||
// TODO: make browser name configurable
|
||||
if args[0] == "Nightly".into() {
|
||||
// get the dict of values inside the message's args
|
||||
let dict_values = match &args[6] {
|
||||
MessageItem::Dict(v) => v.clone().into_vec(),
|
||||
|
|
Loading…
Reference in New Issue