xi-midi 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c0054fce720de93807aaae4f8a831e8f6630ff2d
4
+ data.tar.gz: 86b5f9503158cb98d54055315c899014055097bf
5
+ SHA512:
6
+ metadata.gz: 6c5e72413f734805515921452edbd9ddaad362a4f086b7191ccba87575858e47c092a4fb52ed09149fc5e545edd42a29afc7477e77d0751a428411bd76ae813b
7
+ data.tar.gz: 46eee9088db90c41ab27e075b924a2bd89668cf2d1fee12152505384dbda6ac4e23fc3e63224845dcb231f248066af38cf37fa5d5e8321acd00a211be537102e
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.14.3
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at munshkr@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in xi-midi.gemspec
4
+ gemspec
5
+
6
+ gem 'rawmidi', git: 'https://github.com/munshkr/rawmidi-ruby'
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Damián Silvani
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # Xi::MIDI
2
+
3
+ MIDI support for Xi
4
+
5
+ ## Installation
6
+
7
+ $ gem install xi-midi
8
+
9
+ TODO: Configure Xi to require this MIDI extension automatically
10
+
11
+ ## Usage
12
+
13
+ TODO: Write usage instructions here
14
+
15
+ ## Development
16
+
17
+ After checking out the repo, run `bundle` to install dependencies. Then, run
18
+ `rake test` to run the tests.
19
+
20
+ To install this gem onto your local machine, run `bundle exec rake install`. To
21
+ release a new version, update the version number in `version.rb`, and then run
22
+ `bundle exec rake release`, which will create a git tag for the version, push
23
+ git commits and tags, and push the `.gem` file to
24
+ [rubygems.org](https://rubygems.org).
25
+
26
+ ## Contributing
27
+
28
+ Bug reports and pull requests are welcome on GitHub at
29
+ https://github.com/xi-livecode/xi-midi. This project is intended to be a safe,
30
+ welcoming space for collaboration, and contributors are expected to adhere to
31
+ the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
32
+
33
+ ## License
34
+
35
+ The MIT License (MIT)
36
+
37
+ Copyright (c) 2017 Damián Emiliano Silvani
38
+
39
+ Permission is hereby granted, free of charge, to any person obtaining a copy
40
+ of this software and associated documentation files (the "Software"), to deal
41
+ in the Software without restriction, including without limitation the rights
42
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
43
+ copies of the Software, and to permit persons to whom the Software is
44
+ furnished to do so, subject to the following conditions:
45
+
46
+ The above copyright notice and this permission notice shall be included in all
47
+ copies or substantial portions of the Software.
48
+
49
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
50
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
51
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
52
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
53
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
54
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
55
+ SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
data/lib/xi/midi.rb ADDED
@@ -0,0 +1,8 @@
1
+ require "xi/midi/version"
2
+ require 'xi/midi/stream'
3
+
4
+ module Xi
5
+ module MIDI
6
+ # Your code goes here...
7
+ end
8
+ end
@@ -0,0 +1,85 @@
1
+ require 'singleton'
2
+ require 'thread'
3
+ require 'rawmidi'
4
+
5
+ module Xi::MIDI
6
+ class Proxy
7
+ include Singleton
8
+
9
+ MAX_CHANNELS = 16
10
+ MAX_NOTES = 128
11
+ NOTE_ON = 0x90
12
+ NOTE_OFF = 0x80
13
+ CC = 0xb0
14
+
15
+ def initialize
16
+ @mutex = Mutex.new
17
+ @outputs = RawMIDI::Output.all
18
+
19
+ # Make sure to close outputs at exit
20
+ at_exit do
21
+ begin
22
+ @outputs.each(&:close)
23
+ rescue => err
24
+ puts "Error when closing MIDI outputs: #{err}"
25
+ end
26
+ end
27
+ end
28
+
29
+ def list
30
+ RawMIDI::Output.all.map.with_index { |o, i| [i, o] }
31
+ end
32
+
33
+ def open(device)
34
+ unless @outputs[device]
35
+ fail ArgumentError, "MIDI device #{device} not found"
36
+ end
37
+ @outputs[device].open
38
+ end
39
+
40
+ def open?(device)
41
+ unless @outputs[device]
42
+ fail ArgumentError, "MIDI device #{device} not found"
43
+ end
44
+ @outputs[device].open?
45
+ end
46
+
47
+ def note_on(device, channel, note, velocity)
48
+ send_bytes(device, NOTE_ON + channel, note, velocity)
49
+ end
50
+
51
+ def note_off(device, channel, note)
52
+ send_bytes(device, NOTE_OFF + channel, note, 0)
53
+ end
54
+
55
+ def cc(device, channel, id, value)
56
+ send_bytes(device, CC + channel, id, value)
57
+ end
58
+
59
+ def reset_all
60
+ @outputs.size.times { |i| reset(i) }
61
+ end
62
+
63
+ def reset(device)
64
+ MAX_CHANNELS.times.each do |channel|
65
+ MAX_NOTES.times.each do |note|
66
+ note_off(device, channel, note)
67
+ end
68
+ end
69
+ end
70
+
71
+ private
72
+
73
+ def send_bytes(device, *bytes)
74
+ return unless open?(device)
75
+
76
+ logger.debug([:send_bytes, device, bytes].join(', '))
77
+ @mutex.synchronize { @outputs[device].write(bytes) }
78
+ end
79
+
80
+ def logger
81
+ # FIXME this should be configurable
82
+ @logger ||= Logger.new("/tmp/xi.log")
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,84 @@
1
+ require 'xi/stream'
2
+ require 'xi/midi/proxy'
3
+
4
+ module Xi::MIDI
5
+ class Stream < ::Stream
6
+ attr_accessor :device, :channel
7
+
8
+ def initialize(clock, device: 0, channel: 0)
9
+ super(clock)
10
+
11
+ @device = device
12
+ @channel = channel
13
+ @playing_notes = {}
14
+
15
+ midi.open(device)
16
+ at_exit { kill_playing_notes }
17
+ end
18
+
19
+ def set(**params)
20
+ params[:gate] = :midinote
21
+ super(params)
22
+ end
23
+
24
+ def stop
25
+ kill_playing_notes
26
+ super
27
+ end
28
+
29
+ private
30
+
31
+ def kill_playing_notes
32
+ @mutex.synchronize do
33
+ @playing_notes.each do |_, note|
34
+ midi.note_off(@device, note[:channel], note[:midinote])
35
+ end
36
+ @playing_notes.clear
37
+ end
38
+ end
39
+
40
+ def do_gate_on_change(so_ids)
41
+ channel = Array(@state[:channel] || 0)
42
+ midinote = Array(@state[:midinote] || 60)
43
+ velocity = Array(@state[:velocity] || 127)
44
+
45
+ so_ids.each.with_index do |so_id, i|
46
+ channel_i = channel[i % channel.size]
47
+ midinote_i = midinote[i % midinote.size]
48
+ velocity_i = velocity[i % velocity.size]
49
+
50
+ logger.info "MIDI Note on: #{[channel_i, midinote_i, velocity_i]}"
51
+ midi.note_on(@device, channel_i, midinote_i, velocity_i)
52
+
53
+ @playing_notes[so_id] = {channel: channel_i, midinote: midinote_i}
54
+ end
55
+ end
56
+
57
+ def do_gate_off_change(so_ids)
58
+ so_ids.each do |so_id|
59
+ note = @playing_notes.delete(so_id)
60
+ if note
61
+ logger.info "MIDI Note off: #{[note[:channel], note[:midinote]]}"
62
+ midi.note_off(@device, note[:channel], note[:midinote])
63
+ end
64
+ end
65
+ end
66
+
67
+ def do_state_change
68
+ logger.info changed_state
69
+ changed_state.each do |p, v|
70
+ cc_id = cc_parameters[p]
71
+ midi.cc(@device, channel, cc_id, v) if cc_id
72
+ end
73
+ end
74
+
75
+ # @override
76
+ def cc_parameters
77
+ {}
78
+ end
79
+
80
+ def midi
81
+ Proxy.instance
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,5 @@
1
+ module Xi
2
+ module MIDI
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,25 @@
1
+ module Xi::MIDI
2
+ module VolcaKeys
3
+ CC = {
4
+ portamento: 5,
5
+ expression: 11,
6
+ voice: 40,
7
+ detune: 42,
8
+ vco_eg_int: 43,
9
+ cutoff: 44,
10
+ vcf_eg_int: 45,
11
+ lfo_rate: 46,
12
+ lfo_pitch_int: 47,
13
+ lfo_cutoff_int: 48,
14
+ attack: 49,
15
+ decay: 50,
16
+ sustain: 51,
17
+ delay_time: 52,
18
+ delay_feedback: 53,
19
+ }
20
+
21
+ def cc_parameters
22
+ CC
23
+ end
24
+ end
25
+ end
data/xi-midi.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'xi/midi/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "xi-midi"
8
+ spec.version = Xi::MIDI::VERSION
9
+ spec.authors = ["Damián Silvani"]
10
+ spec.email = ["munshkr@gmail.com"]
11
+
12
+ spec.summary = %q{MIDI support for Xi}
13
+ spec.homepage = "https://github.com/xi-livecode/xi-midi"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "bin"
20
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.14"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "minitest", "~> 5.0"
26
+
27
+ spec.add_dependency 'rawmidi'
28
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: xi-midi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Damián Silvani
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-02-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rawmidi
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description:
70
+ email:
71
+ - munshkr@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".travis.yml"
78
+ - CODE_OF_CONDUCT.md
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - lib/xi/midi.rb
84
+ - lib/xi/midi/proxy.rb
85
+ - lib/xi/midi/stream.rb
86
+ - lib/xi/midi/version.rb
87
+ - lib/xi/midi/volca_keys.rb
88
+ - xi-midi.gemspec
89
+ homepage: https://github.com/xi-livecode/xi-midi
90
+ licenses:
91
+ - MIT
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 2.5.1
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: MIDI support for Xi
113
+ test_files: []