Skip to content

Commit

Permalink
Add start delay
Browse files Browse the repository at this point in the history
  • Loading branch information
MyBlackMIDIScore committed Sep 30, 2024
1 parent efcd87f commit 1934703
Show file tree
Hide file tree
Showing 12 changed files with 106 additions and 41 deletions.
41 changes: 41 additions & 0 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ atomic_float = "1.1.0"
ico = "0.3.0"
rfd = "0.15.0"
open = "5.3.0"
midir = "0.10.0"
time = "0.3.36"

num_enum = "0.7.3"
palette = "0.7.6"
colors-transform = "0.2"
midir = "0.10.0"


[build-dependencies]
resvg = { version = "0.31.0", default-features = false }
Expand Down
9 changes: 5 additions & 4 deletions src/gui/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@ mod settings;
mod shortcuts;

use std::path::Path;
use std::path::PathBuf;
use std::sync::{Arc, RwLock};
use std::thread;
use std::{path::PathBuf, time::Duration};

use crossbeam_channel::{Receiver, Sender};
use egui::FontFamily::{Monospace, Proportional};
use egui::FontId;
use egui::Frame;
use settings::SettingsWindow;
use time::Duration;

use crate::audio_playback::{EmptyPlayer, MidiDevicePlayer};
use crate::{
Expand Down Expand Up @@ -198,7 +199,7 @@ impl GuiWasabiWindow {

// Render the panel
let height_prev = ctx.available_rect().height();
self.show_playback_panel(&ctx, state);
self.show_playback_panel(&ctx, settings, state);

// Calculate available space left for keyboard and notes
// We must render notes before keyboard because the notes
Expand Down Expand Up @@ -230,7 +231,7 @@ impl GuiWasabiWindow {
.show_separator_line(false)
.show(&ctx, |ui| {
if let Some(midi_file) = self.midi_file.as_mut() {
let skip_dur = Duration::from_secs_f64(settings.gui.skip_control);
let skip_dur = Duration::seconds_f64(settings.gui.skip_control);
let time = midi_file.timer().get_time();

// Set playback keyboard shortcuts
Expand All @@ -252,7 +253,7 @@ impl GuiWasabiWindow {
if midi_file.allows_seeking_backward() {
midi_file.timer_mut().seek(if time <= skip_dur {
// FIXME: Start deplay
Duration::from_secs(0)
Duration::seconds(0)
} else {
time - skip_dur
})
Expand Down
26 changes: 19 additions & 7 deletions src/gui/window/playback_panel.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
use std::time::Duration;
use time::Duration;

use egui::{popup_below_widget, PopupCloseBehavior};

use super::{GuiWasabiWindow, SPACE, WIN_MARGIN};
use crate::{midi::MIDIFileBase, state::WasabiState, utils::convert_seconds_to_time_string};
use crate::{
midi::MIDIFileBase, settings::WasabiSettings, state::WasabiState,
utils::convert_seconds_to_time_string,
};

impl GuiWasabiWindow {
pub fn show_playback_panel(&mut self, ctx: &egui::Context, state: &mut WasabiState) {
pub fn show_playback_panel(
&mut self,
ctx: &egui::Context,
settings: &WasabiSettings,
state: &mut WasabiState,
) {
let mut mouse_over_panel = false;
if let Some(mouse) = ctx.pointer_latest_pos() {
if mouse.y < 60.0 {
Expand Down Expand Up @@ -109,7 +117,7 @@ impl GuiWasabiWindow {

if let Some(midi) = self.midi_file.as_ref() {
time_total = midi.midi_length().unwrap_or(0.0);
time_passed = midi.timer().get_time().as_secs_f64();
time_passed = midi.timer().get_time().as_seconds_f64();
}

let mut timeid = ui
Expand Down Expand Up @@ -146,16 +154,20 @@ impl GuiWasabiWindow {
|| ui.add(egui::Slider::new(&mut 0.0, 0.0..=1.0).show_value(false));
if let Some(midi_file) = self.midi_file.as_mut() {
if let Some(length) = midi_file.midi_length() {
let mut time = midi_file.timer().get_time().as_secs_f64();
let mut time = midi_file.timer().get_time().as_seconds_f64();
let time_prev = time;

ui.add(
egui::Slider::new(&mut time, 0.0..=length).show_value(false),
egui::Slider::new(
&mut time,
-settings.midi.start_delay..=length,
)
.show_value(false),
);
if (time_prev != time)
&& (midi_file.allows_seeking_backward() || time_prev < time)
{
midi_file.timer_mut().seek(Duration::from_secs_f64(time));
midi_file.timer_mut().seek(Duration::seconds_f64(time));
}
} else {
empty_slider();
Expand Down
10 changes: 9 additions & 1 deletion src/gui/window/settings/midi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,17 @@ impl SettingsWindow {
);
});
ui.end_row();

ui.label("Start Delay (s):");
ui.add(
egui::DragValue::new(&mut settings.midi.start_delay)
.speed(1.0)
.range(0.0..=100.0),
);
ui.end_row();
});
ui.vertical_centered(|ui| {
ui.small("Changes to this setting will be applied when a new MIDI is loaded.");
ui.small("Changes to the above settings will be applied when a new MIDI is loaded.");
});

ui.horizontal(|ui| ui.add_space(width + 40.0));
Expand Down
6 changes: 1 addition & 5 deletions src/gui/window/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub fn draw_stats(
.collapsible(false)
.title_bar(false)
.scroll([false, false])
.enabled(true)
.enabled(false)
.frame(stats_frame)
.fixed_pos(pos)
.fixed_size(egui::Vec2::new(200.0, 128.0))
Expand All @@ -94,10 +94,6 @@ pub fn draw_stats(
stats.time_total = midi_file.midi_length().unwrap_or(0.0);
let time = midi_file.timer().get_time().as_seconds_f64();

length_millis = (stats.time_total * 10.0) as u64 % 10;
length_sec = stats.time_total as u64 % 60;
length_min = stats.time_total as u64 / 60;

if time > stats.time_total {
stats.time_passed = stats.time_total;
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/midi/cake/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ impl CakeMIDIFile {
let (keys, note_count) = key_join_handle.join().unwrap();
let audio = audio_join_handle.join().unwrap();

let mut timer = TimeKeeper::new();
let mut timer = TimeKeeper::new(settings.midi.start_delay);

InRamAudioPlayer::new(audio, timer.get_listener(), player).spawn_playback();

Expand Down
2 changes: 1 addition & 1 deletion src/midi/live/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl LiveLoadMIDIFile {
}
});

let mut timer = TimeKeeper::new();
let mut timer = TimeKeeper::new(settings.midi.start_delay);

let colors = MIDIColor::new_vec_from_settings(midi.track_count(), settings);

Expand Down
2 changes: 1 addition & 1 deletion src/midi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use rand::Rng;
pub use cake::{blocks::CakeBlock, intvec4::IntVector4, CakeMIDIFile, CakeSignature};
pub use live::LiveLoadMIDIFile;
pub use ram::InRamMIDIFile;
pub use shared::timer::START_DELAY;

use crate::settings::{Colors, WasabiSettings};

Expand Down Expand Up @@ -124,6 +123,7 @@ impl MIDIColor {
pub fn new_vec_from_palette(tracks: usize, path: impl Into<PathBuf>) -> Vec<Self> {
let path: PathBuf = path.into();
if path.exists() {
// TODO
return Vec::new();
}

Expand Down
2 changes: 1 addition & 1 deletion src/midi/ram/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ impl InRamMIDIFile {
let (keys, note_count) = key_join_handle.join().unwrap();
let audio = audio_join_handle.join().unwrap();

let mut timer = TimeKeeper::new();
let mut timer = TimeKeeper::new(settings.midi.start_delay);

InRamAudioPlayer::new(audio, timer.get_listener(), player).spawn_playback();

Expand Down
Loading

0 comments on commit 1934703

Please sign in to comment.