Skip to content

Commit

Permalink
Merge pull request #29 from subalterngames/field_params_optimizations
Browse files Browse the repository at this point in the history
Rendering optimizations
  • Loading branch information
subalterngames authored Jan 20, 2024
2 parents 9fef5d0 + 8087764 commit da9e964
Show file tree
Hide file tree
Showing 36 changed files with 661 additions and 491 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: 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.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.
Expand Down
5 changes: 5 additions & 0 deletions common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,8 @@ pub fn get_bytes(path: &Path) -> Vec<u8> {
pub fn get_default_data_folder() -> PathBuf {
current_dir().unwrap().join("data")
}

#[cfg(debug_assertions)]
pub fn get_test_config() -> ini::Ini {
ini::Ini::load_from_file("../data/config.ini").unwrap()
}
37 changes: 23 additions & 14 deletions common/src/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ impl Paths {
/// Setup the paths, needs to be be called at least once.
pub fn init(data_directory_from_cli: &Path) {
let data_directory = get_data_directory(data_directory_from_cli);
PATHS.set(Self::new(&data_directory)).unwrap();
}

/// Returns a new `Paths` that can be used for testing.
#[cfg(debug_assertions)]
pub fn get_test_paths() -> Self {
Self::new(&PathBuf::from("../data"))
}

/// Returns a new `Paths` object.
fn new(data_directory: &Path) -> Self {
let user_directory = match UserDirs::new() {
Some(user_dirs) => match user_dirs.document_dir() {
Some(documents) => documents.join("cacophony"),
Expand All @@ -60,20 +71,18 @@ impl Paths {
let export_directory = get_directory("exports", &user_directory);
let splash_path = data_directory.join("splash.png");
let default_soundfont_path = data_directory.join("CT1MBGMRSV1.06.sf2");
PATHS
.set(Self {
default_ini_path,
user_directory,
user_ini_path,
text_path,
soundfonts_directory,
saves_directory,
export_directory,
splash_path,
default_soundfont_path,
data_directory,
})
.unwrap();
Self {
default_ini_path,
user_directory,
user_ini_path,
text_path,
soundfonts_directory,
saves_directory,
export_directory,
splash_path,
default_soundfont_path,
data_directory: data_directory.to_path_buf(),
}
}

/// Get a reference to the paths, panics when not initialized.
Expand Down
7 changes: 2 additions & 5 deletions common/src/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,7 @@ impl View {

#[cfg(test)]
mod tests {
use crate::time::PPQ_U;
use crate::view::View;
use crate::EditMode;
use ini::Ini;
use crate::{get_test_config, EditMode, View, PPQ_U};

const VIEW_T1: u64 = PPQ_U * 133;

Expand Down Expand Up @@ -250,6 +247,6 @@ mod tests {
}

fn get_new_view() -> View {
View::new(&Ini::load_from_file("../data/config.ini").unwrap())
View::new(&get_test_config())
}
}
5 changes: 2 additions & 3 deletions io/src/piano_roll/edit_mode_deltas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,11 @@ impl EditModeDeltas {
#[cfg(test)]
mod tests {
use super::EditModeDeltas;
use common::PPQ_U;
use ini::Ini;
use common::{get_test_config, PPQ_U};

#[test]
fn edit_mode_deltas() {
let e = EditModeDeltas::new(&Ini::load_from_file("../data/config.ini").unwrap());
let e = EditModeDeltas::new(&get_test_config());
assert_eq!(e.quick_time_factor, 4, "{}", e.quick_time_factor);
assert_eq!(e.precise_time, PPQ_U / 32, "{}", e.precise_time);
assert_eq!(e.normal_note, 1, "{}", e.normal_note);
Expand Down
7 changes: 3 additions & 4 deletions render/src/export_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ impl ExportPanel {
position[1] + 1,
],
decaying,
renderer,
);
let writing = text.get("EXPORT_PANEL_WRITING");
let writing_label = Label::new(
Expand All @@ -39,6 +40,7 @@ impl ExportPanel {
position[1] + 1,
],
writing,
renderer,
);
Self {
panel,
Expand Down Expand Up @@ -67,10 +69,7 @@ impl Drawable for ExportPanel {
+ self.panel.background.grid_rect.size[0] / 2
- w / 2;
let y = self.panel.background.grid_rect.position[1] + 1;
let label = Label {
position: [x, y],
text: samples,
};
let label = Label::new([x, y], samples, renderer);
renderer.text(&label, &ColorKey::FocusDefault);
}
ExportState::AppendingDecay => {
Expand Down
Loading

0 comments on commit da9e964

Please sign in to comment.