Skip to content

Commit

Permalink
Tranpose test done
Browse files Browse the repository at this point in the history
  • Loading branch information
jeudine committed Sep 21, 2024
1 parent 0b44f59 commit 1fddb84
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 7 deletions.
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,3 @@
Library for developing MIDI Sequencers.

*WIP*

## TO DO

* Make test for transpose
88 changes: 85 additions & 3 deletions src/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ use crate::Context;
use crate::MidiConnection;
use crate::MidiController;
use crate::MidiNote;
use crate::Note;
use crate::Track;

#[test]
fn test_play_note() {
fn play_note() {
let debug_conn = Rc::new(RefCell::new(DebugMidiConnectionInner {
notes_on: HashMap::new(),
start_timestamp: Instant::now(),
Expand Down Expand Up @@ -65,7 +67,7 @@ impl Conductor for DebugConductor1 {
}

#[test]
fn test_play_note_conductor() {
fn play_note_conductor() {
let debug_conn = Rc::new(RefCell::new(DebugMidiConnectionInner {
notes_on: HashMap::new(),
start_timestamp: Instant::now(),
Expand Down Expand Up @@ -96,7 +98,7 @@ impl Conductor for DebugConductor2 {
}

#[test]
fn test_notes_stop_on_quit() {
fn notes_stop_on_quit() {
let debug_conn = Rc::new(RefCell::new(DebugMidiConnectionInner {
notes_on: HashMap::new(),
start_timestamp: Instant::now(),
Expand All @@ -106,3 +108,83 @@ fn test_notes_stop_on_quit() {
super::common::test_conductor(conductor, midi);
assert!(debug_conn.borrow().notes_on.is_empty());
}

struct DebugConductor3 {
conn: Rc<RefCell<DebugMidiConnectionInner>>,
track: crate::DeteTrack,
}

impl Conductor for DebugConductor3 {
fn init(&mut self, _context: &mut Context<impl MidiConnection>) {}

fn update(&mut self, context: &mut Context<impl MidiConnection>) {
if context.step == 74 {
context.quit();
} else {
if context.step == 0 {
self.track.transpose(Some(Note::C));
}

if context.step == 48 {
self.track.transpose(Some(Note::G));
}

if context.step == 1 {
assert!(self
.conn
.borrow()
.notes_on
.contains_key(&(0, MidiNote::midi_value(&MidiNote::new(Note::C, 5, 89)))));
}

if context.step == 25 {
assert!(self
.conn
.borrow()
.notes_on
.contains_key(&(0, MidiNote::midi_value(&MidiNote::new(Note::DS, 5, 89)))));
}

if context.step == 49 {
assert!(self
.conn
.borrow()
.notes_on
.contains_key(&(0, MidiNote::midi_value(&MidiNote::new(Note::G, 4, 89)))));
}

if context.step == 73 {
assert!(self
.conn
.borrow()
.notes_on
.contains_key(&(0, MidiNote::midi_value(&MidiNote::new(Note::AS, 4, 89)))));
}

context.midi.play_track(&mut self.track);
}
}
}

#[test]
fn dete_track_transpose() {
let debug_conn = Rc::new(RefCell::new(DebugMidiConnectionInner {
notes_on: HashMap::new(),
start_timestamp: Instant::now(),
}));
let midi = MidiController::new(DebugMidiConnection(debug_conn.clone()));
let conductor = DebugConductor3 {
conn: debug_conn,
track: crate::DeteTrack::new(
48,
vec![
(MidiNote::new(Note::A, 4, 89), 0, 12),
(MidiNote::new(Note::C, 5, 89), 24, 12),
],
Note::A,
0,
"test_transpose",
),
};
super::common::test_conductor(conductor, midi);
}

0 comments on commit 1fddb84

Please sign in to comment.