Skip to content

Conversation

sada
Copy link

@sada sada commented Dec 10, 2017

スモウルビーの「終わるまで( )の音を鳴らす」に当たる play_until_done を作成するために、音の何回鳴らすか(ループ回数)を変更できる Sound#loop_count= を追加しました。

DXRubyのドキュメントの http://mirichi.github.io/dxruby-doc/api/Sound_23loop_count_3D.html を参考にして Sound#loop_count= の引数を n にしました。
あと http://dxruby.osdn.jp/DXRubyReference/20095318417765.htmSound#loopCount= の記述があったので別名で呼び出せるようにしました。

dxruby_sdlのサンプルを使用して、以下のプログラムでループ回数を変更できることを確認しました。

require 'dxruby'

sound = Sound.new('./sound.wav')
bgm = Sound.new('./bgm.mid')

sound.loopCount = 2
sound.play

bgm.loopCount = 0
bgm.play

Window.loop do
end

@coveralls
Copy link

Coverage Status

Coverage increased (+0.02%) to 98.049% when pulling 98bb4ec on sada:add_sound_loop_count into d5d2cce on smalruby:master.

Copy link

@takaokouji takaokouji left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

おぉ、これはいいですね!
dxruby_sdlはわりとゴールがわかりやすいので、高専生が修正するのもできそうですね。


def initialize(filename)
@music = SDL::Mixer::Music.load(filename)
@loop_count = -1

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

インスタンス変数の名前ですが、dxrubyだとインスタンス変数を定義しないと思うので、@_loop_countとして、先頭にアンダーバーをつけてもらえますかね。

Spriteの@xが衝突して困ったことになっているのですよね^_^;

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@_loop_count に名前を変更するのを 91ea522 で修正しました。

@takaokouji
Copy link

@loop_countを@_loop_countに修正してもらえたらマージします!

@coveralls
Copy link

Coverage Status

Coverage increased (+0.02%) to 98.049% when pulling 91ea522 on sada:add_sound_loop_count into d5d2cce on smalruby:master.

Copy link

@takaokouji takaokouji left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ごめんよ、もう少し修正してほしいところがあったよ 🙇

describe '#loop_count=' do
context 'WAVE file', wave: true do
it 'SDL::Waveのループ回数を変更する' do
expect(sound.instance_variable_get('@sound')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ごめんよ、もう1点、修正してほしいところがありました。

ここでのチェックですが、インスタンス変数の値をチェックするのではなくて、
https://github.com/sada/dxruby_sdl/blob/91ea522c83edf17b9ad0270783872e9d13eb7182/spec/lib/dxruby_sdl/sound_spec.rb#L44

https://github.com/sada/dxruby_sdl/blob/91ea522c83edf17b9ad0270783872e9d13eb7182/spec/lib/dxruby_sdl/sound_spec.rb#L78
のように、 SDL::Mixer#play_channel の第3引数が #loop_count= で指定した 1 になっているかどうかをチェックしてもらえますでしょうか?
出来る限り、 @_loop_count は外に出したくないからです。

以下のような感じを想定しています。

wave = sound.instance_variable_get('@sound').instance_variable_get('@wave')
expect(SDL::Mixer).to receive(:play_channel).with(-1, wave, 1)
sound.loop_count = 1
sound.play

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

テストを SDL::Mixer#play_channel が呼び出された時の引数を確認するように 01b510b で修正しました。


context 'MIDI file', midi: true do
it 'SDL::Musicのループ回数を変更する' do
expect(sound.instance_variable_get('@sound')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここも同じで、以下のような感じに修正してもらえるかな。

music = sound.instance_variable_get('@sound').instance_variable_get('@music')
expect(SDL::Mixer).to receive(:play_music).with(music, 1)
sound.loop_count = 1
sound.play

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

テストを SDL::Mixer#play_music が呼び出された時の引数を確認するように 01b510b で修正しました。

@coveralls
Copy link

Coverage Status

Coverage increased (+0.02%) to 98.052% when pulling 01b510b on sada:add_sound_loop_count into d5d2cce on smalruby:master.

@takaokouji takaokouji merged commit 91d8e36 into smalruby:master Dec 12, 2017
@takaokouji
Copy link

ありがとうございました!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants