Skip to content

Commit

Permalink
Merge branch 'field_params_optimizations' into lines
Browse files Browse the repository at this point in the history
  • Loading branch information
subalterngames committed Jan 16, 2024
2 parents 9da938c + 7ce3a00 commit e895118
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 115 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.2"
version = "0.2.3"
authors = ["Esther Alter <subalterngames@gmail.com>"]
description = "A minimalist and ergonomic MIDI sequencer"
documentation = "https://github.com/subalterngames/cacophony"
Expand Down Expand Up @@ -86,7 +86,7 @@ speech_dispatcher_0_9 = ["text/speech_dispatcher_0_9"]

[package]
name = "cacophony"
version = "0.2.2"
version = "0.2.3"
authors = ["Esther Alter <subalterngames@gmail.com>"]
description = "A minimalist and ergonomic MIDI sequencer"
documentation = "https://github.com/subalterngames/cacophony"
Expand Down Expand Up @@ -122,7 +122,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.2"
version = "0.2.3"
resources = ["data/*"]
copyright = "Copyright (c) Subaltern Games LLC 2023. All rights reserved."
short_description = "A minimalist and ergonomic MIDI sequencer."
Expand Down
4 changes: 3 additions & 1 deletion audio/src/conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,10 @@ impl Conn {
synth.set_sample_rate(self.framerate);
drop(synth);

// Enqueue note events.
let mut midi_event_queue = self.midi_event_queue.lock();
// Clear the queue before adding new events.
midi_event_queue.clear();
// Enqueue note events.
for track in state.music.get_playable_tracks().iter() {
for note in track.get_playback_notes(state.time.playback) {
// Note-on event.
Expand Down
5 changes: 5 additions & 0 deletions audio/src/midi_event_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,9 @@ impl MidiEventQueue {
}
midi_events
}

/// Clear the queue.
pub(crate) fn clear(&mut self) {
self.events.clear()
}
}
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# 0.2.x

## 0.2.3

- Optimized text and rectangle rendering, which reduces CPU usage by around 5%.

## 0.2.2

- Fixed: There was an input bug where the play/start key (spacebar) was sometimes unresponsive for the first few presses. This is because audio was still decaying from a previous play, meaning that technically the previous play was still ongoing.
- Fixed: When a new file is created or when a new save file loaded, the app didn't reset correctly.
- Fixed: If you try to play music and there are no tracks or no playable notes, the app starts playing music and then immediately stops.
- Fixed: If you're playing music and then load a save file, the save file can't play music because the synthesizer still has MIDI events from the previous music.

## 0.2.1

Expand Down
10 changes: 9 additions & 1 deletion io/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,15 @@ impl IO {
// Get the focused panel.
let panel = self.get_panel(&state.panels[state.focus.get()]);
// Play music.
if panel.allow_play_music() && input.happened(&InputEvent::PlayStop) {
if input.happened(&InputEvent::PlayStop)
&& panel.allow_play_music()
&& !state.music.midi_tracks.is_empty()
&& state
.music
.get_playable_tracks()
.iter()
.any(|t| !t.get_playback_notes(state.time.playback).is_empty())
{
conn.set_music(state);
}
// We're not done yet.
Expand Down
42 changes: 0 additions & 42 deletions render/src/field_params/boolean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,45 +92,3 @@ impl Boolean {
values
}
}

#[cfg(test)]
mod tests {
use crate::field_params::Boolean;
use crate::tests::get_test_renderer;
use common::Paths;
use ini::Ini;
use std::path::PathBuf;
use text::Text;

#[test]
fn boolean() {
let renderer = get_test_renderer();
Paths::init(&PathBuf::from("../data"));
let config = Ini::load_from_file("../data/config.ini").unwrap();
let paths = Paths::get();
let text = Text::new(&config, &paths);
let b0_key = "Boolean value".to_string();
let position = [3, 5];

// New.
let b0 = Boolean::new(b0_key.clone(), position, &text, &renderer);
assert_eq!(&b0.key.text, &b0_key);
assert_eq!(b0.width, 16);
assert!(b0.values.contains_key(&true));
assert!(b0.values.contains_key(&false));
for (bo, bt) in b0.values.keys().zip(["Y", "N"]) {
let bv = &b0.values[bo];
assert_eq!(&bv.text, bt);
}
let bv = b0.get_boolean_label(&true);
assert_eq!(&bv.text, "Y");
let bv = b0.get_boolean_label(&false);
assert_eq!(&bv.text, "N");

// New from width.
let width = 21;
let b1 = Boolean::new_from_width(b0_key.clone(), position, width, &text, &renderer);
assert_eq!(&b1.key.text, &b0_key);
assert_eq!(b1.width, width);
}
}
29 changes: 0 additions & 29 deletions render/src/field_params/key_width.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,32 +76,3 @@ impl KeyWidth {
Width::new(value_position, value_width as usize)
}
}

#[cfg(test)]
mod tests {
use crate::field_params::KeyWidth;
use crate::tests::get_test_renderer;

#[test]
fn key_width() {
let renderer = get_test_renderer();
// New.
let key_str = "My key-width pair";
let position = [3, 5];
let value_width = 3;
let key_width = KeyWidth::new(key_str.to_string(), position, value_width, &renderer);
assert_eq!(&key_width.key.text, key_str);
assert_eq!(key_width.width, 22);
assert_eq!(key_width.value.position, [22, 5]);
assert_eq!(key_width.value.width_u32, value_width);
let value = key_width.get_value("value", &renderer);
assert_eq!(value.text, "lue");

// New from width.
let key_width = KeyWidth::new_from_width(key_str, position, 10, value_width, &renderer);
assert_eq!(key_width.key.text, "My k");
assert_eq!(key_width.width, 10);
assert_eq!(key_width.value.position, [10, 5]);
assert_eq!(key_width.value.width_u32, value_width);
}
}
21 changes: 0 additions & 21 deletions render/src/field_params/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,3 @@ impl List {
)
}
}

#[cfg(test)]
mod tests {
use crate::field_params::{
list::{LEFT_ARROW, RIGHT_ARROW},
List,
};
use crate::tests::get_test_renderer;

#[test]
fn field_params_list() {
let renderer = get_test_renderer();
let li = List::new([3, 5], 17, &renderer);
assert_eq!(&li.left_arrow.text, LEFT_ARROW);
assert_eq!(&li.right_arrow.text, RIGHT_ARROW);
assert_eq!(li.label.position, [4, 5]);
assert_eq!(li.label.width, 17);
let la = li.get_value("This is a very long label! Too long!", &renderer);
assert_eq!(la.text, "This is a very lo")
}
}
11 changes: 0 additions & 11 deletions render/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,3 @@ pub(crate) fn get_track_heights(state: &State, conn: &Conn) -> Vec<u32> {
}
elements
}

#[cfg(test)]
mod tests {
use crate::Renderer;
use ini::Ini;

pub(crate) fn get_test_renderer() -> Renderer {
let config = Ini::load_from_file("../data/config.ini").unwrap();
Renderer::new(&config)
}
}

0 comments on commit e895118

Please sign in to comment.