win32-sound 0.4.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gemtest ADDED
File without changes
data/CHANGES CHANGED
@@ -1,3 +1,15 @@
1
+ == 0.5.0 - 28-Jun-2012
2
+ * Now uses FFI instead of win32-api. This means it works with JRuby, too.
3
+ * Corresponding updates to the tests, Rakefile, gemspec, etc.
4
+ * Removed the Sound::Error exception class. If an underlying FFI function
5
+ fails then a SystemCallError (Errno::XXX) is raised instead.
6
+
7
+ == 0.4.3 - 21-May-2011
8
+ * Refactored Rakefile, removing an old gem install task and adding a
9
+ default task and a clean task.
10
+ * Altered the gemspec, including a platform change to 'universal-win32', and
11
+ removed a deprecated specification method.
12
+
1
13
  == 0.4.2 - 6-Aug-2009
2
14
  * Changed the license to Artistic 2.0.
3
15
  * Updated to use the Windows::Sound module from the windows-pr library.
data/README CHANGED
@@ -1,63 +1,56 @@
1
- == Description
2
- A library for playing and controlling sounds on MS Windows.
1
+ = Description
2
+ A library for playing and controlling sounds on MS Windows.
3
3
 
4
- == Prerequisites
5
- * windows-pr 1.0.6 or later
4
+ = Prerequisites
5
+ * ffi
6
+ * test-unit 2 (Development only)
6
7
 
7
- == Installation instructions
8
- === Gem installation
9
- gem install win32-sound
8
+ = Installation
9
+ gem install win32-sound
10
10
 
11
- === Local installation
12
- rake test (optional)
13
- rake install (non-gem) or rake install_gem (gem)
11
+ = Synopsis
12
+ require 'win32/sound'
13
+ include Win32
14
14
 
15
- == Synopsis
16
- require 'win32/sound'
17
- include Win32
15
+ # Play a wav file
16
+ Sound.play("somefile.wav")
18
17
 
19
- # Play a wav file
20
- Sound.play("somefile.wav")
18
+ # Play a system sound
19
+ Sound.play("SystemAsterisk",Sound::ALIAS)
21
20
 
22
- # Play a system sound
23
- Sound.play("SystemAsterisk",Sound::ALIAS)
21
+ # Get the current volume of the waveform-audio output device.
22
+ p Sound.volume.join(", ") # left channel, right channel
24
23
 
25
- # Get the current volume of the waveform-audio output device.
26
- p Sound.volume.join(", ") # left channel, right channel
24
+ = Acknowledgements
25
+ API ideas derived (or not) from Perl's Win32::Sound module and Python's
26
+ winsound package.
27
27
 
28
- == Acknowledgements
29
- API ideas derived (or not) from Perl's Win32::Sound module and Python's
30
- winsound package.
31
-
32
- == Known Bugs
33
- None that I'm aware of. Please report any bugs on the Win32 Utils home
34
- page at http://rubyforge.org/projects/win32utils.
28
+ = Known Bugs
29
+ None that I'm aware of. Please report any bugs on the project page
30
+ at https://github.com/djberg96/win32-sound.
35
31
 
36
- == Questions and Comments
37
- Please post questions and/or comments on one of the forums on the project
38
- page at http://rubyforge.org/projects/win32utils. Click the 'Forums' tab.
39
-
40
- == Future Plans
41
- Add ability to retrieve information about WAV files.
42
- Add MIDI support?
43
-
44
- == Developer's Notes
45
- The MessageBeep() function, which the Python "winsound" module contains,
46
- is intentionally omitted here. I felt it was redundant, because you can
47
- achieve the same effect with something like this:
48
- Sound.play("SystemAsterisk", Sound::ALIAS).
32
+ = Future Plans
33
+ Add ability to retrieve information about WAV files.
34
+ Add MIDI support?
35
+
36
+ = Developer's Notes
37
+ The MessageBeep() function, which the Python "winsound" module contains,
38
+ is intentionally omitted here. I felt it was redundant, because you can
39
+ achieve the same effect with something like this:
40
+
41
+ Sound.play("SystemAsterisk", Sound::ALIAS).
49
42
 
50
- == License
51
- Artistic 2.0
43
+ = License
44
+ Artistic 2.0
52
45
 
53
- == Copyright
54
- (C) 2004-2009, Daniel J. Berger, All Rights Reserved
46
+ = Copyright
47
+ (C) 2004-2012, Daniel J. Berger, All Rights Reserved
55
48
 
56
- == Warranty
57
- This package is provided "as is" and without any express or
58
- implied warranties, including, without limitation, the implied
59
- warranties of merchantability and fitness for a particular purpose.
49
+ = Warranty
50
+ This package is provided "as is" and without any express or
51
+ implied warranties, including, without limitation, the implied
52
+ warranties of merchantability and fitness for a particular purpose.
60
53
 
61
- == Author(s)
62
- Daniel Berger
63
- Park Heesob
54
+ = Author(s)
55
+ Daniel Berger
56
+ Park Heesob
data/Rakefile CHANGED
@@ -1,26 +1,31 @@
1
1
  require 'rake'
2
2
  require 'rake/testtask'
3
+ require 'rake/clean'
3
4
 
4
- desc "Install the win32-sound package (non-gem)"
5
- task :install do
6
- dest = File.join(Config::CONFIG['sitelibdir'], 'win32')
7
- Dir.mkdir(dest) unless File.exists? dest
8
- cp 'lib/win32/sound.rb', dest, :verbose => true
9
- end
5
+ CLEAN.include("**/*.gem", "**/*.rbc")
6
+
7
+ namespace :gem do
8
+ desc "Create the win32-sound gem"
9
+ task :create => [:clean] do
10
+ spec = eval(IO.read("win32-sound.gemspec"))
11
+ Gem::Builder.new(spec).build
12
+ end
10
13
 
11
- desc "Install the win32-sound package as a gem"
12
- task :install_gem do
13
- ruby 'win32-sound.gemspec'
14
- file = Dir["*.gem"].first
15
- sh "gem install #{file}"
14
+ desc "Install the win32-sound library"
15
+ task :install => [:create] do
16
+ file = Dir["*.gem"].first
17
+ sh "gem install #{file}"
18
+ end
16
19
  end
17
20
 
18
21
  desc 'Run the example program'
19
22
  task :example do
20
- ruby '-Ilib examples\example_win32_sound.rb'
23
+ ruby '-Ilib examples\example_win32_sound.rb'
21
24
  end
22
25
 
23
26
  Rake::TestTask.new do |t|
24
- t.warning = true
25
- t.verbose = true
27
+ t.warning = true
28
+ t.verbose = true
26
29
  end
30
+
31
+ task :default => :test
data/lib/win32/sound.rb CHANGED
@@ -1,211 +1,229 @@
1
- require 'windows/sound'
2
- require 'windows/error'
1
+ require 'ffi'
3
2
 
4
3
  # The Win32 module serves as a namespace only.
5
4
  module Win32
6
5
 
7
- # The Sound class encapsulates various methods for playing sound as well
8
- # as querying or configuring sound related properties.
9
- class Sound
10
-
11
- # The Win32::Sound::Error class is typically raised if any of the
12
- # Win32::Sound methods fail.
13
- class Error < StandardError; end
14
-
15
- include Windows::Sound
16
- include Windows::Error
17
- extend Windows::Sound
18
- extend Windows::Error
19
-
20
- # The version of the win32-sound library
21
- VERSION = '0.4.2'
22
-
23
- LOW_FREQUENCY = 37
24
- HIGH_FREQUENCY = 32767
25
- MAX_VOLUME = 0xFFFF
26
-
27
- SYNC = SND_SYNC # play synchronously (default)
28
- ASYNC = SND_ASYNC # play asynchronously
29
- NODEFAULT = SND_NODEFAULT # silence (!default) if sound not found
30
- MEMORY = SND_MEMORY # pszSound points to a memory file
31
- LOOP = SND_LOOP # loop the sound until next sndPlaySound
32
- NOSTOP = SND_NOSTOP # don't stop any currently playing sound
33
- NOWAIT = SND_NOWAIT # don't wait if the driver is busy
34
- ALIAS = SND_ALIAS # name is a registry alias
35
- ALIAS_ID = SND_ALIAS_ID # alias is a predefined ID
36
- FILENAME = SND_FILENAME # name is file name
37
- RESOURCE = SND_RESOURCE # name is resource name or atom
38
- PURGE = SND_PURGE # purge non-static events for task
39
- APPLICATION = SND_APPLICATION # look for app specific association
40
-
41
- # Returns an array of all the available sound devices; their names contain
42
- # the type of the device and a zero-based ID number. Possible return values
43
- # are WAVEOUT, WAVEIN, MIDIOUT, MIDIIN, AUX or MIXER.
44
- #
45
- def self.devices
46
- devs = []
47
-
48
- begin
49
- 0.upto(waveOutGetNumDevs()){ |i| devs << "WAVEOUT#{i}" }
50
- 0.upto(waveInGetNumDevs()){ |i| devs << "WAVEIN#{i}" }
51
- 0.upto(midiOutGetNumDevs()){ |i| devs << "MIDIOUT#{i}" }
52
- 0.upto(midiInGetNumDevs()){ |i| devs << "MIDIIN#{i}" }
53
- 0.upto(auxGetNumDevs()){ |i| devs << "AUX#{i}" }
54
- 0.upto(mixerGetNumDevs()){ |i| devs << "MIXER#{i}" }
55
- rescue Exception
56
- raise Error, get_last_error
57
- end
58
-
59
- devs
60
- end
6
+ # The Sound class encapsulates various methods for playing sound as well
7
+ # as querying or configuring sound related properties.
8
+ class Sound
9
+ extend FFI::Library
10
+
11
+ private
12
+
13
+ ffi_lib :kernel32
14
+
15
+ attach_function :Beep, [:ulong, :ulong], :bool
16
+
17
+ ffi_lib :winmm
18
+
19
+ attach_function :PlaySound, [:string, :long, :ulong], :bool
20
+ attach_function :waveOutSetVolume, [:long, :ulong], :int
21
+ attach_function :waveOutGetVolume, [:long, :pointer], :int
22
+ attach_function :waveOutGetNumDevs, [], :int
23
+ attach_function :waveInGetNumDevs, [], :int
24
+ attach_function :midiOutGetNumDevs, [], :int
25
+ attach_function :midiInGetNumDevs, [], :int
26
+ attach_function :auxGetNumDevs, [], :int
27
+ attach_function :mixerGetNumDevs, [], :int
28
+
29
+ private_class_method :Beep, :PlaySound, :waveOutSetVolume, :waveOutGetVolume
30
+ private_class_method :waveInGetNumDevs, :waveOutGetNumDevs, :midiOutGetNumDevs
31
+ private_class_method :midiInGetNumDevs, :auxGetNumDevs, :mixerGetNumDevs
32
+
33
+ public
34
+
35
+ # The version of the win32-sound library
36
+ VERSION = '0.5.0'
61
37
 
62
- # Generates simple tones on the speaker. The function is synchronous; it
63
- # does not return control to its caller until the sound finishes.
64
- #
65
- # The frequency (in Hertz) must be between 37 and 32767.
66
- # The duration is in milliseconds.
67
- #
68
- def self.beep(frequency, duration)
69
- if frequency > HIGH_FREQUENCY || frequency < LOW_FREQUENCY
70
- raise Error, 'invalid frequency'
71
- end
72
-
73
- if 0 == Beep(frequency, duration)
74
- raise Error, get_last_error
75
- end
76
-
77
- self
38
+ LOW_FREQUENCY = 37
39
+ HIGH_FREQUENCY = 32767
40
+ MAX_VOLUME = 0xFFFF
41
+
42
+ SYNC = 0x00000000 # play synchronously (default)
43
+ ASYNC = 0x00000001 # play asynchronously
44
+ NODEFAULT = 0x00000002 # silence (!default) if sound not found
45
+ MEMORY = 0x00000004 # pszSound points to a memory file
46
+ LOOP = 0x00000008 # loop the sound until next sndPlaySound
47
+ NOSTOP = 0x00000010 # don't stop any currently playing sound
48
+ NOWAIT = 8192 # don't wait if the driver is busy
49
+ ALIAS = 65536 # name is a registry alias
50
+ ALIAS_ID = 1114112 # alias is a predefined ID
51
+ FILENAME = 131072 # name is file name
52
+ RESOURCE = 262148 # name is resource name or atom
53
+ PURGE = 0x00000040 # purge non-static events for task
54
+ APPLICATION = 0x00000080 # look for app specific association
55
+
56
+ # Returns an array of all the available sound devices; their names contain
57
+ # the type of the device and a zero-based ID number. Possible return values
58
+ # are WAVEOUT, WAVEIN, MIDIOUT, MIDIIN, AUX or MIXER.
59
+ #
60
+ def self.devices
61
+ devs = []
62
+
63
+ begin
64
+ 0.upto(waveOutGetNumDevs()){ |i| devs << "WAVEOUT#{i}" }
65
+ 0.upto(waveInGetNumDevs()){ |i| devs << "WAVEIN#{i}" }
66
+ 0.upto(midiOutGetNumDevs()){ |i| devs << "MIDIOUT#{i}" }
67
+ 0.upto(midiInGetNumDevs()){ |i| devs << "MIDIIN#{i}" }
68
+ 0.upto(auxGetNumDevs()){ |i| devs << "AUX#{i}" }
69
+ 0.upto(mixerGetNumDevs()){ |i| devs << "MIXER#{i}" }
70
+ rescue Exception
71
+ raise SystemCallError, FFI.errno, "GetNumDevs"
78
72
  end
79
-
80
- # Stops any currently playing waveform sound. If +purge+ is set to
81
- # true, then *all* sounds are stopped. The default is false.
82
- #
83
- def self.stop(purge = false)
84
- if purge && purge != 0
85
- flags = PURGE
86
- else
87
- flags = 0
88
- end
89
-
90
- unless PlaySound(0, 0, flags)
91
- raise Error, get_last_error
92
- end
93
-
94
- self
73
+
74
+ devs
75
+ end
76
+
77
+ # Generates simple tones on the speaker. The function is synchronous; it
78
+ # does not return control to its caller until the sound finishes.
79
+ #
80
+ # The frequency (in Hertz) must be between 37 and 32767.
81
+ # The duration is in milliseconds.
82
+ #
83
+ def self.beep(frequency, duration)
84
+ if frequency > HIGH_FREQUENCY || frequency < LOW_FREQUENCY
85
+ raise ArgumentError, 'invalid frequency'
95
86
  end
96
-
97
- # Plays the specified sound. The sound can be a wave file or a system
98
- # sound, when used in conjunction with the ALIAS flag.
99
- #
100
- # Valid flags:
101
- #
102
- # Sound::ALIAS
103
- # The sound parameter is a system-event alias in the registry or the
104
- # WIN.INI file. If the registry contains no such name, it plays the
105
- # system default sound unless the NODEFAULT value is also specified.
106
- # Do not use with FILENAME.
107
- #
108
- # Sound::APPLICATION
109
- # The sound is played using an application-specific association.
110
- #
111
- # Sound::ASYNC
112
- # The sound is played asynchronously and the function returns
113
- # immediately after beginning the sound.
114
- #
115
- # Sound::FILENAME
116
- # The sound parameter is the name of a WAV file. Do not use with
117
- # ALIAS.
118
- #
119
- # Sound::LOOP
120
- # The sound plays repeatedly until Sound.stop() is called. You must
121
- # also specify the ASYNC flag to loop sounds.
122
- #
123
- # Sound::MEMORY
124
- # The sound points to an image of a waveform sound in memory.
125
- #
126
- # Sound::NODEFAULT
127
- # If the sound cannot be found, the function returns silently without
128
- # playing the default sound.
129
- #
130
- # Sound::NOSTOP
131
- # If a sound is currently playing, the function immediately returns
132
- # false without playing the requested sound.
133
- #
134
- # Sound::NOWAIT
135
- # If the driver is busy, return immediately without playing the sound.
136
- #
137
- # Sound::PURGE
138
- # Stop playing all instances of the specified sound.
139
- #
140
- # Sound::SYNC
141
- # The sound is played synchronously and the function does not return
142
- # until the sound ends.
143
- #
144
- # Examples:
145
- #
146
- # require 'win32/sound'
147
- # include Win32
148
- #
149
- # # Play a wave file once
150
- # Sound.play('some_file.wav')
151
- #
152
- # # Play a wave file in an asynchronous loop for 2 seconds
153
- # Sound.play('some_file.wav', Sound::ASYNC | Sound::LOOP)
154
- # sleep 2
155
- # Sound.stop
156
- #
157
- def self.play(sound, flags = 0)
158
- unless PlaySound(sound, 0, flags)
159
- raise Error, get_last_error
160
- end
161
-
162
- self
87
+
88
+ if 0 == Beep(frequency, duration)
89
+ raise SystemCallError, FFI.errno, "Beep"
163
90
  end
164
-
165
- # Sets the volume for the left and right channel. If the +right_channel+
166
- # is omitted, the volume is set for *both* channels.
167
- #
168
- # You may optionally pass a single Integer rather than an Array, in which
169
- # case it is assumed you are setting both channels to the same value.
170
- #
171
- def self.set_wave_volume(left_channel, right_channel = nil)
172
- right_channel ||= left_channel
173
-
174
- lvolume = left_channel > MAX_VOLUME ? MAX_VOLUME : left_channel
175
- rvolume = right_channel > MAX_VOLUME ? MAX_VOLUME : right_channel
176
-
177
- volume = lvolume | rvolume << 16
178
-
179
- if waveOutSetVolume(-1, volume) != 0
180
- raise Error, get_last_error
181
- end
182
-
183
- self
91
+
92
+ self
93
+ end
94
+
95
+ # Stops any currently playing waveform sound. If +purge+ is set to
96
+ # true, then *all* sounds are stopped. The default is false.
97
+ #
98
+ def self.stop(purge = false)
99
+ if purge && purge != 0
100
+ flags = PURGE
101
+ else
102
+ flags = 0
184
103
  end
185
-
186
- # Returns a 2-element array that contains the volume for the left channel
187
- # and right channel, respectively.
188
- def self.wave_volume
189
- volume = [0].pack('L')
190
- if waveOutGetVolume(-1, volume) != 0
191
- raise Error, get_last_error
192
- end
193
- volume = volume.unpack('L').first
194
- [low_word(volume), high_word(volume)]
104
+
105
+ unless PlaySound(nil, 0, flags)
106
+ raise SystemCallError, FFI.errno, "PlaySound"
195
107
  end
196
108
 
197
- class << self
198
- alias get_wave_volume wave_volume
109
+ self
110
+ end
111
+
112
+ # Plays the specified sound. The sound can be a wave file or a system
113
+ # sound, when used in conjunction with the ALIAS flag.
114
+ #
115
+ # Valid flags:
116
+ #
117
+ # Sound::ALIAS
118
+ # The sound parameter is a system-event alias in the registry or the
119
+ # WIN.INI file. If the registry contains no such name, it plays the
120
+ # system default sound unless the NODEFAULT value is also specified.
121
+ # Do not use with FILENAME.
122
+ #
123
+ # Sound::APPLICATION
124
+ # The sound is played using an application-specific association.
125
+ #
126
+ # Sound::ASYNC
127
+ # The sound is played asynchronously and the function returns
128
+ # immediately after beginning the sound.
129
+ #
130
+ # Sound::FILENAME
131
+ # The sound parameter is the name of a WAV file. Do not use with
132
+ # ALIAS.
133
+ #
134
+ # Sound::LOOP
135
+ # The sound plays repeatedly until Sound.stop() is called. You must
136
+ # also specify the ASYNC flag to loop sounds.
137
+ #
138
+ # Sound::MEMORY
139
+ # The sound points to an image of a waveform sound in memory.
140
+ #
141
+ # Sound::NODEFAULT
142
+ # If the sound cannot be found, the function returns silently without
143
+ # playing the default sound.
144
+ #
145
+ # Sound::NOSTOP
146
+ # If a sound is currently playing, the function immediately returns
147
+ # false without playing the requested sound.
148
+ #
149
+ # Sound::NOWAIT
150
+ # If the driver is busy, return immediately without playing the sound.
151
+ #
152
+ # Sound::PURGE
153
+ # Stop playing all instances of the specified sound.
154
+ #
155
+ # Sound::SYNC
156
+ # The sound is played synchronously and the function does not return
157
+ # until the sound ends.
158
+ #
159
+ # Examples:
160
+ #
161
+ # require 'win32/sound'
162
+ # include Win32
163
+ #
164
+ # # Play a wave file once
165
+ # Sound.play('some_file.wav')
166
+ #
167
+ # # Play a wave file in an asynchronous loop for 2 seconds
168
+ # Sound.play('some_file.wav', Sound::ASYNC | Sound::LOOP)
169
+ # sleep 2
170
+ # Sound.stop
171
+ #
172
+ def self.play(sound, flags = 0)
173
+ unless PlaySound(sound, 0, flags)
174
+ raise SystemCallError, FFI.errno, "PlaySound"
199
175
  end
200
-
201
- private
202
-
203
- def self.low_word(num)
204
- num & 0xFFFF
176
+
177
+ self
178
+ end
179
+
180
+ # Sets the volume for the left and right channel. If the +right_channel+
181
+ # is omitted, the volume is set for *both* channels.
182
+ #
183
+ # You may optionally pass a single Integer rather than an Array, in which
184
+ # case it is assumed you are setting both channels to the same value.
185
+ #
186
+ def self.set_wave_volume(left_channel, right_channel = nil)
187
+ right_channel ||= left_channel
188
+
189
+ lvolume = left_channel > MAX_VOLUME ? MAX_VOLUME : left_channel
190
+ rvolume = right_channel > MAX_VOLUME ? MAX_VOLUME : right_channel
191
+
192
+ volume = lvolume | rvolume << 16
193
+
194
+ if waveOutSetVolume(-1, volume) != 0
195
+ raise SystemCallError, FFI.errno, "waveOutSetVolume"
205
196
  end
206
-
207
- def self.high_word(num)
208
- num >> 16
197
+
198
+ self
199
+ end
200
+
201
+ # Returns a 2-element array that contains the volume for the left channel
202
+ # and right channel, respectively.
203
+ def self.wave_volume
204
+ ptr = FFI::MemoryPointer.new(:ulong)
205
+
206
+ if waveOutGetVolume(-1, ptr) != 0
207
+ raise SystemCallError, FFI.errno, "waveOutGetVolume"
209
208
  end
210
- end
209
+
210
+ volume = ptr.read_long
211
+
212
+ [low_word(volume), high_word(volume)]
213
+ end
214
+
215
+ class << self
216
+ alias get_wave_volume wave_volume
217
+ end
218
+
219
+ private
220
+
221
+ def self.low_word(num)
222
+ num & 0xFFFF
223
+ end
224
+
225
+ def self.high_word(num)
226
+ num >> 16
227
+ end
228
+ end
211
229
  end
@@ -4,88 +4,100 @@
4
4
  # Test suite for the win32-sound library. You should run this test case
5
5
  # via the 'rake test' task.
6
6
  ##########################################################################
7
- require 'test/unit'
7
+ require 'test-unit'
8
8
  require 'win32/sound'
9
9
  include Win32
10
10
 
11
11
  class TC_Win32_Sound < Test::Unit::TestCase
12
- def setup
13
- @wav = "c:\\windows\\media\\chimes.wav"
14
- end
15
-
16
- def test_version
17
- assert_equal('0.4.2', Sound::VERSION)
18
- end
19
-
20
- def test_beep
21
- assert_respond_to(Sound, :beep)
22
- assert_nothing_raised{ Sound.beep(55, 100) }
23
- end
24
-
25
- def test_beep_expected_errors
26
- assert_raises(Sound::Error){ Sound.beep(0, 100) }
27
- assert_raises(ArgumentError){ Sound.beep }
28
- assert_raises(ArgumentError){ Sound.beep(500) }
29
- assert_raises(ArgumentError){ Sound.beep(500, 500, 5) }
30
- end
31
-
32
- def test_devices
33
- assert_respond_to(Sound, :devices)
34
- assert_nothing_raised{ Sound.devices }
35
- assert_kind_of(Array,Sound.devices)
36
- end
37
-
38
- def test_stop
39
- assert_respond_to(Sound, :stop)
40
- assert_nothing_raised{ Sound.stop }
41
- assert_nothing_raised{ Sound.stop(true) }
42
- end
43
-
44
- def test_get_volume_basic
45
- assert_respond_to(Sound, :wave_volume)
46
- assert_respond_to(Sound, :get_wave_volume)
47
- assert_nothing_raised{ Sound.get_wave_volume }
48
- end
49
-
50
- def test_get_volume
51
- assert_kind_of(Array, Sound.get_wave_volume)
52
- assert_equal(2, Sound.get_wave_volume.length)
53
- end
12
+ def setup
13
+ @wav = "c:\\windows\\media\\chimes.wav"
14
+ end
54
15
 
55
- def test_set_volume
56
- assert_respond_to(Sound, :set_wave_volume)
57
- assert_nothing_raised{ Sound.set_wave_volume(30000) } # About half
58
- assert_nothing_raised{ Sound.set_wave_volume(30000, 30000) }
59
- end
60
-
61
- def test_play
62
- assert_respond_to(Sound, :play)
63
- assert_nothing_raised{ Sound.play(@wav) }
64
- end
16
+ def test_version
17
+ assert_equal('0.5.0', Sound::VERSION)
18
+ end
65
19
 
66
- def test_play_alias
67
- assert_nothing_raised{ Sound.play('SystemAsterisk', Sound::ALIAS) }
68
- end
69
-
70
- def test_expected_errors
71
- assert_raises(Sound::Error){ Sound.beep(-1, 1) }
72
- end
73
-
74
- def test_constants
75
- assert_not_nil(Sound::ALIAS)
76
- assert_not_nil(Sound::APPLICATION)
77
- assert_not_nil(Sound::ASYNC)
78
- assert_not_nil(Sound::FILENAME)
79
- assert_not_nil(Sound::LOOP)
80
- assert_not_nil(Sound::MEMORY)
81
- assert_not_nil(Sound::NODEFAULT)
82
- assert_not_nil(Sound::NOSTOP)
83
- assert_not_nil(Sound::NOWAIT)
84
- assert_not_nil(Sound::PURGE)
85
- assert_not_nil(Sound::SYNC)
86
- end
87
-
88
- def teardown
89
- @wav = nil
90
- end
20
+ def test_beep
21
+ assert_respond_to(Sound, :beep)
22
+ assert_nothing_raised{ Sound.beep(55, 100) }
23
+ end
24
+
25
+ def test_beep_expected_errors
26
+ assert_raises(ArgumentError){ Sound.beep(0, 100) }
27
+ assert_raises(ArgumentError){ Sound.beep }
28
+ assert_raises(ArgumentError){ Sound.beep(500) }
29
+ assert_raises(ArgumentError){ Sound.beep(500, 500, 5) }
30
+ end
31
+
32
+ def test_devices
33
+ assert_respond_to(Sound, :devices)
34
+ assert_nothing_raised{ Sound.devices }
35
+ assert_kind_of(Array,Sound.devices)
36
+ end
37
+
38
+ def test_stop
39
+ assert_respond_to(Sound, :stop)
40
+ assert_nothing_raised{ Sound.stop }
41
+ assert_nothing_raised{ Sound.stop(true) }
42
+ end
43
+
44
+ def test_get_volume_basic
45
+ assert_respond_to(Sound, :wave_volume)
46
+ assert_respond_to(Sound, :get_wave_volume)
47
+ assert_nothing_raised{ Sound.get_wave_volume }
48
+ end
49
+
50
+ def test_get_volume
51
+ assert_kind_of(Array, Sound.get_wave_volume)
52
+ assert_equal(2, Sound.get_wave_volume.length)
53
+ end
54
+
55
+ def test_set_volume
56
+ assert_respond_to(Sound, :set_wave_volume)
57
+ assert_nothing_raised{ Sound.set_wave_volume(30000) } # About half
58
+ assert_nothing_raised{ Sound.set_wave_volume(30000, 30000) }
59
+ end
60
+
61
+ def test_play
62
+ assert_respond_to(Sound, :play)
63
+ assert_nothing_raised{ Sound.play(@wav) }
64
+ end
65
+
66
+ def test_play_alias
67
+ assert_nothing_raised{ Sound.play('SystemAsterisk', Sound::ALIAS) }
68
+ end
69
+
70
+ def test_expected_errors
71
+ assert_raises(ArgumentError){ Sound.beep(-1, 1) }
72
+ end
73
+
74
+ def test_constants
75
+ assert_not_nil(Sound::ALIAS)
76
+ assert_not_nil(Sound::APPLICATION)
77
+ assert_not_nil(Sound::ASYNC)
78
+ assert_not_nil(Sound::FILENAME)
79
+ assert_not_nil(Sound::LOOP)
80
+ assert_not_nil(Sound::MEMORY)
81
+ assert_not_nil(Sound::NODEFAULT)
82
+ assert_not_nil(Sound::NOSTOP)
83
+ assert_not_nil(Sound::NOWAIT)
84
+ assert_not_nil(Sound::PURGE)
85
+ assert_not_nil(Sound::SYNC)
86
+ end
87
+
88
+ test "ffi functions are private" do
89
+ assert_not_respond_to(Sound, :Beep)
90
+ assert_not_respond_to(Sound, :waveOutSetVolume)
91
+ assert_not_respond_to(Sound, :waveOutGetVolume)
92
+ assert_not_respond_to(Sound, :waveOutGetNumDevs)
93
+ assert_not_respond_to(Sound, :waveInGetNumDevs)
94
+ assert_not_respond_to(Sound, :midiInGetNumDevs)
95
+ assert_not_respond_to(Sound, :midiOutGetNumDevs)
96
+ assert_not_respond_to(Sound, :auxGetNumDevs)
97
+ assert_not_respond_to(Sound, :mixerGetNumDevs)
98
+ end
99
+
100
+ def teardown
101
+ @wav = nil
102
+ end
91
103
  end
data/win32-sound.gemspec CHANGED
@@ -1,28 +1,25 @@
1
1
  require 'rubygems'
2
2
 
3
- spec = Gem::Specification.new do |gem|
4
- gem.name = 'win32-sound'
5
- gem.version = '0.4.2'
6
- gem.author = 'Daniel J. Berger'
7
- gem.license = 'Artistic 2.0'
8
- gem.email = 'djberg96@gmail.com'
9
- gem.homepage = 'http://www.rubyforge.org/projects/win32utils'
10
- gem.platform = Gem::Platform::RUBY
11
- gem.summary = 'A library for playing with sound on MS Windows.'
12
- gem.test_file = 'test/test_win32_sound.rb'
13
- gem.has_rdoc = true
14
- gem.files = Dir['**/*'].reject{ |f| f.include?('CVS') }
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'win32-sound'
5
+ spec.version = '0.5.0'
6
+ spec.author = 'Daniel J. Berger'
7
+ spec.license = 'Artistic 2.0'
8
+ spec.email = 'djberg96@gmail.com'
9
+ spec.homepage = 'http://www.rubyforge.org/projects/win32utils'
10
+ spec.summary = 'A library for playing with sound on MS Windows.'
11
+ spec.test_file = 'test/test_win32_sound.rb'
12
+ spec.files = Dir['**/*'] << ".gemtest"
15
13
 
16
- gem.extra_rdoc_files = ['CHANGES', 'README', 'MANIFEST']
17
- gem.rubyforge_project = 'win32utils'
14
+ spec.extra_rdoc_files = ['CHANGES', 'README', 'MANIFEST']
15
+ spec.rubyforge_project = 'win32utils'
18
16
 
19
- gem.add_dependency('windows-pr', '>= 1.0.6')
20
-
21
- gem.description = <<-EOF
22
- The win32-sound library provides an interface for playing various
23
- sounds on MS Windows operating systems, including system sounds and
24
- wave files, as well as querying and configuring sound related properties.
25
- EOF
26
- end
17
+ spec.add_dependency('ffi')
18
+ spec.add_development_dependency('test-unit')
27
19
 
28
- Gem::Builder.new(spec).build
20
+ spec.description = <<-EOF
21
+ The win32-sound library provides an interface for playing various
22
+ sounds on MS Windows operating systems, including system sounds and
23
+ wave files, as well as querying and configuring sound related properties.
24
+ EOF
25
+ end
metadata CHANGED
@@ -1,38 +1,59 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: win32-sound
3
- version: !ruby/object:Gem::Version
4
- version: 0.4.2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
5
+ prerelease:
5
6
  platform: ruby
6
- authors:
7
+ authors:
7
8
  - Daniel J. Berger
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
-
12
- date: 2009-08-06 00:00:00 -06:00
13
- default_executable:
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: windows-pr
12
+ date: 2012-06-28 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: ffi
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
17
22
  type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: 1.0.6
24
- version:
25
- description: " The win32-sound library provides an interface for playing various\n sounds on MS Windows operating systems, including system sounds and\n wave files, as well as querying and configuring sound related properties.\n"
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: test-unit
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: ! " The win32-sound library provides an interface for playing various\n
47
+ \ sounds on MS Windows operating systems, including system sounds and\n wave
48
+ files, as well as querying and configuring sound related properties.\n"
26
49
  email: djberg96@gmail.com
27
50
  executables: []
28
-
29
51
  extensions: []
30
-
31
- extra_rdoc_files:
52
+ extra_rdoc_files:
32
53
  - CHANGES
33
54
  - README
34
55
  - MANIFEST
35
- files:
56
+ files:
36
57
  - CHANGES
37
58
  - examples/example_win32_sound.rb
38
59
  - lib/win32/sound.rb
@@ -41,33 +62,31 @@ files:
41
62
  - README
42
63
  - test/test_win32_sound.rb
43
64
  - win32-sound.gemspec
44
- has_rdoc: true
65
+ - .gemtest
45
66
  homepage: http://www.rubyforge.org/projects/win32utils
46
- licenses:
67
+ licenses:
47
68
  - Artistic 2.0
48
69
  post_install_message:
49
70
  rdoc_options: []
50
-
51
- require_paths:
71
+ require_paths:
52
72
  - lib
53
- required_ruby_version: !ruby/object:Gem::Requirement
54
- requirements:
55
- - - ">="
56
- - !ruby/object:Gem::Version
57
- version: "0"
58
- version:
59
- required_rubygems_version: !ruby/object:Gem::Requirement
60
- requirements:
61
- - - ">="
62
- - !ruby/object:Gem::Version
63
- version: "0"
64
- version:
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ! '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
65
85
  requirements: []
66
-
67
86
  rubyforge_project: win32utils
68
- rubygems_version: 1.3.4
87
+ rubygems_version: 1.8.24
69
88
  signing_key:
70
89
  specification_version: 3
71
90
  summary: A library for playing with sound on MS Windows.
72
- test_files:
91
+ test_files:
73
92
  - test/test_win32_sound.rb