Implement basic toml-config parsing & serialzation
This commit is contained in:
parent
4559d72ffd
commit
1b49c08eb1
2 changed files with 119 additions and 13 deletions
115
src/config.rs
Normal file
115
src/config.rs
Normal file
|
@ -0,0 +1,115 @@
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use std::{collections::BTreeMap, fmt::Debug};
|
||||||
|
use toml::ser::Error;
|
||||||
|
|
||||||
|
pub fn default() -> Result<String, Error> {
|
||||||
|
let mut applications = BTreeMap::new();
|
||||||
|
applications.insert("Feishin".to_string(), "Feishin".to_string());
|
||||||
|
applications.insert("Librewolf".to_string(), "Librewolf".to_string());
|
||||||
|
let mut keymap = BTreeMap::new();
|
||||||
|
keymap.insert(
|
||||||
|
NanoKeys::Param4Mute,
|
||||||
|
"program-mute/Feishin,Librewolf".to_string(),
|
||||||
|
);
|
||||||
|
let mut audioinputs = BTreeMap::new();
|
||||||
|
audioinputs.insert(
|
||||||
|
"headphones".to_string(),
|
||||||
|
"alsa_output.usb-Burr-Brown_from_TI_USB_Audio_CODEC-00.pro-output-0".to_string(),
|
||||||
|
);
|
||||||
|
audioinputs.insert(
|
||||||
|
"speakers".to_string(),
|
||||||
|
"alsa_output.pci-0000_0c_00.4.analog-stereo".to_string(),
|
||||||
|
);
|
||||||
|
let audiooutputs = BTreeMap::new();
|
||||||
|
let conf: Config = Config {
|
||||||
|
general: General {
|
||||||
|
nano_kontrol_pattern: "nanoKONTROL2".to_string(),
|
||||||
|
led_mode: LedMode::Toggle,
|
||||||
|
},
|
||||||
|
applications,
|
||||||
|
keymap,
|
||||||
|
audioinputs,
|
||||||
|
audiooutputs,
|
||||||
|
};
|
||||||
|
toml::to_string(&conf)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
pub struct Config {
|
||||||
|
pub general: General,
|
||||||
|
pub audioinputs: BTreeMap<String, String>,
|
||||||
|
pub audiooutputs: BTreeMap<String, String>,
|
||||||
|
pub applications: BTreeMap<String, String>,
|
||||||
|
pub keymap: BTreeMap<NanoKeys, String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
pub struct General {
|
||||||
|
#[serde(rename = "nanoKONTROLPattern")]
|
||||||
|
pub nano_kontrol_pattern: String,
|
||||||
|
#[serde(rename = "ledMode")]
|
||||||
|
pub led_mode: LedMode,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
pub enum LedMode {
|
||||||
|
Default,
|
||||||
|
Toggle,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
|
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
|
||||||
|
pub enum NanoKeys {
|
||||||
|
TrackPrev = 58,
|
||||||
|
TrackNext = 59,
|
||||||
|
Cycle = 46,
|
||||||
|
MarkerSet = 60,
|
||||||
|
MarkerPrev = 61,
|
||||||
|
MarkerNext = 62,
|
||||||
|
Prev = 43,
|
||||||
|
Next = 44,
|
||||||
|
Stop = 42,
|
||||||
|
Play = 41,
|
||||||
|
Record = 45,
|
||||||
|
Param1Solo = 32,
|
||||||
|
Param2Solo = 33,
|
||||||
|
Param3Solo = 34,
|
||||||
|
Param4Solo = 35,
|
||||||
|
Param5Solo = 36,
|
||||||
|
Param6Solo = 37,
|
||||||
|
Param7Solo = 38,
|
||||||
|
Param8Solo = 39,
|
||||||
|
Param1Mute = 48,
|
||||||
|
Param2Mute = 49,
|
||||||
|
Param3Mute = 50,
|
||||||
|
Param4Mute = 51,
|
||||||
|
Param5Mute = 52,
|
||||||
|
Param6Mute = 53,
|
||||||
|
Param7Mute = 54,
|
||||||
|
Param8Mute = 55,
|
||||||
|
Param1Record = 64,
|
||||||
|
Param2Record = 65,
|
||||||
|
Param3Record = 66,
|
||||||
|
Param4Record = 67,
|
||||||
|
Param5Record = 68,
|
||||||
|
Param6Record = 69,
|
||||||
|
Param7Record = 70,
|
||||||
|
Param8Record = 71,
|
||||||
|
Param1Slider = 0,
|
||||||
|
Param2Slider = 1,
|
||||||
|
Param3Slider = 2,
|
||||||
|
Param4Slider = 3,
|
||||||
|
Param5Slider = 4,
|
||||||
|
Param6Slider = 5,
|
||||||
|
Param7Slider = 6,
|
||||||
|
Param8Slider = 7,
|
||||||
|
Param1Knob = 16,
|
||||||
|
Param2Knob = 17,
|
||||||
|
Param3Knob = 18,
|
||||||
|
Param4Knob = 19,
|
||||||
|
Param5Knob = 20,
|
||||||
|
Param6Knob = 21,
|
||||||
|
Param7Knob = 22,
|
||||||
|
Param8Knob = 23,
|
||||||
|
}
|
17
src/main.rs
17
src/main.rs
|
@ -1,16 +1,7 @@
|
||||||
use itertools::Itertools;
|
//use itertools::Itertools;
|
||||||
use mpris::PlayerFinder;
|
//use mpris::{Player, PlayerFinder};
|
||||||
fn list_all_mpris() {
|
mod config;
|
||||||
PlayerFinder::new()
|
|
||||||
.expect("Could not connect to D-Bus")
|
|
||||||
.find_all()
|
|
||||||
.unwrap_or_else(|_| Vec::new())
|
|
||||||
.into_iter()
|
|
||||||
.map(|player| player.identity().to_string())
|
|
||||||
.unique()
|
|
||||||
.for_each(|player| println!("{}", player));
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
list_all_mpris();
|
print!("{}", config::default().unwrap());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue