Compare commits

..

No commits in common. "mistress" and "mistress" have entirely different histories.

2 changed files with 8 additions and 35 deletions

View File

@ -1,5 +1,5 @@
[package] [package]
name = "bwowww" name = "synth-notifications"
version = "0.1.0" version = "0.1.0"
authors = ["Agatha Rose <agatharose@wantscuddl.es>"] authors = ["Agatha Rose <agatharose@wantscuddl.es>"]
edition = "2018" edition = "2018"
@ -7,7 +7,6 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
clap = "2.33.3"
dbus = "0.9.3" dbus = "0.9.3"
midi-control = "0.2.0" midi-control = "0.2.0"
midir = "0.7.0" midir = "0.7.0"

View File

@ -3,7 +3,6 @@ use std::{
time::Duration, time::Duration,
}; };
use clap::clap_app;
use dbus::blocking::Connection; use dbus::blocking::Connection;
use dbus::message::MatchRule; use dbus::message::MatchRule;
use dbus::Message; use dbus::Message;
@ -11,39 +10,13 @@ use dbus::{arg::messageitem::MessageItem, channel::MatchingReceiver};
use midi_control::*; use midi_control::*;
use midir::*; 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() { fn main() {
let conf = parse_cli_opts();
let midi_device = MidiOutput::new("synth output meow").expect("could not find device"); let midi_device = MidiOutput::new("synth output meow").expect("could not find device");
let ports = midi_device.ports(); let ports = midi_device.ports();
// assumes that the device is connected on port 1 // assumes that the device is connected on port 1
// TODO: add port selection
let midi_out = midi_device let midi_out = midi_device
.connect(&ports[conf.port], "meow port") .connect(&ports[1], "meow port")
.expect("oh dear"); .expect("oh dear");
let midi_out = Arc::new(Mutex::new(midi_out)); let midi_out = Arc::new(Mutex::new(midi_out));
@ -67,7 +40,7 @@ fn main() {
conn.start_receive( conn.start_receive(
rule, rule,
Box::new(move |msg, _| { Box::new(move |msg, _| {
midi_hook(&conf, midi_out.clone(), &msg); midi_hook(midi_out.clone(), &msg);
true true
}), }),
); );
@ -75,7 +48,7 @@ fn main() {
// Start matching using old scheme // Start matching using old scheme
rule.eavesdrop = true; rule.eavesdrop = true;
conn.add_match(rule, move |_: (), _, msg| { conn.add_match(rule, move |_: (), _, msg| {
midi_hook(&conf, midi_out.clone(), &msg); midi_hook(midi_out.clone(), &msg);
true true
}) })
.expect("add_match failed"); .expect("add_match failed");
@ -87,7 +60,7 @@ fn main() {
// TODO: use the ctrlc crate to handle the midi connection closing // 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(); let args = msg.get_items();
// do nothing if args are empty // 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 // 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 // get the dict of values inside the message's args
let dict_values = match &args[6] { let dict_values = match &args[6] {
MessageItem::Dict(v) => v.clone().into_vec(), MessageItem::Dict(v) => v.clone().into_vec(),