Pachelbel 1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/README.md +29 -0
- data/lib/Pachelbel.rb +8 -0
- data/lib/project/Pachelbel.rb +111 -0
- metadata +62 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6a36f16adf11839e845eb170a3c2300ef16d89ba
|
4
|
+
data.tar.gz: 1218462e10ef281509b7a31a6121629ad8e055f4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 592c3cbcaeeab23cb4542a6bb254ab8698a7b831e85c3e46edb4c95050e2f9a9975928729db75812da36796a3482d1827b49a70047c33069a7add1be5c05ee64
|
7
|
+
data.tar.gz: ee515583a6dbcb075f27458baf534381620b62979842c1c05cb2e6c9edc41369e8f4d0c4581dc792bc1ffd8f99302357d497baf2d84f5360d365b609069291bf
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Pachelbel
|
2
|
+
|
3
|
+
Pachelbel makes processing and synthesizing audio in RubyMotion a breeze. It's built on top of the Web Audio API, which was designed to be simple, yet powerful.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'Pachelbel'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install Pachelbel
|
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
|
data/lib/Pachelbel.rb
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
unless defined?(Motion::Project::Config)
|
2
|
+
raise "This file must be required within a RubyMotion project Rakefile."
|
3
|
+
end
|
4
|
+
|
5
|
+
lib_dir_path = File.dirname(File.expand_path(__FILE__))
|
6
|
+
Motion::Project::App.setup do |app|
|
7
|
+
app.files.unshift(Dir.glob(File.join(lib_dir_path, "project/**/*.rb")))
|
8
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
module Pachelbel
|
2
|
+
class AudioContext
|
3
|
+
attr_reader :webview
|
4
|
+
|
5
|
+
HTML = '<script>' + 'window.AudioContext = window.AudioContext || window.webkitAudioContext;' +
|
6
|
+
'var audio_context = new AudioContext();' + 'var audio_nodes = [audio_context.destination];' + '</script>'
|
7
|
+
|
8
|
+
def run_js(script)
|
9
|
+
@webview.stringByEvaluatingJavaScriptFromString script
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
@webview = UIWebView.new
|
14
|
+
@webview.delegate = self
|
15
|
+
@webview.loadHTMLString HTML, baseURL: nil
|
16
|
+
end
|
17
|
+
|
18
|
+
def webViewDidFinishLoad(_)
|
19
|
+
run_js 'audio_context.createOscillator();' # workaround to start timer
|
20
|
+
end
|
21
|
+
|
22
|
+
# API Attributes
|
23
|
+
|
24
|
+
def currentTime
|
25
|
+
run_js('audio_context.currentTime;').to_f
|
26
|
+
end
|
27
|
+
|
28
|
+
def destination
|
29
|
+
@destination ||= begin
|
30
|
+
object = AudioDestinationNode.allocate
|
31
|
+
object._audio_context = self
|
32
|
+
object._index = 0
|
33
|
+
object
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def listener
|
38
|
+
run_js('audio_context.listener;')
|
39
|
+
end
|
40
|
+
|
41
|
+
def sampleRate
|
42
|
+
run_js('audio_context.sampleRate;').to_f
|
43
|
+
end
|
44
|
+
|
45
|
+
# API Constructors
|
46
|
+
|
47
|
+
def createOscillator
|
48
|
+
object = Oscillator.allocate
|
49
|
+
object._audio_context = self
|
50
|
+
object._index = run_js('audio_nodes.push( audio_context.createOscillator() );').to_i - 1
|
51
|
+
object
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
class AudioNode
|
56
|
+
attr_reader :audio_context
|
57
|
+
attr_reader :index
|
58
|
+
|
59
|
+
def run_js(script)
|
60
|
+
@audio_context.run_js script
|
61
|
+
end
|
62
|
+
|
63
|
+
def _audio_context=(value)
|
64
|
+
@audio_context = value
|
65
|
+
end
|
66
|
+
|
67
|
+
def _index=(value)
|
68
|
+
@index = value
|
69
|
+
end
|
70
|
+
|
71
|
+
def _js_snippet
|
72
|
+
"audio_nodes[#{@index}]"
|
73
|
+
end
|
74
|
+
|
75
|
+
# API Methods
|
76
|
+
|
77
|
+
def connect(destination)
|
78
|
+
run_js("#{_js_snippet}.connect(#{destination._js_snippet});")
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
class AudioDestinationNode < AudioNode
|
83
|
+
# API Attributes
|
84
|
+
|
85
|
+
def maxChannelCount
|
86
|
+
run_js("#{_js_snippet}.maxChannelCount;").to_i
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
class Oscillator < AudioNode
|
91
|
+
# API Attributes
|
92
|
+
|
93
|
+
def frequency
|
94
|
+
run_js("#{_js_snippet}.frequency.value;").to_f
|
95
|
+
end
|
96
|
+
|
97
|
+
def frequency=(value)
|
98
|
+
run_js("#{_js_snippet}.frequency.value = #{value.to_f};").to_f
|
99
|
+
end
|
100
|
+
|
101
|
+
# API Methods
|
102
|
+
|
103
|
+
def start(time)
|
104
|
+
run_js("#{_js_snippet}.start(#{time});")
|
105
|
+
end
|
106
|
+
|
107
|
+
def stop(time)
|
108
|
+
run_js("#{_js_snippet}.stop(#{time});")
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
metadata
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: Pachelbel
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '1.0'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Drew Carey Buglione
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: Process and synthesize audio in RubyMotion
|
28
|
+
email:
|
29
|
+
- me@drewb.ug
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- README.md
|
35
|
+
- lib/Pachelbel.rb
|
36
|
+
- lib/project/Pachelbel.rb
|
37
|
+
homepage: ''
|
38
|
+
licenses:
|
39
|
+
- ''
|
40
|
+
metadata: {}
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options: []
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - '>='
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
requirements: []
|
56
|
+
rubyforge_project:
|
57
|
+
rubygems_version: 2.0.6
|
58
|
+
signing_key:
|
59
|
+
specification_version: 4
|
60
|
+
summary: Pachelbel makes processing and synthesizing audio in RubyMotion a breeze.
|
61
|
+
It's built on top of the Web Audio API, which was designed to be simple, yet powerful.
|
62
|
+
test_files: []
|