Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
806 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
require 'rake' | ||
require 'rake/testtask' | ||
require "rake" | ||
require "rake/testtask" | ||
|
||
Rake::TestTask.new(:test) do |t| | ||
t.libs << "test" | ||
t.test_files = FileList["test/**/test_*.rb"] | ||
t.test_files = FileList["test/**/*_test.rb"] | ||
t.verbose = true | ||
end | ||
|
||
task :default => [:test] | ||
task :default => [:test] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require 'helper' | ||
|
||
class ConstantsTest < Test::Unit::TestCase | ||
|
||
include MIDIMessage | ||
include TestHelper | ||
|
||
def test_note_on | ||
msg = NoteOn["c3"].new(0, 100) | ||
assert_equal(NoteOn, msg.class) | ||
assert_equal("C3", msg.name) | ||
assert_equal("C", msg.note_name) | ||
assert_equal([0x90, 0x30, 100], msg.to_a) | ||
end | ||
|
||
def test_control_change | ||
msg = NoteOn["C3"].new(0, 100) | ||
assert_equal(NoteOn, msg.class) | ||
assert_equal("C3", msg.name) | ||
assert_equal([0x90, 0x30, 100], msg.to_a) | ||
end | ||
|
||
def test_control_change | ||
msg = ControlChange["Modulation Wheel"].new(2, 0x20) | ||
assert_equal(ControlChange, msg.class) | ||
assert_equal(msg.channel, 2) | ||
assert_equal(0x01, msg.index) | ||
assert_equal(0x20, msg.value) | ||
assert_equal([0xB2, 0x01, 0x20], msg.to_a) | ||
end | ||
|
||
def test_system_realtime | ||
msg = SystemRealtime["Stop"].new | ||
assert_equal(SystemRealtime, msg.class) | ||
assert_equal("Stop", msg.name) | ||
assert_equal([0xFC], msg.to_a) | ||
end | ||
|
||
def test_system_common | ||
msg = SystemCommon["Song Select"].new | ||
assert_equal(SystemCommon, msg.class) | ||
assert_equal("Song Select", msg.name) | ||
assert_equal([0xF3], msg.to_a) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require 'helper' | ||
|
||
class ContextTest < Test::Unit::TestCase | ||
|
||
include MIDIMessage | ||
include TestHelper | ||
def test_note_off | ||
msg = with(:channel => 0, :velocity => 64) do | ||
note_off(55) | ||
end | ||
assert_equal(0, msg.channel) | ||
assert_equal(55, msg.note) | ||
assert_equal(64, msg.velocity) | ||
assert_equal([128, 55, 64], msg.to_a) | ||
assert_equal("803740", msg.to_bytestr) | ||
end | ||
|
||
def test_note_on | ||
msg = with(:channel => 0, :velocity => 64) do | ||
note_on(55) | ||
end | ||
assert_equal(0, msg.channel) | ||
assert_equal(55, msg.note) | ||
assert_equal(64, msg.velocity) | ||
assert_equal([144, 55, 64], msg.to_a) | ||
assert_equal("903740", msg.to_bytestr) | ||
end | ||
|
||
def test_control_change | ||
msg = with(:channel => 2) do | ||
control_change(0x20, 0x30) | ||
end | ||
assert_equal(msg.channel, 2) | ||
assert_equal(0x20, msg.index) | ||
assert_equal(0x30, msg.value) | ||
assert_equal([0xB2, 0x20, 0x30], msg.to_a) | ||
assert_equal("B22030", msg.to_bytestr) | ||
|
||
end | ||
|
||
def test_polyphonic_aftertouch | ||
msg = with(:channel => 1) do | ||
polyphonic_aftertouch(0x40, 0x40) | ||
end | ||
assert_equal(1, msg.channel) | ||
assert_equal(0x40, msg.note) | ||
assert_equal(0x40, msg.value) | ||
assert_equal([0xA1, 0x40, 0x40], msg.to_a) | ||
assert_equal("A14040", msg.to_bytestr) | ||
end | ||
|
||
def test_program_change | ||
msg = with(:channel => 3) do | ||
program_change(0x40) | ||
end | ||
assert_equal(3, msg.channel) | ||
assert_equal(0x40, msg.program) | ||
assert_equal([0xC3, 0x40], msg.to_a) | ||
assert_equal("C340", msg.to_bytestr) | ||
|
||
end | ||
|
||
def test_channel_aftertouch | ||
msg = with(:channel => 3) do | ||
channel_aftertouch(0x50) | ||
end | ||
assert_equal(3, msg.channel) | ||
assert_equal(0x50, msg.value) | ||
assert_equal([0xD3, 0x50], msg.to_a) | ||
assert_equal("D350", msg.to_bytestr) | ||
end | ||
|
||
def test_pitch_bend | ||
msg = with(:channel => 0) do | ||
pitch_bend(0x50, 0xA0) | ||
end | ||
assert_equal(0, msg.channel) | ||
assert_equal(0x50, msg.low) | ||
assert_equal(0xA0, msg.high) | ||
assert_equal([0xE0, 0x50, 0xA0], msg.to_a) | ||
assert_equal("E050A0", msg.to_bytestr) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require 'helper' | ||
|
||
class FilterTest < Test::Unit::TestCase | ||
|
||
include MIDIMessage | ||
include MIDIMessage::Process | ||
include TestHelper | ||
|
||
def test_high_pass_note_reject | ||
msg = MIDIMessage::NoteOn["C0"].new(0, 100) | ||
assert_equal(12, msg.note) | ||
outp = HighPassFilter.new(:note, 20).process(msg) | ||
assert_equal(nil, outp) | ||
end | ||
|
||
def test_high_pass_note_accept | ||
msg = MIDIMessage::NoteOn["C4"].new(0, 100) | ||
assert_equal(60, msg.note) | ||
outp = HighPassFilter.new(:note, 20).process(msg) | ||
assert_equal(msg, outp) | ||
end | ||
|
||
def test_low_pass_note_reject | ||
msg = MIDIMessage::NoteOn["C4"].new(0, 100) | ||
assert_equal(60, msg.note) | ||
outp = LowPassFilter.new(:note, 50).process(msg) | ||
assert_equal(nil, outp) | ||
end | ||
|
||
def test_low_pass_note_accept | ||
msg = MIDIMessage::NoteOn["C4"].new(0, 100) | ||
assert_equal(60, msg.note) | ||
outp = LowPassFilter.new(:note, 100).process(msg) | ||
assert_equal(msg, outp) | ||
end | ||
|
||
def test_band_pass_note_reject | ||
msg = MIDIMessage::NoteOn["C4"].new(0, 100) | ||
assert_equal(60, msg.note) | ||
outp = BandPassFilter.new(:note, (20..50)).process(msg) | ||
assert_equal(nil, outp) | ||
end | ||
|
||
def test_band_pass_note_accept | ||
msg = MIDIMessage::NoteOn["C4"].new(0, 100) | ||
assert_equal(60, msg.note) | ||
outp = BandPassFilter.new(:note, (20..100)).process(msg) | ||
assert_equal(msg, outp) | ||
end | ||
|
||
def test_band_reject_note_reject | ||
msg = MIDIMessage::NoteOn["C4"].new(0, 100) | ||
assert_equal(60, msg.note) | ||
outp = NotchFilter.new(:note, (20..70)).process(msg) | ||
assert_equal(nil, outp) | ||
end | ||
|
||
def test_band_reject_note_accept | ||
msg = MIDIMessage::NoteOn["C4"].new(0, 100) | ||
assert_equal(60, msg.note) | ||
outp = NotchFilter.new(:note, (20..50)).process(msg) | ||
assert_equal(msg, outp) | ||
end | ||
|
||
def test_multiband_note_reject | ||
msg = MIDIMessage::NoteOn["C4"].new(0, 100) | ||
assert_equal(60, msg.note) | ||
outp = Filter.new(:note, [(20..30), (40..50)]).process(msg) | ||
assert_equal(nil, outp) | ||
end | ||
|
||
def test_multiband_note_accept | ||
msg = MIDIMessage::NoteOn["C4"].new(0, 100) | ||
assert_equal(60, msg.note) | ||
outp = Filter.new(:note, [(20..30), (50..70)]).process(msg) | ||
assert_equal(msg, outp) | ||
end | ||
|
||
def test_multinotch_note_reject | ||
msg = MIDIMessage::NoteOn["C4"].new(0, 100) | ||
assert_equal(60, msg.note) | ||
outp = Filter.new(:note, [(20..30), (55..65)], :reject => true).process(msg) | ||
assert_equal(nil, outp) | ||
end | ||
|
||
def test_multinotch_note_accept | ||
msg = MIDIMessage::NoteOn["C4"].new(0, 100) | ||
assert_equal(60, msg.note) | ||
outp = Filter.new(:note, [(20..30), (40..50)], :reject => true).process(msg) | ||
assert_equal(msg, outp) | ||
end | ||
|
||
def test_numeric_note_accept | ||
msg1 = MIDIMessage::NoteOn["C4"].new(0, 100) | ||
msg2 = MIDIMessage::NoteOn["C5"].new(0, 100) | ||
f = Filter.new(:note, 60) | ||
outp = f.process(msg1) | ||
assert_equal(msg1, outp) | ||
outp = f.process(msg2) | ||
assert_equal(nil, outp) | ||
end | ||
|
||
def test_numeric_note_reject | ||
msg1 = MIDIMessage::NoteOn["C4"].new(0, 100) | ||
msg2 = MIDIMessage::NoteOn["C5"].new(0, 100) | ||
f = Filter.new(:note, 60, :reject => true) | ||
outp = f.process(msg1) | ||
assert_equal(nil, outp) | ||
outp = f.process(msg2) | ||
assert_equal(msg2, outp) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require 'helper' | ||
|
||
class LimitTest < Test::Unit::TestCase | ||
|
||
include MIDIMessage | ||
include MIDIMessage::Process | ||
include TestHelper | ||
|
||
def test_numeric_range | ||
msg = MIDIMessage::NoteOn["C0"].new(0, 100) | ||
assert_equal(12, msg.note) | ||
Limit.new(:note, 30).process(msg) | ||
assert_equal(30, msg.note) | ||
end | ||
|
||
def test_low_note | ||
msg = MIDIMessage::NoteOn["C0"].new(0, 100) | ||
assert_equal(12, msg.note) | ||
Limit.new(:note, (20..50)).process(msg) | ||
assert_equal(20, msg.note) | ||
end | ||
|
||
def test_high_note | ||
msg = MIDIMessage::NoteOn["C6"].new(0, 100) | ||
assert_equal(84, msg.note) | ||
Limit.new(:note, (20..50)).process(msg) | ||
assert_equal(50, msg.note) | ||
end | ||
|
||
def test_low_velocity | ||
msg = MIDIMessage::NoteOn["C0"].new(0, 10) | ||
assert_equal(10, msg.velocity) | ||
Limit.new(:velocity, (30..110)).process(msg) | ||
assert_equal(30, msg.velocity) | ||
end | ||
|
||
def test_high_velocity | ||
msg = MIDIMessage::NoteOn["C6"].new(0, 120) | ||
assert_equal(120, msg.velocity) | ||
Limit.new(:velocity, (25..75)).process(msg) | ||
assert_equal(75, msg.velocity) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require 'helper' | ||
|
||
class MutabilityTest < Test::Unit::TestCase | ||
|
||
include MIDIMessage | ||
include TestHelper | ||
|
||
def test_note | ||
msg = NoteOn["E4"].new(0, 100) | ||
assert_equal(0x40, msg.note) | ||
assert_equal("E4", msg.name) | ||
msg.note += 5 | ||
assert_equal(0x45, msg.note) | ||
assert_equal("A4", msg.name) | ||
end | ||
|
||
def test_octave | ||
msg = NoteOn["E4"].new(0, 100) | ||
assert_equal(0x40, msg.note) | ||
assert_equal("E4", msg.name) | ||
msg.octave += 1 | ||
assert_equal(0x4C, msg.note) | ||
assert_equal("E5", msg.name) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require 'helper' | ||
|
||
class NoteEventTest < Test::Unit::TestCase | ||
|
||
include MIDIMessage | ||
include TestHelper | ||
|
||
def test_create_event | ||
msg = NoteOn.new(0, 0x40, 0x40) | ||
event = Event::Note.new(msg, 10) | ||
assert_equal(msg, event.start) | ||
assert_equal(10, event.duration) | ||
assert_equal(NoteOff, event.finish.class) | ||
assert_equal(msg.note, event.finish.note) | ||
assert_equal(msg.note, event.note) | ||
end | ||
|
||
def test_override_finish | ||
msg = NoteOn.new(0, 0x40, 0x40) | ||
msg2 = NoteOff.new(0, 0x40, 127) | ||
event = Event::Note.new(msg, 5, :finish => msg2) | ||
assert_equal(msg, event.start) | ||
assert_equal(5, event.duration) | ||
assert_equal(0x40, event.start.velocity) | ||
assert_equal(NoteOff, event.finish.class) | ||
assert_equal(0x40, event.finish.note) | ||
assert_equal(127, event.finish.velocity) | ||
end | ||
|
||
end |
Oops, something went wrong.