use core::fmt;
use crate::error::Error;
use crate::ids::Slot;
use crate::param::ParamId;
use crate::program::Program;
use crate::sysex::{Command, Identity};
use crate::wire::{Channel, ChannelMessage};
use super::{ControlApp, Request};
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum Event {
EditBuffer(Program),
Program {
slot: Slot,
program: Program,
},
Identity(Identity),
ControlApp(ControlApp),
Parameter {
parameter: ParamId,
value: u16,
},
Channel {
channel: Channel,
message: ChannelMessage,
},
Timeout(Request),
Unhandled(Command),
Failed(Error),
Foreign {
manufacturer: [u8; 3],
model: u8,
},
Lost(u16),
}
impl fmt::Display for Event {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::EditBuffer(program) => write!(f, "edit buffer: {}", program.name()),
Self::Program { slot, program } => write!(f, "{slot}: {}", program.name()),
Self::Identity(identity) => write!(f, "firmware {}", identity.firmware),
Self::ControlApp(control_app) => write!(f, "selected {control_app}"),
Self::Parameter { parameter, value } => write!(f, "{parameter} = {value}"),
Self::Channel { channel, message } => write!(f, "channel {channel}: {message}"),
Self::Timeout(request) => write!(f, "no answer to the {request}"),
Self::Unhandled(command) => write!(f, "untracked {command}"),
Self::Failed(error) => write!(f, "unreadable frame: {error}"),
Self::Foreign { manufacturer, .. } => {
write!(f, "frame from manufacturer {manufacturer:02X?}")
}
Self::Lost(count) => write!(f, "{count} events dropped"),
}
}
}