mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 12:16:42 +01:00
wip(p60,e90): impl macros
This commit is contained in:
parent
f4a4b08c8a
commit
9d4fcaa32b
17 changed files with 748 additions and 1083 deletions
190
crates/tek_tui/src/tui_impls.rs
Normal file
190
crates/tek_tui/src/tui_impls.rs
Normal file
|
|
@ -0,0 +1,190 @@
|
|||
use crate::*;
|
||||
|
||||
macro_rules! impl_jack_api {
|
||||
($Struct:ident $(:: $field:ident)*) => {
|
||||
impl JackApi for $Struct {
|
||||
fn jack (&self) -> &Arc<RwLock<JackClient>> {
|
||||
&self$(.$field)*
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! impl_clock_api {
|
||||
($Struct:ident $(:: $field:ident)*) => {
|
||||
impl ClockApi for $Struct {
|
||||
fn timebase (&self) -> &Arc<Timebase> {
|
||||
&self$(.$field)*.current.timebase
|
||||
}
|
||||
fn quant (&self) -> &Quantize {
|
||||
&self$(.$field)*.quant
|
||||
}
|
||||
fn sync (&self) -> &LaunchSync {
|
||||
&self$(.$field)*.sync
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! impl_playhead_api {
|
||||
($Struct:ident $(:: $field:ident)*) => {
|
||||
impl PlayheadApi for $Struct {
|
||||
fn current (&self) -> &Instant {
|
||||
&self$(.$field)*.current
|
||||
}
|
||||
fn transport (&self) -> &jack::Transport {
|
||||
&self$(.$field)*.transport
|
||||
}
|
||||
fn playing (&self) -> &RwLock<Option<TransportState>> {
|
||||
&self$(.$field)*.playing
|
||||
}
|
||||
fn started (&self) -> &RwLock<Option<(usize, usize)>> {
|
||||
&self$(.$field)*.started
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! impl_has_phrases {
|
||||
($Struct:ident $(:: $field:ident)*) => {
|
||||
impl HasPhrases for $Struct {
|
||||
fn phrases (&self) -> &Vec<Arc<RwLock<Phrase>>> {
|
||||
&self$(.$field)*
|
||||
}
|
||||
fn phrases_mut (&mut self) -> &mut Vec<Arc<RwLock<Phrase>>> {
|
||||
&mut self$(.$field)*
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! impl_has_phrase {
|
||||
($Struct:ident $(:: $field:ident)*) => {
|
||||
impl HasPhrase for $Struct {
|
||||
fn reset (&self) -> bool {
|
||||
self$(.$field)*.reset
|
||||
}
|
||||
fn reset_mut (&mut self) -> &mut bool {
|
||||
&mut self$(.$field)*.reset
|
||||
}
|
||||
fn phrase (&self) -> &Option<(Instant, Option<Arc<RwLock<Phrase>>>)> {
|
||||
todo!()
|
||||
}
|
||||
fn phrase_mut (&self) -> &mut Option<(Instant, Option<Arc<RwLock<Phrase>>>)> {
|
||||
todo!()
|
||||
}
|
||||
fn next_phrase (&self) -> &Option<(Instant, Option<Arc<RwLock<Phrase>>>)> {
|
||||
todo!()
|
||||
}
|
||||
fn next_phrase_mut (&mut self) -> &mut Option<(Instant, Option<Arc<RwLock<Phrase>>>)> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! impl_midi_player {
|
||||
($Struct:ident $(:: $field:ident)*) => {
|
||||
impl MidiInputApi for $Struct {
|
||||
fn midi_ins(&self) -> &Vec<Port<jack::MidiIn>> {
|
||||
todo!()
|
||||
}
|
||||
fn midi_ins_mut(&self) -> &mut Vec<Port<jack::MidiIn>> {
|
||||
todo!()
|
||||
}
|
||||
fn recording(&self) -> bool {
|
||||
todo!()
|
||||
}
|
||||
fn recording_mut(&mut self) -> &mut bool {
|
||||
todo!()
|
||||
}
|
||||
fn monitoring(&self) -> bool {
|
||||
todo!()
|
||||
}
|
||||
fn monitoring_mut(&mut self) -> &mut bool {
|
||||
todo!()
|
||||
}
|
||||
fn overdub(&self) -> bool {
|
||||
todo!()
|
||||
}
|
||||
fn overdub_mut(&mut self) -> &mut bool {
|
||||
todo!()
|
||||
}
|
||||
fn notes_in(&self) -> &Arc<RwLock<[bool; 128]>> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
impl MidiOutputApi for $Struct {
|
||||
fn midi_outs (&self) -> &Vec<Port<jack::MidiOut>> {
|
||||
todo!()
|
||||
}
|
||||
fn midi_outs_mut (&mut self) -> &mut Vec<Port<jack::MidiOut>> {
|
||||
todo!()
|
||||
}
|
||||
fn midi_note (&mut self) -> &mut Vec<u8> {
|
||||
todo!()
|
||||
}
|
||||
fn notes_out (&self) -> &Arc<RwLock<[bool; 128]>> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
impl MidiPlayerApi for $Struct {}
|
||||
}
|
||||
}
|
||||
|
||||
impl_jack_api!(TransportTui::jack);
|
||||
impl_jack_api!(SequencerTui::jack);
|
||||
impl_jack_api!(ArrangerTui::jack);
|
||||
impl_clock_api!(TransportTui::state);
|
||||
impl_clock_api!(SequencerTui::transport);
|
||||
impl_clock_api!(ArrangerTui::transport);
|
||||
impl_clock_api!(PhrasePlayerModel::transport);
|
||||
impl_clock_api!(ArrangerTrack);
|
||||
impl_playhead_api!(TransportTui::state);
|
||||
impl_playhead_api!(SequencerTui::transport);
|
||||
impl_playhead_api!(ArrangerTui::transport);
|
||||
impl_playhead_api!(PhrasePlayerModel::transport);
|
||||
impl_playhead_api!(ArrangerTrack);
|
||||
impl_has_phrases!(PhrasesModel::phrases);
|
||||
impl_has_phrases!(SequencerTui::phrases);
|
||||
impl_has_phrases!(ArrangerTui::phrases);
|
||||
impl_has_phrase!(SequencerTui::player);
|
||||
impl_has_phrase!(ArrangerTrack::player);
|
||||
impl_has_phrase!(PhrasePlayerModel);
|
||||
|
||||
impl HasScenes<ArrangerScene> for ArrangerTui {
|
||||
fn scenes (&self) -> &Vec<ArrangerScene> {
|
||||
&self.scenes
|
||||
}
|
||||
fn scenes_mut (&mut self) -> &mut Vec<ArrangerScene> {
|
||||
&mut self.scenes
|
||||
}
|
||||
fn scene_add (&mut self, name: Option<&str>, color: Option<ItemColor>)
|
||||
-> Usually<&mut ArrangerScene>
|
||||
{
|
||||
let name = name.map_or_else(||self.scene_default_name(), |x|x.to_string());
|
||||
let scene = ArrangerScene {
|
||||
name: Arc::new(name.into()),
|
||||
clips: vec![None;self.tracks().len()],
|
||||
color: color.unwrap_or_else(||ItemColor::random()),
|
||||
};
|
||||
self.scenes_mut().push(scene);
|
||||
let index = self.scenes().len() - 1;
|
||||
Ok(&mut self.scenes_mut()[index])
|
||||
}
|
||||
fn selected_scene (&self) -> Option<&ArrangerScene> {
|
||||
self.selected.scene().map(|s|self.scenes().get(s)).flatten()
|
||||
}
|
||||
fn selected_scene_mut (&mut self) -> Option<&mut ArrangerScene> {
|
||||
self.selected.scene().map(|s|self.scenes_mut().get_mut(s)).flatten()
|
||||
}
|
||||
}
|
||||
|
||||
impl HasTracks<ArrangerTrack> for ArrangerTui {
|
||||
fn tracks (&self) -> &Vec<ArrangerTrack> {
|
||||
&self.tracks
|
||||
}
|
||||
fn tracks_mut (&mut self) -> &mut Vec<ArrangerTrack> {
|
||||
&mut self.tracks
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue