uzi-soundmanager 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
4
+ *.swp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in uzi-soundmanager.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,157 @@
1
+ require 'singleton'
2
+
3
+ module Uzi
4
+ class SoundManager
5
+ include Singleton
6
+
7
+ attr_reader :window
8
+ attr_accessor :samples, :instances, :songs, :block, :limit
9
+
10
+ def setup(window, directory)
11
+ @window, @directory = window, directory
12
+
13
+ @samples = {}
14
+ @instances = {}
15
+
16
+ @songs = {}
17
+
18
+ @block = []
19
+ @limit = {}
20
+ end
21
+
22
+
23
+
24
+ def get_filename(key)
25
+ Dir["#{@directory}/#{key.to_s}.{wav,ogg,mp3}"].first
26
+ end
27
+
28
+ def load(key, limit=nil)
29
+ @instances[key] ||= []
30
+ unless @samples.has_key?(key)
31
+ @samples[key] = Gosu::Sample.new(@window, get_filename(key))
32
+ end
33
+
34
+ @limit[key] = limit unless limit.nil?
35
+
36
+ return @samples[key]
37
+ end
38
+
39
+ def load_song(key)
40
+ unless @songs.has_key?(key)
41
+ @songs[key] = Gosu::Song.new(@window, get_filename(key))
42
+ end
43
+
44
+ return @songs[key]
45
+ end
46
+
47
+
48
+
49
+ def unload(key)
50
+ if @samples.has_key?(key)
51
+ stop(key)
52
+
53
+ @samples.delete(key)
54
+ @instances.delete(key)
55
+ end
56
+ end
57
+
58
+ def unload_song(key)
59
+ if @songs.has_key?(key)
60
+ stop_song(key)
61
+
62
+ @songs.delete(key)
63
+ end
64
+ end
65
+
66
+
67
+
68
+ def play(key, *args)
69
+ return if @block.include?(key)
70
+
71
+ if @limit.has_key?(key) && @instances[key].length >= @limit[key]
72
+ @instances[key].first.stop
73
+ @instances[key].shift
74
+ end
75
+
76
+ @instances[key] << @samples[key].play(*args)
77
+ return @instances[key].last
78
+ end
79
+
80
+ def playing?(key)
81
+ @instances.has_key?(key) && @instances[key].any?{|s| s.playing? }
82
+ end
83
+
84
+
85
+
86
+ def play_song(key, *args)
87
+ @songs[key].play(*args)
88
+ end
89
+
90
+ def song_playing?(key)
91
+ @songs[key].playing?
92
+ end
93
+
94
+ def stop_song(key)
95
+ @songs[key].stop if @songs[key].playing? || @songs[key].paused?
96
+ end
97
+
98
+ def pause_song(key)
99
+ @songs[key].pause if @songs[key].playing?
100
+ end
101
+
102
+ def resume_song(key)
103
+ @songs[key].play if @songs[key].paused?
104
+ end
105
+
106
+
107
+
108
+ def clear
109
+ @instances.each do|k,v|
110
+ v.delete_if{|i| !i.playing? && !i.paused? }
111
+ end
112
+ end
113
+
114
+
115
+
116
+ def stop(key)
117
+ @instances[key].each{|i| i.stop }
118
+ end
119
+
120
+ def pause(key)
121
+ @instances[key].each{|i| i.pause if i.playing? }
122
+ end
123
+
124
+ def resume(key)
125
+ @instances[key].each{|i| i.resume if i.paused? }
126
+ end
127
+
128
+
129
+
130
+ def stop_all
131
+ @instances.keys.each{|key| stop(key) }
132
+ end
133
+
134
+ def pause_all
135
+ @instances.keys.each{|key| pause(key) }
136
+ end
137
+
138
+ def resume_all
139
+ @instances.keys.each{|key| resume(key) }
140
+ end
141
+
142
+
143
+
144
+ def block(key, &block)
145
+ @block << key
146
+
147
+ if block_given?
148
+ block.call
149
+ unblock(key)
150
+ end
151
+ end
152
+
153
+ def unblock(key)
154
+ @block.delete_if{|b| b == key }
155
+ end
156
+ end
157
+ end
@@ -0,0 +1,5 @@
1
+ module Uzi
2
+ class Soundmanager
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "uzi-soundmanager/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "uzi-soundmanager"
7
+ s.version = Uzi::Soundmanager::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Michael Morin"]
10
+ s.email = ["michael.c.morin@gmail.com"]
11
+ s.homepage = "http://rubygems.org/gems/uzi-soundmanager"
12
+ s.summary = %q{A class for loading and managing Gosu::SoundInstance and Gosu::Song objects.}
13
+ s.description = %q{A class for loading and managing Gosu::SoundInstance and Gosu::Song objects.}
14
+
15
+ s.rubyforge_project = "uzi-soundmanager"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: uzi-soundmanager
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Michael Morin
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-10-18 00:00:00 -04:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: A class for loading and managing Gosu::SoundInstance and Gosu::Song objects.
23
+ email:
24
+ - michael.c.morin@gmail.com
25
+ executables: []
26
+
27
+ extensions: []
28
+
29
+ extra_rdoc_files: []
30
+
31
+ files:
32
+ - .gitignore
33
+ - Gemfile
34
+ - Rakefile
35
+ - lib/uzi-soundmanager.rb
36
+ - lib/uzi-soundmanager/version.rb
37
+ - uzi-soundmanager.gemspec
38
+ has_rdoc: true
39
+ homepage: http://rubygems.org/gems/uzi-soundmanager
40
+ licenses: []
41
+
42
+ post_install_message:
43
+ rdoc_options: []
44
+
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ hash: 3
53
+ segments:
54
+ - 0
55
+ version: "0"
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 3
62
+ segments:
63
+ - 0
64
+ version: "0"
65
+ requirements: []
66
+
67
+ rubyforge_project: uzi-soundmanager
68
+ rubygems_version: 1.3.7
69
+ signing_key:
70
+ specification_version: 3
71
+ summary: A class for loading and managing Gosu::SoundInstance and Gosu::Song objects.
72
+ test_files: []
73
+