Skip to content

Commit 2cc8c12

Browse files
committed
Remove FrameSig
The intention behind FrameSig was that some signals only need to be updated once per batch of samples rather than once per audio sample. This mostly corresponds to user input. This caused some problems with compatibility between components. FrameSigs could be converted to Sigs but not the other way around, and some code was written to expect FrameSigs. Another issue is that when a boolean value is represented by a FrameSig, it can only chance at a cadence of once per frame, which means that trigger signals will remain high for an entire batch of samples rather than a single sample as was likely the intention.
1 parent cd3351e commit 2cc8c12

30 files changed

+395
-1903
lines changed

bevy/src/lib.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
use bevy::{input::keyboard::KeyboardInput, prelude::*, window::PrimaryWindow};
22
use caw_computer_keyboard::Keyboard;
3-
use caw_core::{frame_sig_var, FrameSig, FrameSigVar};
3+
use caw_core::{sig_var, Sig, SigVar};
44

55
#[derive(Resource, Clone)]
66
pub struct BevyInput {
7-
pub mouse_x: FrameSig<FrameSigVar<f32>>,
8-
pub mouse_y: FrameSig<FrameSigVar<f32>>,
9-
pub keyboard: Keyboard<FrameSig<FrameSigVar<bool>>>,
7+
pub mouse_x: Sig<SigVar<f32>>,
8+
pub mouse_y: Sig<SigVar<f32>>,
9+
pub keyboard: Keyboard<Sig<SigVar<bool>>>,
1010
}
1111

1212
impl Default for BevyInput {
1313
fn default() -> Self {
14-
let keyboard = Keyboard::new(|_| frame_sig_var(false));
15-
let mouse_x = frame_sig_var(0.5);
16-
let mouse_y = frame_sig_var(0.5);
14+
let keyboard = Keyboard::new(|_| sig_var(false));
15+
let mouse_x = sig_var(0.5);
16+
let mouse_y = sig_var(0.5);
1717
Self {
1818
keyboard,
1919
mouse_x,
@@ -88,7 +88,7 @@ fn get_key<K>(key_code: KeyCode, keyboard: &Keyboard<K>) -> Option<&K> {
8888

8989
fn update_key_state(
9090
input: &KeyboardInput,
91-
keyboard: &Keyboard<FrameSig<FrameSigVar<bool>>>,
91+
keyboard: &Keyboard<Sig<SigVar<bool>>>,
9292
) {
9393
get_key(input.key_code, keyboard)
9494
.iter()
@@ -104,8 +104,8 @@ fn update_key_state(
104104

105105
fn update_mouse_position(
106106
window: &Window,
107-
mouse_x: &FrameSig<FrameSigVar<f32>>,
108-
mouse_y: &FrameSig<FrameSigVar<f32>>,
107+
mouse_x: &Sig<SigVar<f32>>,
108+
mouse_y: &Sig<SigVar<f32>>,
109109
) {
110110
if let Some(position) = window.cursor_position() {
111111
let window_size = window.size();

computer-keyboard/src/lib.rs

Lines changed: 3 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use caw_core::{Buf, FrameSig, FrameSigT, Sig, SigT};
1+
use caw_core::{Buf, Sig, SigT};
22
use caw_keyboard::{KeyEvent, KeyEvents, Note};
33
use itertools::izip;
44

@@ -314,7 +314,7 @@ fn opinionated_note_by_key(start_note: Note) -> Vec<(Key, Note)> {
314314
.collect::<Vec<_>>()
315315
}
316316

317-
pub fn opinionated_key_events_<S>(
317+
pub fn opinionated_key_events<S>(
318318
keyboard: &Keyboard<S>,
319319
start_note: Note,
320320
) -> Sig<impl SigT<Item = KeyEvents>>
@@ -353,67 +353,14 @@ where
353353
})
354354
}
355355

356-
pub fn opinionated_key_events<S>(
357-
keyboard: &Keyboard<S>,
358-
start_note: Note,
359-
) -> FrameSig<impl FrameSigT<Item = KeyEvents>>
360-
where
361-
S: FrameSigT<Item = bool> + Clone,
362-
{
363-
struct KeyState<S>
364-
where
365-
S: FrameSigT<Item = bool> + Clone,
366-
{
367-
key_sig: S,
368-
note: Note,
369-
pressed: bool,
370-
}
371-
let note_by_key = opinionated_note_by_key(start_note);
372-
let mut state = note_by_key
373-
.into_iter()
374-
.map(|(key, note)| KeyState {
375-
key_sig: keyboard.get(key),
376-
note,
377-
pressed: false,
378-
})
379-
.collect::<Vec<_>>();
380-
FrameSig::from_fn(move |ctx| {
381-
let mut key_events = KeyEvents::empty();
382-
for state in state.iter_mut() {
383-
let pressed = state.key_sig.frame_sample(ctx);
384-
if pressed != state.pressed {
385-
state.pressed = pressed;
386-
key_events.push(KeyEvent {
387-
note: state.note,
388-
pressed,
389-
velocity_01: 1.0,
390-
});
391-
}
392-
}
393-
key_events
394-
})
395-
}
396-
397356
impl<K> Keyboard<K>
398357
where
399358
K: SigT<Item = bool> + Clone,
400-
{
401-
pub fn opinionated_key_events_(
402-
self,
403-
start_note: Note,
404-
) -> Sig<impl SigT<Item = KeyEvents>> {
405-
opinionated_key_events_(&self, start_note)
406-
}
407-
}
408-
409-
impl<K> Keyboard<K>
410-
where
411-
K: FrameSigT<Item = bool> + Clone,
412359
{
413360
pub fn opinionated_key_events(
414361
self,
415362
start_note: Note,
416-
) -> FrameSig<impl FrameSigT<Item = KeyEvents>> {
363+
) -> Sig<impl SigT<Item = KeyEvents>> {
417364
opinionated_key_events(&self, start_note)
418365
}
419366
}

0 commit comments

Comments
 (0)