pub enum Source {
Show 19 variants
Combo1,
Combo2,
Combo3,
Combo4,
Combo1_2,
Combo2_3,
Combo3_4,
Usb1,
Chat,
Usb2,
Bluetooth,
SoundPad,
VirtualGame,
VirtualMusic,
VirtualA,
VirtualB,
CallMe1,
CallMe2,
CallMe3,
}Expand description
An audio source: where audio comes from. Model-independent (19 sources,
one shared device picker across the Pro family). The protocol source index
equals enum order (Combo1 = 0 .. CallMe3 = 18); it is the first
dimension (source-major) of the mix matrix.
CallMe1..=CallMe3 (16..=18) are return channels addressed outside the
regular matrix on some firmware; see Source::is_callme.
Variants§
Combo1
Combo2
Combo3
Combo4
Combo1_2
Combo2_3
Combo3_4
Usb1
Chat
Usb2
Bluetooth
SoundPad
VirtualGame
VirtualMusic
VirtualA
VirtualB
CallMe1
CallMe2
CallMe3
Implementations§
Source§impl Source
impl Source
Sourcepub fn to_protocol(self) -> u8
pub fn to_protocol(self) -> u8
The protocol source index (0..=18).
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}Sourcepub fn from_protocol(idx: u8) -> Option<Self>
pub fn from_protocol(idx: u8) -> Option<Self>
Inverse of Source::to_protocol; None for an out-of-range index.
Trait Implementations§
impl Copy for Source
impl Eq for Source
impl StructuralPartialEq for Source
Auto Trait Implementations§
impl Freeze for Source
impl RefUnwindSafe for Source
impl Send for Source
impl Sync for Source
impl Unpin for Source
impl UnsafeUnpin for Source
impl UnwindSafe for Source
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more