mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 11:46:41 +01:00
add Modal::Message to handle errors
This commit is contained in:
parent
a77536c234
commit
0a090765d3
4 changed files with 43 additions and 16 deletions
|
|
@ -405,14 +405,16 @@ impl Tek {
|
|||
match index {
|
||||
0 => {
|
||||
let jack = self.jack.clone();
|
||||
self.track_mut()
|
||||
.expect("no active track")
|
||||
.devices
|
||||
.push({
|
||||
let sampler = Sampler::new(&jack, &"sampler", &[], &[&[], &[]], &[&[], &[]])?;
|
||||
Device::Sampler(sampler)
|
||||
});
|
||||
self.modal = None;
|
||||
let sampler = if let Ok(sampler) = Sampler::new(
|
||||
&jack, &"sampler", &[], &[&[], &[]], &[&[], &[]]
|
||||
) {
|
||||
self.modal = None;
|
||||
Device::Sampler(sampler)
|
||||
} else {
|
||||
self.modal = Some(Modal::Message(Message::FailedToAddDevice));
|
||||
return Err("failed to add device".into())
|
||||
};
|
||||
self.track_mut().expect("no active track").devices.push(sampler);
|
||||
Ok(())
|
||||
},
|
||||
1 => todo!(),
|
||||
|
|
@ -458,9 +460,20 @@ pub trait HasSelection {
|
|||
pub enum Modal {
|
||||
Help,
|
||||
Menu,
|
||||
Device(usize)
|
||||
Device(usize),
|
||||
Message(Message)
|
||||
}
|
||||
|
||||
/// Various possible messages
|
||||
#[derive(PartialEq, Clone, Copy, Debug)]
|
||||
pub enum Message {
|
||||
FailedToAddDevice,
|
||||
}
|
||||
|
||||
content!(TuiOut: |self: Message| match self {
|
||||
Self::FailedToAddDevice => "Failed to add device"
|
||||
});
|
||||
|
||||
/// Represents the current user selection in the arranger
|
||||
#[derive(PartialEq, Clone, Copy, Debug, Default)]
|
||||
pub enum Selection {
|
||||
|
|
|
|||
|
|
@ -67,10 +67,11 @@ impl Tek {
|
|||
Fixed::xy(30, 15, Tui::fg_bg(Rgb(255,255,255), Rgb(16,16,16), Bsp::b(
|
||||
Repeat(" "),
|
||||
Outer(true, Style::default().fg(Tui::g(96)))
|
||||
.enclose(self.modal.map(|modal|match modal {
|
||||
.enclose(self.modal.as_ref().map(|modal|match modal {
|
||||
Modal::Menu => self.view_modal_menu().boxed(),
|
||||
Modal::Help => self.view_modal_help().boxed(),
|
||||
Modal::Device(index) => self.view_modal_device(index).boxed(),
|
||||
Modal::Device(index) => self.view_modal_device(*index).boxed(),
|
||||
Modal::Message(message) => self.view_modal_message(message).boxed(),
|
||||
}))
|
||||
)))
|
||||
))
|
||||
|
|
@ -120,6 +121,10 @@ impl Tek {
|
|||
Bsp::s(Tui::bold(true, "Add device"), Map::south(1, choices, choice))
|
||||
}
|
||||
|
||||
fn view_modal_message <'a> (&'a self, message: &'a Message) -> impl Content<TuiOut> + use<'a> {
|
||||
Bsp::s(message, "[ OK ]")
|
||||
}
|
||||
|
||||
/// Spacing between tracks.
|
||||
pub(crate) const TRACK_SPACING: usize = 0;
|
||||
|
||||
|
|
@ -361,14 +366,13 @@ impl<'a> ArrangerView<'a> {
|
|||
.right(*width_side, button_2("Z", "add device", *is_editing))
|
||||
.middle(*width_mid, per_track_top(*width_mid, ||self.tracks_with_sizes_scrolled(),
|
||||
move|index, track|{
|
||||
wrap(if *track_selected == Some(index) {
|
||||
let bg = if *track_selected == Some(index) {
|
||||
track.color.light
|
||||
} else {
|
||||
track.color.base
|
||||
}.rgb, Tui::g(224), Tui::bold(true, Fill::x(Bsp::e(
|
||||
Tui::fg_bg(Reset, Reset, "[ "),
|
||||
Tui::fg_bg(Reset, Reset, " ]"),
|
||||
))))
|
||||
};
|
||||
let fg = Tui::g(224);
|
||||
track.devices.get(0).map(|device|wrap(bg.rgb, fg, device.name()))
|
||||
}))
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -38,3 +38,12 @@ pub enum Device {
|
|||
#[cfg(feature = "clap")] Clap, // TODO
|
||||
#[cfg(feature = "sf2")] Sf2, // TODO
|
||||
}
|
||||
|
||||
impl Device {
|
||||
pub fn name (&self) -> &str {
|
||||
match self {
|
||||
Self::Sampler(sampler) => sampler.name.as_ref(),
|
||||
_ => todo!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,6 +64,7 @@ impl Sampler {
|
|||
) -> Usually<Self> {
|
||||
let name = name.as_ref();
|
||||
Ok(Self {
|
||||
name: name.into(),
|
||||
midi_in: Some(JackMidiIn::new(jack, format!("M/{name}"), midi_from)?),
|
||||
audio_ins: vec![
|
||||
JackAudioIn::new(jack, &format!("L/{name}"), audio_from[0])?,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue