Skip to content

Commit

Permalink
Merge pull request #57 from subalterngames/debug_abc123
Browse files Browse the repository at this point in the history
Debug abc123
  • Loading branch information
subalterngames authored Aug 18, 2024
2 parents e4cc7e6 + 934c956 commit 05e0807
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 15 deletions.
14 changes: 7 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
members = ["audio", "common", "input", "io", "render", "text"]

[workspace.package]
version = "0.2.6"
version = "0.2.7"
authors = ["Esther Alter <[email protected]>"]
description = "A minimalist and ergonomic MIDI sequencer"
documentation = "https://github.com/subalterngames/cacophony"
Expand Down Expand Up @@ -84,7 +84,7 @@ speech_dispatcher_0_9 = ["text/speech_dispatcher_0_9"]

[package]
name = "cacophony"
version = "0.2.6"
version = "0.2.7"
authors = ["Esther Alter <[email protected]>"]
description = "A minimalist and ergonomic MIDI sequencer"
documentation = "https://github.com/subalterngames/cacophony"
Expand Down Expand Up @@ -120,7 +120,7 @@ path = "text"
name = "Cacophony"
identifier = "com.subalterngames.cacophony"
icon = ["icon/32.png", "icon/64.png", "icon/128.png", "icon/256.png"]
version = "0.2.6"
version = "0.2.7"
resources = ["data/*"]
copyright = "Copyright (c) Subaltern Games LLC 2023. All rights reserved."
short_description = "A minimalist and ergonomic MIDI sequencer."
Expand Down
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# 0.2.x

## 0.2.7

- Allow alphanumeric input in `--events events.txt`.

## 0.2.6

- Fixed: If you let all notes in your music play (as opposed to stopping in the middle), it frequently becomes impossible to play or add new notes.
Expand Down
7 changes: 7 additions & 0 deletions input/src/debug_input_event.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use crate::InputEvent;

#[cfg(debug_assertions)]
pub(crate) enum DebugInputEvent {
InputEvent(InputEvent),
Alphanumeric(char),
}
24 changes: 19 additions & 5 deletions input/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@
//! - `InputEvent` is an enum defining an event triggered by user input, e.g. a decrease in track volume.
//! - `Input` maps raw qwerty keycode and raw MIDI messages (control bindings) to input events. It updates per frame, reading input and storing new events.
#[cfg(debug_assertions)]
mod debug_input_event;

mod input_event;
mod keys;
mod midi_binding;
mod midi_conn;
mod note_on;
mod qwerty_binding;

use common::args::Args;
use common::{State, MAX_NOTE, MIN_NOTE};
#[cfg(debug_assertions)]
use debug_input_event::DebugInputEvent;
use hashbrown::HashMap;
use ini::Ini;
pub use input_event::InputEvent;
Expand Down Expand Up @@ -89,7 +95,8 @@ pub struct Input {
/// Characters pressed on this frame.
pub pressed_chars: Vec<char>,
/// Debug input events.
debug_inputs: Vec<InputEvent>,
#[cfg(debug_assertions)]
debug_inputs: Vec<DebugInputEvent>,
/// The MIDI time counter.
time_counter: i16,
}
Expand Down Expand Up @@ -126,8 +133,11 @@ impl Input {
let lines = s.split('\n');
for line in lines {
match line.trim().parse::<InputEvent>() {
Ok(e) => debug_inputs.push(e),
Err(_) => panic!("Failed to parse {}", line),
Ok(e) => debug_inputs.push(DebugInputEvent::InputEvent(e)),
Err(_) => line
.trim()
.chars()
.for_each(|c| debug_inputs.push(DebugInputEvent::Alphanumeric(c))),
}
}
}
Expand Down Expand Up @@ -193,8 +203,12 @@ impl Input {

// DEBUG.
if cfg!(debug_assertions) && !&self.debug_inputs.is_empty() {
let e = self.debug_inputs.remove(0);
events.push(e);
match self.debug_inputs.remove(0) {
// Push an event.
DebugInputEvent::InputEvent(e) => events.push(e),
// Push a char.
DebugInputEvent::Alphanumeric(c) => self.pressed_chars.push(c),
}
}

// Qwerty note input.
Expand Down

0 comments on commit 05e0807

Please sign in to comment.