Skip to content

Commit

Permalink
Merge branch 'main' into field_params_optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
subalterngames committed Jan 12, 2024
2 parents f39ce42 + 4cc932e commit 8ac442c
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 13 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.1"
version = "0.2.2"
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.1"
version = "0.2.2"
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.1"
version = "0.2.2"
resources = ["data/*"]
copyright = "Copyright (c) Subaltern Games LLC 2023. All rights reserved."
short_description = "A minimalist and ergonomic MIDI sequencer."
Expand Down
10 changes: 9 additions & 1 deletion audio/src/conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ impl Conn {
pub fn set_music(&mut self, state: &State) {
let play_state = *self.play_state.lock();
match play_state {
PlayState::NotPlaying => self.start_music(state),
PlayState::NotPlaying | PlayState::Decaying => self.start_music(state),
_ => self.stop_music(&state.music),
}
}
Expand All @@ -228,6 +228,14 @@ impl Conn {
*self.export_state.lock() != ExportState::NotExporting
}

/// When a new save file is loaded or a new file is opened, stop playing music if any music is playing.
pub fn on_new_file(&mut self, state: &State) {
let play_state = *self.play_state.lock();
if let PlayState::Playing(_) = play_state {
self.stop_music(&state.music);
}
}

/// Schedule MIDI events and start to play music.
fn start_music(&mut self, state: &State) {
// Get the start time.
Expand Down
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# 0.2.x

## 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.

## 0.2.1

- I replaced the default qwerty bindings for note input with a more "standard" layout. This information is stored in config.ini, so if you want the update, make sure to delete Documents/cacophony/config.ini if it exists (Cacophony will use the default data/config.ini instead).
Expand Down
5 changes: 5 additions & 0 deletions common/src/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ impl Time {
pub fn samples_to_ppq(&self, samples: u64, framerate: f32) -> u64 {
((self.bpm.get_f() * samples as f32) / (BPM_TO_SECONDS * framerate) * PPQ_F) as u64
}

pub fn reset(&mut self) {
self.cursor = 0;
self.playback = 0;
}
}

impl Default for Time {
Expand Down
18 changes: 17 additions & 1 deletion common/src/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ pub struct View {
zoom_increments: HashMap<EditMode, usize>,
/// The default zoom index.
initial_zoom_index: usize,
#[serde(skip)]
initial_dn: [u8; 2],
}

impl View {
Expand Down Expand Up @@ -95,6 +97,7 @@ impl View {
zoom_index,
zoom_increments,
initial_zoom_index,
initial_dn: dn,
}
}

Expand Down Expand Up @@ -172,7 +175,20 @@ impl View {
}
// Get the time delta.
let dt = self.zoom_levels[self.zoom_index.get()];
self.dt = [self.dt[0], dt];
self.dt = [self.dt[0], self.dt[0] + dt];
}

/// Reset the view.
pub fn reset(&mut self) {
// Reset the zoom.
self.zoom_index.set(self.initial_zoom_index);
// Reset the time.
let dt = self.zoom_levels[self.initial_zoom_index];
self.dt = [0, dt];
// Reset the notes.
self.dn = self.initial_dn;
// Single track view.
self.single_track = true;
}

/// Returns the note delta.
Expand Down
16 changes: 15 additions & 1 deletion io/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,22 @@ impl IO {
}
// New file.
if input.happened(&InputEvent::NewFile) {
// This prevents the previous file from being overwritten.
paths_state.saves.filename = None;
// Stop playing music.
conn.on_new_file(state);
// Reset the music.
state.music = Music::default();
// Clear the selection.
state.select_mode = SelectMode::Single(None);
// Reset the view.
state.view.reset();
// Reset the time.
state.time.reset();
// Clear the undo/redo stacks.
self.undo.clear();
self.redo.clear();
state.unsaved_changes = false;
}
// Open file.
else if input.happened(&InputEvent::OpenFile) {
Expand Down Expand Up @@ -416,7 +430,7 @@ impl IO {
false
}

/// Open a save file from a path.
/// Open a save file from a path. This is called from main.rs
pub fn load_save(
&self,
save_path: &Path,
Expand Down
2 changes: 2 additions & 0 deletions io/src/open_file_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,8 @@ impl Panel for OpenFilePanel {
if let Some(selected) = paths_state.children.selected {
// Disable the panel.
self.disable(state);
// Stop the music.
conn.on_new_file(state);
// Get the path.
let path = paths_state.children.children[selected].path.clone();
// Read the save file.
Expand Down

0 comments on commit 8ac442c

Please sign in to comment.