forked from sonic-pi-net/sonic-pi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit fixes a counterintuitive syntax issue with `play` where the first argument is a hash ``` play({note: :c, amp: 1}, {release: 0.1}) ``` Up to now, this would have silently dropped any other args from the first hash other than `:note`. This commit fixes that. Also adds some tests for the `note` method as I started looking there and already wrote the tests anyway.
- Loading branch information
Showing
3 changed files
with
92 additions
and
1 deletion.
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
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,37 @@ | ||
#-- | ||
# This file is part of Sonic Pi: http://sonic-pi.net | ||
# Full project source: https://github.com/samaaron/sonic-pi | ||
# License: https://github.com/samaaron/sonic-pi/blob/master/LICENSE.md | ||
# | ||
# Copyright 2013, 2014, 2015 by Sam Aaron (http://sam.aaron.name). | ||
# All rights reserved. | ||
# | ||
# Permission is granted for use, copying, modification, and | ||
# distribution of modified versions of this work as long as this | ||
# notice is included. | ||
#++ | ||
|
||
require_relative "../../setup_test" | ||
require_relative "../../../lib/sonicpi/lang/core" | ||
require_relative "../../../lib/sonicpi/lang/sound" | ||
require 'mocha/setup' | ||
|
||
module SonicPi | ||
class SampleTester < Test::Unit::TestCase | ||
|
||
def setup | ||
@mock_sound = Object.new | ||
@mock_sound.extend(Lang::Sound) | ||
@mock_sound.extend(Lang::Core) | ||
end | ||
|
||
def test_sample_with_various_args | ||
Note.expects(:resolve_midi_note_without_octave).with(:c4) | ||
@mock_sound.note :c4 | ||
|
||
Note.expects(:resolve_midi_note).with(:c, 5) | ||
@mock_sound.note :c, octave: 5 | ||
end | ||
|
||
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,49 @@ | ||
#-- | ||
# This file is part of Sonic Pi: http://sonic-pi.net | ||
# Full project source: https://github.com/samaaron/sonic-pi | ||
# License: https://github.com/samaaron/sonic-pi/blob/master/LICENSE.md | ||
# | ||
# Copyright 2013, 2014, 2015 by Sam Aaron (http://sam.aaron.name). | ||
# All rights reserved. | ||
# | ||
# Permission is granted for use, copying, modification, and | ||
# distribution of modified versions of this work as long as this | ||
# notice is included. | ||
#++ | ||
|
||
require_relative "../../setup_test" | ||
require_relative "../../../lib/sonicpi/atom" | ||
require_relative "../../../lib/sonicpi/lang/core" | ||
require_relative "../../../lib/sonicpi/lang/sound" | ||
require 'mocha/setup' | ||
require 'ostruct' | ||
|
||
module SonicPi | ||
class PlayTester < Test::Unit::TestCase | ||
def setup | ||
@mock_sound = Object.new | ||
@mock_sound.extend(Lang::Sound) | ||
@mock_sound.extend(Lang::Core) | ||
@mock_sound.stubs(:sleep) # avoid loading Spider class | ||
@mock_sound.stubs(:ensure_good_timing!) # avoid loading Spider class | ||
@mock_sound.stubs(:current_synth_name).returns(:beep) | ||
end | ||
|
||
def test_play_with_various_args | ||
@mock_sound.expects(:trigger_inst).with(:beep, {note: 60.0}) | ||
@mock_sound.play :c | ||
|
||
@mock_sound.expects(:trigger_inst).with(:beep, {note: 60.0, release: 0.1}) | ||
@mock_sound.play :c, release: 0.1 | ||
|
||
# Single hash | ||
@mock_sound.expects(:trigger_inst).with(:beep, {note: 60.0, release: 0.1}) | ||
@mock_sound.play({note: :c, release: 0.1}) | ||
|
||
# Hash and args | ||
@mock_sound.expects(:trigger_inst).with(:beep, {note: 60.0, amp: 1, release: 0.1}) | ||
@mock_sound.play({note: :c, amp: 1}, {release: 0.1}) | ||
end | ||
|
||
end | ||
end |