Skip to content

Commit

Permalink
refactor: remove setter actions
Browse files Browse the repository at this point in the history
  • Loading branch information
heypoom committed Dec 17, 2023
1 parent 08eda9d commit 2d7ebd9
Show file tree
Hide file tree
Showing 8 changed files with 3 additions and 93 deletions.
8 changes: 2 additions & 6 deletions canvas/src/blocks/clock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ export const ClockBlock = memo((props: ClockProps) => {
setCycleError(!valid)

if (valid) {
updateNodeData(id, { freq })
engine.send(id, { type: "SetClockFreq", freq })
engine.ctx?.force_tick_block(id)
engine.updateBlockData(id, "Clock", { freq })
}
}}
{...(cycleError && { color: "tomato" })}
Expand All @@ -55,9 +53,7 @@ export const ClockBlock = memo((props: ClockProps) => {
onCheckedChange={(ping) => {
if (ping === "indeterminate") return

updateNodeData(id, { ping })
engine.send(id, { type: "SetClockPing", ping })
engine.ctx?.force_tick_block(id)
engine.updateBlockData(id, "Clock", { ping })
}}
/>
</div>
Expand Down
8 changes: 0 additions & 8 deletions machine/src/blocks/clock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,6 @@ impl Canvas {

for message in &messages {
match &message.action {
Action::SetClockFreq { freq: f, } => {
*freq = *f;
}

Action::SetClockPing { ping: p, } => {
*ping = *p;
}

Action::Reset => {
*time = 0;
}
Expand Down
6 changes: 0 additions & 6 deletions machine/src/blocks/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,6 @@ impl Canvas {
};
}

Action::SetAutoReset { auto_reset: value } => {
let Memory { auto_reset, .. } = &mut self.mut_block(id)?.data else { continue; };

*auto_reset = value;
}

_ => {}
}
}
Expand Down
18 changes: 0 additions & 18 deletions machine/src/blocks/midi_in.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,6 @@ impl Canvas {
self.send_data_to_sinks(id, vec![note as u16, value as u16])?;
}

Action::SetMidiPort { port: p } => {
if let MidiIn { port, .. } = &mut self.mut_block(id)?.data {
*port = p;
}
}

Action::SetMidiInputEvent { event } => {
if let MidiIn { on, .. } = &mut self.mut_block(id)?.data {
*on = event;
}
}

Action::SetMidiChannels { channels: chan } => {
if let MidiIn { channels, .. } = &mut self.mut_block(id)?.data {
*channels = chan;
}
}

_ => {}
}
}
Expand Down
14 changes: 0 additions & 14 deletions machine/src/blocks/midi_out.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,6 @@ impl Canvas {
})
}

Action::SetMidiOutputFormat { format: fmt } => {
*format = fmt;
}

Action::SetMidiPort { port: p } => {
*port = p;
}

Action::SetMidiChannels { channels } => {
if let Some(chan) = channels.first() {
*channel = *chan;
}
}

Action::Write { address, data } => {
// MIDI channels and ports cannot be over 255.
if *channel > 255 || *port > 255 { continue; }
Expand Down
5 changes: 0 additions & 5 deletions machine/src/blocks/osc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ impl Canvas {
pub fn tick_osc_block(&mut self, id: u16, messages: Vec<Message>) -> Errorable {
for message in &messages {
match &message.action {
Action::SetWaveform { waveform: wf } => {
if let Osc { waveform } = &mut self.mut_block(id)?.data {
*waveform = *wf;
};
}
Action::Data { body } => {
let mut waveform = Waveform::Sine;

Expand Down
6 changes: 0 additions & 6 deletions machine/src/blocks/pixel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,6 @@ impl Canvas {
};
}

Action::SetPixelMode { mode: m } => {
if let Pixel { mode, .. } = &mut self.mut_block(id)?.data {
*mode = m;
};
}

Action::Reset => {
if let Pixel { pixels, .. } = &mut self.mut_block(id)?.data {
pixels.clear()
Expand Down
31 changes: 1 addition & 30 deletions machine/src/canvas/message.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use serde::{Deserialize, Serialize};
use tsify::Tsify;
use crate::audio::midi::{MidiInputEvent, MidiOutputFormat};
use crate::audio::waveform::Waveform;
use crate::blocks::pixel::PixelMode;
use crate::audio::midi::{MidiInputEvent};
use crate::canvas::wire::Port;

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Tsify)]
Expand Down Expand Up @@ -44,31 +42,4 @@ pub enum Action {

/// Notify the block that a MIDI message has been received.
Midi { event: MidiInputEvent, note: u8, value: u8, channel: u8, port: u8 },

/// Set the MIDI port
SetMidiPort { port: u16 },

/// Set the MIDI channels.
SetMidiChannels { channels: Vec<u16> },

/// Select the MIDI input event for the block to subscribe to.
SetMidiInputEvent { event: MidiInputEvent },

/// Set the MIDI output format.
SetMidiOutputFormat { format: MidiOutputFormat },

/// Set the waveform of the oscillator.
SetWaveform { waveform: Waveform },

/// Set the pixel mode of the pixel block.
SetPixelMode { mode: PixelMode },

/// Should the block reset via the reset command?
SetAutoReset { auto_reset: bool },

/// Set the clock's frequency
SetClockFreq { freq: u16 },

/// Set whether we should send a ping instead of the time.
SetClockPing { ping: bool },
}

0 comments on commit 2d7ebd9

Please sign in to comment.