Skip to main content

MixOutput

Enum MixOutput 

Source
pub enum MixOutput {
Show 13 variants Headphone1, Headphone2, Headphone3, Headphone4, Speaker, Recording, Bluetooth, Usb1, Chat, Usb2, CallMe1, CallMe2, CallMe3,
}
Expand description

A mix output bus: where audio is routed to. Model-independent (13 buses). The protocol mix index equals enum order (Headphone1 = 0 .. CallMe3 = 12); it is the second dimension of the source-major mix matrix.

Variants§

§

Headphone1

§

Headphone2

§

Headphone3

§

Headphone4

§

Speaker

§

Recording

§

Bluetooth

§

Usb1

§

Chat

§

Usb2

§

CallMe1

§

CallMe2

§

CallMe3

Implementations§

Source§

impl MixOutput

Source

pub fn to_protocol(self) -> u8

The protocol mix index (0..=12).

Examples found in repository?
examples/cli.rs (line 1150)
1122fn raw_request(
1123    writer: &Writer,
1124    layout: &Shared<Option<Layout>>,
1125    args: &[&str],
1126    raw: RawValue,
1127) -> Result<Outcome, String> {
1128    if args.len() < 3 {
1129        return Err("usage: raw-press|raw-release <source> <mix> <link|unlink> \
1130                    OR raw-bool <source> <mix> <link|unlink> <on|off>"
1131            .into());
1132    }
1133    let source = parse_source(args[0])?;
1134    let mix = parse_mix(args[1])?;
1135    let property = match args[2] {
1136        "link" => "mixLinkRequest",
1137        "unlink" => "mixUnlinkRequest",
1138        other => return Err(format!("expected link|unlink, got {other}")),
1139    };
1140    let value = match raw {
1141        RawValue::Press => Value::Binary(vec![0x01, 0x01, 0x02, 0x01, 0x01, 0x02]),
1142        RawValue::Release => Value::Binary(vec![0x01, 0x01, 0x03, 0x01, 0x01, 0x03]),
1143        RawValue::Bool(b) => Value::Bool(b),
1144    };
1145    let layout_guard = layout.lock().unwrap();
1146    let layout_ref = layout_guard
1147        .as_ref()
1148        .ok_or_else(|| "no Layout yet".to_string())?;
1149    let path = layout_ref
1150        .mix_cell_path(source.to_protocol(), mix.to_protocol())
1151        .ok_or_else(|| "bad cell".to_string())?;
1152    drop(layout_guard);
1153    let body = change_frame::encode_property_changed(&path, property, &value);
1154    writer(body).map_err(|e| format!("write: {e}"))?;
1155    println!("sent 1 frame: {property} = {value:?}");
1156    Ok(Outcome::Continue)
1157}
1158
1159/// `raw-write <PATH> <PROP_NAME> <KIND> <VALUE...>`: send a raw
1160/// propertyChanged frame with arbitrary path, property name, and value.
1161/// PATH is comma-separated `u32`s (e.g. `359,0`). KIND is one of `int`,
1162/// `i64`, `bool`, `dbl`, `str`. For `str`, the remainder of the line is the
1163/// string (allowing spaces). This is the fuzzing / probing primitive:
1164/// bypasses every typed `Command` and lets you write anything to anywhere.
1165fn raw_write(writer: &Writer, args: &[&str]) -> Result<Outcome, String> {
1166    if args.len() < 3 {
1167        return Err(
1168            "usage: raw-write <path,commas,between,u32s> <prop_name> <kind> [<value...>] \
1169             (value defaults to empty for str)"
1170                .into(),
1171        );
1172    }
1173    let path: Vec<u32> = args[0]
1174        .split(',')
1175        .map(|s| s.trim().parse::<u32>())
1176        .collect::<Result<_, _>>()
1177        .map_err(|e| format!("bad path (need comma-separated u32s): {e}"))?;
1178    let prop_name = args[1];
1179    let kind = args[2].to_ascii_lowercase();
1180    let payload = args.get(3..).map(|s| s.join(" ")).unwrap_or_default();
1181    let value = match kind.as_str() {
1182        "int" => Value::Int(payload.parse::<i64>().map_err(|e| format!("int: {e}"))?),
1183        "i64" => Value::Int64(payload.parse::<i64>().map_err(|e| format!("i64: {e}"))?),
1184        "bool" => Value::Bool(parse_bool(&payload)?),
1185        "dbl" | "f64" | "double" => {
1186            Value::Double(payload.parse::<f64>().map_err(|e| format!("dbl: {e}"))?)
1187        }
1188        "str" | "string" => Value::String(payload),
1189        other => return Err(format!("unknown kind: {other}")),
1190    };
1191    let body = change_frame::encode_property_changed(&path, prop_name, &value);
1192    writer(body).map_err(|e| format!("write: {e}"))?;
1193    println!("sent raw {prop_name} = {value:?} at path {path:?}");
1194    Ok(Outcome::Continue)
1195}
1196
1197/// `dump-node <NAME>`: find the first node in the cached fullSync tree whose
1198/// name matches, and print all its properties + values (with the current
1199/// wire types visible). Useful for reading singleton node state
1200/// (`NETWORK`, `SYSTEM`, `OUTPUT`, etc.) without waiting for a change event.
1201fn dump_node(root: &Shared<Option<Node>>, name: &str) -> Result<(), String> {
1202    let guard = root.lock().unwrap();
1203    let r = guard
1204        .as_ref()
1205        .ok_or_else(|| "no fullSync parsed yet".to_string())?;
1206    fn find<'a>(n: &'a Node, target: &str, path: &mut Vec<u32>) -> Option<(&'a Node, Vec<u32>)> {
1207        if n.name == target {
1208            return Some((n, path.clone()));
1209        }
1210        for (i, c) in n.children.iter().enumerate() {
1211            path.push(i as u32);
1212            if let Some(found) = find(c, target, path) {
1213                return Some(found);
1214            }
1215            path.pop();
1216        }
1217        None
1218    }
1219    let mut path = Vec::new();
1220    let (node, node_path) =
1221        find(r, name, &mut path).ok_or_else(|| format!("no node named {name}"))?;
1222    println!(
1223        "[node] <{}> at path {:?} ({} properties, {} children)",
1224        node.name,
1225        node_path,
1226        node.properties.len(),
1227        node.children.len()
1228    );
1229    for p in &node.properties {
1230        println!("  {} = {:?}", p.name, p.value);
1231    }
1232    Ok(())
1233}
1234
1235/// `dump-schema`: walk the cached fullSync tree and print every unique
1236/// `(node_name, property_name)` pair found. Used to enumerate the wire's
1237/// total property surface for completeness auditing.
1238fn dump_schema(root: &Shared<Option<Node>>) -> Result<(), String> {
1239    let guard = root.lock().unwrap();
1240    let r = guard
1241        .as_ref()
1242        .ok_or_else(|| "no fullSync parsed yet".to_string())?;
1243    let mut seen: std::collections::BTreeMap<String, std::collections::BTreeSet<String>> =
1244        std::collections::BTreeMap::new();
1245    fn walk(
1246        n: &Node,
1247        seen: &mut std::collections::BTreeMap<String, std::collections::BTreeSet<String>>,
1248    ) {
1249        let entry = seen.entry(n.name.clone()).or_default();
1250        for p in &n.properties {
1251            entry.insert(p.name.clone());
1252        }
1253        for c in &n.children {
1254            walk(c, seen);
1255        }
1256    }
1257    walk(r, &mut seen);
1258    println!("[schema] {} unique node types", seen.len());
1259    for (node, props) in &seen {
1260        println!("  <{node}> ({} props)", props.len());
1261        for p in props {
1262            println!("    - {p}");
1263        }
1264    }
1265    Ok(())
1266}
1267
1268/// `dump-cell <source> <mix>`: find the MIX node for that (source, mix) cell
1269/// in the cached parsed root and print all of its properties + values, raw.
1270/// No interpretation, no decode. Lets you see what `mixLinkRequest` and friends
1271/// actually look like at rest, and how they differ across cells.
1272fn dump_cell(
1273    layout: &Shared<Option<Layout>>,
1274    root: &Shared<Option<Node>>,
1275    args: &[&str],
1276) -> Result<(), String> {
1277    if args.len() < 2 {
1278        return Err("usage: dump-cell <source> <mix>".into());
1279    }
1280    let source = parse_source(args[0])?;
1281    let mix = parse_mix(args[1])?;
1282
1283    let layout_guard = layout.lock().unwrap();
1284    let l = layout_guard
1285        .as_ref()
1286        .ok_or_else(|| "no Layout yet; wait for the fullSync".to_string())?;
1287    let root_guard = root.lock().unwrap();
1288    let r = root_guard
1289        .as_ref()
1290        .ok_or_else(|| "no fullSync parsed yet".to_string())?;
1291
1292    let s_idx = source.to_protocol();
1293    let m_idx = mix.to_protocol();
1294    let per_source = l.mix_count_per_source() as u32;
1295    let target = s_idx as u32 * per_source + m_idx as u32;
1296
1297    let mut counter: u32 = 0;
1298    for child in &r.children {
1299        if child.name != "MIX" {
1300            continue;
1301        }
1302        if counter == target {
1303            println!("[cell] source={source:?} mix={mix:?} root_idx_offset={counter}");
1304            for p in &child.properties {
1305                println!("  {} = {:?}", p.name, p.value);
1306            }
1307            return Ok(());
1308        }
1309        counter += 1;
1310    }
1311    Err(format!(
1312        "cell not found (offset {target}, found {counter} MIX nodes)"
1313    ))
1314}
Source

pub fn from_protocol(idx: u8) -> Option<Self>

Inverse of MixOutput::to_protocol; None for an out-of-range index.

Source

pub fn label(self) -> &'static str

Human-readable label for UIs and logs.

Trait Implementations§

Source§

impl Clone for MixOutput

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for MixOutput

Source§

impl Debug for MixOutput

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for MixOutput

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for MixOutput

Source§

impl FromStr for MixOutput

Source§

type Err = ParseMixOutputError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl Hash for MixOutput

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for MixOutput

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for MixOutput

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.