Skip to content

Commit

Permalink
feat: add Instrument::PedalHihat
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanleiby committed Jul 9, 2024
1 parent c03a633 commit 109e526
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 15 deletions.
Binary file added res/sounds/pedal-hihat.wav
Binary file not shown.
1 change: 1 addition & 0 deletions src/audio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ async fn schedule_note(
"res/sounds/tom-hi.wav" => StaticSoundSettings::new().volume(0.25),
"res/sounds/tom-med.wav" => StaticSoundSettings::new().volume(0.25),
"res/sounds/tom-low.wav" => StaticSoundSettings::new().volume(0.25),
"res/sounds/pedal-hihat.wav" => StaticSoundSettings::new().volume(0.5),
_ => StaticSoundSettings::new(),
}
.start_time(ClockTime {
Expand Down
4 changes: 2 additions & 2 deletions src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub const GRID_TOP_Y: f64 = 64.;
pub const TICK_SCHEDULE_AHEAD: f64 = 2.; // schedule audio this many (N) ticks ahead of time (i.e. N seconds ahead if at 60bpm)

// General use
pub const ALL_INSTRUMENTS: [Instrument; 9] = [
pub const ALL_INSTRUMENTS: [Instrument; 10] = [
Instrument::Crash,
Instrument::Ride,
Instrument::OpenHihat,
Expand All @@ -34,7 +34,7 @@ pub const ALL_INSTRUMENTS: [Instrument; 9] = [
Instrument::Tom3,
Instrument::Snare,
Instrument::Kick,
// Pedal Hi-hat
Instrument::PedalHiHat,
];

pub const NUM_ROWS_IN_GRID: usize = ALL_INSTRUMENTS.len();
29 changes: 18 additions & 11 deletions src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,19 @@ impl Input {
let processing_delay = 0.; // TODO: solve this for keyboard input, too.
// Right now we don't know the delay between key press and frame start .. we could improve by guessing midway through the previous frame (1/2 frame duration) without any knowledge

for ins in ALL_INSTRUMENTS.iter() {
let key_code = match ins {
Instrument::ClosedHihat => KeyCode::A,
Instrument::Snare => KeyCode::S,
Instrument::Kick => KeyCode::D,
Instrument::OpenHihat => KeyCode::F,
Instrument::Ride => KeyCode::G,
Instrument::Crash => KeyCode::H,
Instrument::Tom1 => KeyCode::J,
Instrument::Tom2 => KeyCode::K,
Instrument::Tom3 => KeyCode::L,
for (idx, ins) in ALL_INSTRUMENTS.iter().enumerate() {
let key_code = match idx {
0 => KeyCode::A,
1 => KeyCode::S,
2 => KeyCode::D,
3 => KeyCode::F,
4 => KeyCode::G,
5 => KeyCode::H,
6 => KeyCode::J,
7 => KeyCode::K,
8 => KeyCode::L,
9 => KeyCode::Semicolon,
_ => panic!("more than hard-coded num instruments, failed to map key codes"),
};
if is_key_pressed(key_code) {
events.push(Events::UserHit {
Expand Down Expand Up @@ -194,6 +196,7 @@ struct InputConfigMidi {
tom_1: HashSet<u8>,
tom_2: HashSet<u8>,
tom_3: HashSet<u8>,
pedal_hihat: HashSet<u8>,
}

impl InputConfigMidi {
Expand All @@ -208,6 +211,7 @@ impl InputConfigMidi {
Instrument::Tom1 => &self.tom_1,
Instrument::Tom2 => &self.tom_2,
Instrument::Tom3 => &self.tom_3,
Instrument::PedalHiHat => &self.pedal_hihat,
}
}
}
Expand All @@ -226,6 +230,7 @@ fn get_midi_as_user_hits(midi_input: &MidiInput) -> Vec<UserHit> {
tom_1: HashSet::from_iter(vec![]),
tom_2: HashSet::from_iter(vec![]),
tom_3: HashSet::from_iter(vec![]),
pedal_hihat: HashSet::from_iter(vec![]),
};
let td17 = InputConfigMidi {
closed_hi_hat: HashSet::from_iter(vec![42, 22]),
Expand All @@ -238,6 +243,7 @@ fn get_midi_as_user_hits(midi_input: &MidiInput) -> Vec<UserHit> {
tom_1: HashSet::from_iter(vec![50, 48]),
tom_2: HashSet::from_iter(vec![47, 45]),
tom_3: HashSet::from_iter(vec![58, 43]),
pedal_hihat: HashSet::from_iter(vec![]),
};
let alesis_nitro = InputConfigMidi {
closed_hi_hat: HashSet::from_iter(vec![42]),
Expand All @@ -249,6 +255,7 @@ fn get_midi_as_user_hits(midi_input: &MidiInput) -> Vec<UserHit> {
tom_1: HashSet::from_iter(vec![]),
tom_2: HashSet::from_iter(vec![]),
tom_3: HashSet::from_iter(vec![]),
pedal_hihat: HashSet::from_iter(vec![]),
};

let ic_midi = match midi_input.get_device_name() {
Expand Down
1 change: 1 addition & 0 deletions src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ fn draw_beat_grid(desired_hits: &Voices) {
Instrument::Tom1 => "Tom1 (High)",
Instrument::Tom2 => "Tom2 (Med)",
Instrument::Tom3 => "Tom3 (Low)",
Instrument::PedalHiHat => "Pedal Hi-hat",
};

// Labels in top-left of grid
Expand Down
6 changes: 4 additions & 2 deletions src/voices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ use serde::{Deserialize, Serialize};

use crate::consts::ALL_INSTRUMENTS;

#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Instrument {
ClosedHihat,
Snare,
Kick,
OpenHihat,
// PedalHiHat,
PedalHiHat,
Ride,
// RideBell,
Tom1,
Expand Down Expand Up @@ -78,6 +78,7 @@ impl Voices {
Instrument::Tom1 => vec![],
Instrument::Tom2 => vec![],
Instrument::Tom3 => vec![],
Instrument::PedalHiHat => vec![],
};
data.push(Voice {
instrument: *ins,
Expand Down Expand Up @@ -124,6 +125,7 @@ impl Voices {
Instrument::Tom1 => "res/sounds/tom-hi.wav",
Instrument::Tom2 => "res/sounds/tom-med.wav",
Instrument::Tom3 => "res/sounds/tom-low.wav",
Instrument::PedalHiHat => "res/sounds/pedal-hihat.wav",
// Instrument::Metronome => "res/sounds/click.wav",
}
}
Expand Down

0 comments on commit 109e526

Please sign in to comment.