harpjs 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in harpjs.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Daniel Moore
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Harpjs
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'harpjs'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install harpjs
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'harpjs/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "harpjs"
8
+ spec.version = Harpjs::VERSION
9
+ spec.authors = ["Daniel Moore"]
10
+ spec.email = ["yahivin@gmail.com"]
11
+ spec.description = %q{ Simple HTML5 audio wrappers }
12
+ spec.summary = %q{ Simple HTML5 audio wrappers }
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,12 @@
1
+ require "harpjs/version"
2
+
3
+ if defined? ::Rails
4
+ class Engine < ::Rails::Engine
5
+ config.paths['app/assets'] = "source"
6
+ end
7
+ elsif defined? ::Sprockets
8
+ root_dir = File.expand_path(File.dirname(File.dirname(__FILE__)))
9
+ asset_dir = File.join(root_dir, "source")
10
+
11
+ ::Sprockets.append_path asset_dir
12
+ end
@@ -0,0 +1,3 @@
1
+ module Harpjs
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,89 @@
1
+ ###*
2
+ The Music object provides an easy API to play
3
+ songs from your sounds project directory. By
4
+ default, the track is looped.
5
+
6
+ <code><pre>
7
+ Music.play('intro_theme')
8
+ </pre></code>
9
+
10
+ @name Music
11
+ @namespace
12
+ ###
13
+
14
+ Music = (->
15
+ # TODO: Load this from local storage of user preferences
16
+ globalMusicVolume = 1
17
+ trackVolume = 1
18
+
19
+ # TODO: Add format fallbacks
20
+ track = $ "<audio />",
21
+ loop: "loop"
22
+ .appendTo('body').get(0)
23
+
24
+ appendSources = (audio, name) ->
25
+ [
26
+ ["ogg", "audio/ogg"]
27
+ ["mp3", "audio/mpeg"]
28
+ ].forEach ([extension, mimeType]) ->
29
+ source = document.createElement('source')
30
+ source.type = mimeType
31
+ source.src = "#{name}.#{extension}"
32
+ audio.appendChild(source)
33
+
34
+ updateTrackVolume = ->
35
+ track.volume = globalMusicVolume * trackVolume
36
+
37
+ ###*
38
+ Set the global volume modifier for all music.
39
+
40
+ Any value set is clamped between 0 and 1. This is multiplied
41
+ into each individual track that plays.
42
+
43
+ If no argument is given return the current global music volume.
44
+
45
+ @name globalVolume
46
+ @methodOf Music
47
+ @param {Number} [newVolume] The volume to set
48
+ ###
49
+ globalVolume: (newVolume) ->
50
+ if newVolume?
51
+ globalMusicVolume = newVolume.clamp(0, 1)
52
+
53
+ updateTrackVolume()
54
+
55
+ return globalMusicVolume
56
+
57
+ ###*
58
+ Plays a music track.
59
+
60
+ @name play
61
+ @methodOf Music
62
+ @param {String} name The name of the track to play.
63
+ ###
64
+ play: (name) ->
65
+ updateTrackVolume()
66
+
67
+ appendSources(track, "#{BASE_URL}/music/#{name}")
68
+
69
+ track.play()
70
+
71
+ ###*
72
+ Get or set the current music volume. Any value passed is
73
+ clamped between 0 and 1. Use this to adjust the volume of
74
+ individual tracks or to increase or decrease volume during
75
+ gameplay.
76
+
77
+ @name volume
78
+ @methodOf Music
79
+ @param {Number} [newVolume] The volume to set to.
80
+ ###
81
+ volume: (newVolume) ->
82
+ if newVolume?
83
+ trackVolume = newVolume.clamp(0, 1)
84
+ updateTrackVolume()
85
+
86
+ return this
87
+ else
88
+ return trackVolume
89
+ )()
@@ -0,0 +1,146 @@
1
+ (($) ->
2
+ ###*
3
+ A simple interface for playing sounds in games.
4
+
5
+ @name Sound
6
+ @namespace
7
+ ###
8
+ directory = App?.directories?.sounds || "sounds"
9
+ format = "wav"
10
+ sounds = {}
11
+ globalVolume = 1
12
+
13
+ loadSoundChannel = (name) ->
14
+ url = "#{BASE_URL}/#{directory}/#{name}.#{format}"
15
+
16
+ sound = $('<audio />',
17
+ autobuffer: true
18
+ preload: 'auto'
19
+ src: url
20
+ ).get(0)
21
+
22
+ Sound = (id, maxChannels) ->
23
+ play: ->
24
+ Sound.play(id, maxChannels)
25
+
26
+ stop: ->
27
+ Sound.stop(id)
28
+
29
+ Object.extend Sound,
30
+ ###*
31
+ Set the global volume modifier for all sound effects.
32
+
33
+ Any value set is clamped between 0 and 1. This is multiplied
34
+ into each individual effect that plays.
35
+
36
+ If no argument is given return the current global sound effect volume.
37
+
38
+ @name volume
39
+ @methodOf Sound
40
+ @param {Number} [newVolume] The volume to set
41
+ ###
42
+ volume: (newVolume) ->
43
+ if newVolume?
44
+ globalVolume = newVolume.clamp(0, 1)
45
+
46
+ return globalVolume
47
+
48
+ ###*
49
+ Play a sound from your sounds
50
+ directory with the name of `id`.
51
+
52
+ <code><pre>
53
+ # plays a sound called explode from your sounds directory
54
+ Sound.play('explode')
55
+ </pre></code>
56
+
57
+ @name play
58
+ @methodOf Sound
59
+
60
+ @param {String} id id or name of the sound file to play
61
+ @param {String} maxChannels max number of sounds able to be played simultaneously
62
+ ###
63
+ play: (id, maxChannels) ->
64
+ # TODO: Too many channels crash Chrome!!!1
65
+ maxChannels ||= 4
66
+
67
+ unless sounds[id]
68
+ sounds[id] = [loadSoundChannel(id)]
69
+
70
+ channels = sounds[id]
71
+
72
+ freeChannels = channels.select (sound) ->
73
+ sound.currentTime == sound.duration || sound.currentTime == 0
74
+
75
+ if channel = freeChannels.first()
76
+ try
77
+ channel.currentTime = 0
78
+
79
+ channel.volume = globalVolume
80
+ channel.play()
81
+ else
82
+ if !maxChannels || channels.length < maxChannels
83
+ sound = loadSoundChannel(id)
84
+ channels.push(sound)
85
+ sound.play()
86
+ sound.volume = globalVolume
87
+
88
+ ###*
89
+ Play a sound from the given
90
+ url with the name of `id`.
91
+
92
+ <code><pre>
93
+ # plays the sound at the specified url
94
+ Sound.playFromUrl('http://YourSoundWebsite.com/explode.wav')
95
+ </pre></code>
96
+
97
+ @name playFromUrl
98
+ @methodOf Sound
99
+
100
+ @param {String} url location of sound file to play
101
+
102
+ @returns {Sound} this sound object
103
+ ###
104
+ playFromUrl: (url) ->
105
+ sound = $('<audio />').get(0)
106
+ sound.src = url
107
+
108
+ sound.play()
109
+ sound.volume = globalVolume
110
+
111
+ return sound
112
+
113
+ ###*
114
+ Stop a sound while it is playing.
115
+
116
+ <code><pre>
117
+ # stops the sound 'explode' from
118
+ # playing if it is currently playing
119
+ Sound.stop('explode')
120
+ </pre></code>
121
+
122
+ @name stop
123
+ @methodOf Sound
124
+
125
+ @param {String} id id or name of sound to stop playing.
126
+ ###
127
+ stop: (id) ->
128
+ sounds[id]?.stop()
129
+
130
+ ###*
131
+ Set the global volume modifier for all sound effects.
132
+
133
+ Any value set is clamped between 0 and 1. This is multiplied
134
+ into each individual effect that plays.
135
+
136
+ If no argument is given return the current global sound effect volume.
137
+
138
+ @name globalVolume
139
+ @deprecated
140
+ @methodOf Sound
141
+ @param {Number} [newVolume] The volume to set
142
+ ###
143
+ Sound.globalVolume = Sound.volume
144
+
145
+ (exports ? this)["Sound"] = Sound
146
+ )(jQuery)
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: harpjs
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Daniel Moore
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-04-29 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
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: ! ' Simple HTML5 audio wrappers '
47
+ email:
48
+ - yahivin@gmail.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - Gemfile
55
+ - LICENSE.txt
56
+ - README.md
57
+ - Rakefile
58
+ - harpjs.gemspec
59
+ - lib/harpjs.rb
60
+ - lib/harpjs/version.rb
61
+ - source/music.coffee
62
+ - source/sound.coffee
63
+ homepage: ''
64
+ licenses:
65
+ - MIT
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ! '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirements: []
83
+ rubyforge_project:
84
+ rubygems_version: 1.8.24
85
+ signing_key:
86
+ specification_version: 3
87
+ summary: Simple HTML5 audio wrappers
88
+ test_files: []