portmidi 0.0.6 → 1.0.0.pre.beta.1
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/CHANGELOG.md +11 -0
- data/README.rdoc +4 -33
- data/Rakefile +1 -20
- data/lib/portmidi.rb +5 -4
- data/lib/portmidi/output.rb +14 -14
- data/lib/portmidi/pm_map.rb +11 -6
- data/lib/portmidi/version.rb +2 -2
- data/lib/porttime.rb +20 -0
- metadata +42 -48
- data/.gitignore +0 -3
- data/CHANGELOG +0 -3
- data/examples/helper.rb +0 -5
- data/examples/read_test.rb +0 -47
- data/examples/write_sysex_test.rb +0 -11
- data/examples/write_test.rb +0 -14
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1e452838c2123c03f7c8f369384948fc3f3931f5
|
4
|
+
data.tar.gz: 0aab730fb12c0cf945c3a8e3a031e185ec464c44
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d73b315bcf30a77ba23746bbbe5380c2581770283115f73410d9cda7fb3deb20289997c911a63937c6c8985814b48e962ad75c8e62951b25f24e6d834288fd94
|
7
|
+
data.tar.gz: 7ef7471fe2045729288a07fd4516decfa2332ebf8aae2be0fce1351083152eade255020a5f826033f09c170ec9797741a03db8f6b96d8f48e5d803804e40321a
|
data/CHANGELOG.md
ADDED
data/README.rdoc
CHANGED
@@ -18,15 +18,9 @@ means I will mock away the portmidi layer to test my abstractions and add some o
|
|
18
18
|
Implementation wise, there's a few things missing:
|
19
19
|
|
20
20
|
* Setting Channel- and Message filters
|
21
|
-
* Porttime support(not sure I can support that, I guess it needs multithreading, plus: I did not need it until now)
|
22
|
-
examples/read_test.rb on how to decipher sysex atm.
|
23
21
|
* More different exceptions, plus support for Host Errors
|
24
22
|
* A lot of safety nets like testing for open devices before reading and writing and such.
|
25
23
|
|
26
|
-
== What's coming
|
27
|
-
|
28
|
-
* I'd love to see some explicit support for correctly parsing SysEx, see
|
29
|
-
|
30
24
|
== Credits
|
31
25
|
|
32
26
|
The portmidi wrapper was thrown together by Jan Krutisch <jan@krutisch.de>
|
@@ -36,31 +30,8 @@ The portmidi wrapper was thrown together by Jan Krutisch <jan@krutisch.de>
|
|
36
30
|
* Patches by
|
37
31
|
* Thomas Jachmann (http://github.com/thomasjachmann)
|
38
32
|
|
39
|
-
==
|
40
|
-
|
41
|
-
This is a major pita, because currently portmidi doesn't officially build for 64 bit, which
|
42
|
-
makes it impossible to use with the default Snow Leopard Ruby.
|
43
|
-
|
44
|
-
You can try to enable 64 bit support, but I don't have a frekkin clue what this means. It works
|
45
|
-
for me and my application, but YMMV and I am not responsible for any damage this does
|
46
|
-
to you or your system.
|
47
|
-
|
48
|
-
To enable 64 bit compilation (you will see quite a few warnings while compiling), open
|
49
|
-
CMakeLists.txt in the trunk folder and find the following line (around line 39 in my version)
|
50
|
-
|
51
|
-
set(CMAKE_OSX_ARCHITECTURES i386 ppc CACHE STRING "do not build for 64-bit" FORCE)
|
52
|
-
|
53
|
-
and change it to: (yes, the comment is a bit silly)
|
54
|
-
|
55
|
-
set(CMAKE_OSX_ARCHITECTURES i386 ppc x86_64 CACHE STRING "do build for 64-bit" FORCE)
|
56
|
-
|
57
|
-
Now you can call
|
58
|
-
|
59
|
-
make -f pm_mac/Makefile.osx
|
60
|
-
|
61
|
-
if it builds, you can try to install the library. Currently the process seems to be a bit broken,
|
62
|
-
so you actually need to type:
|
63
|
-
|
64
|
-
sudo env PF=/usr make -f pm_mac/Makefile.osx install
|
33
|
+
== Installing Portmidi
|
65
34
|
|
66
|
-
|
35
|
+
* On MacOSX, there's a homebrew recipe, so $ brew install portmidi should do the trick
|
36
|
+
* On most Linuxes, portmidi should be simply a package to install by your packagemanager
|
37
|
+
* On Windows: "try this":http://sourceforge.net/apps/trac/portmedia/wiki/Installing%20portmidi%20on%20Windows
|
data/Rakefile
CHANGED
@@ -2,25 +2,6 @@ require 'rubygems'
|
|
2
2
|
require 'rake'
|
3
3
|
require File.join(File.dirname(__FILE__), "lib/portmidi/version")
|
4
4
|
|
5
|
-
begin
|
6
|
-
require 'jeweler'
|
7
|
-
|
8
|
-
Jeweler::Tasks.new do |gemspec|
|
9
|
-
gemspec.name = "portmidi"
|
10
|
-
gemspec.summary = "An ffi wrapper around the cross platform midi library portmidi"
|
11
|
-
gemspec.description = "An ffi wrapper around the cross platform midi library portmidi, part of the portmedia framework"
|
12
|
-
gemspec.email = "jan@krutisch.de"
|
13
|
-
gemspec.homepage = "http://github.com/halfbyte/portmidi"
|
14
|
-
gemspec.authors = ["Jan Krutisch"]
|
15
|
-
gemspec.version = Portmidi::VERSION
|
16
|
-
gemspec.requirements << "Needs portmidi compiled as a dynamic library"
|
17
|
-
gemspec.requirements << "On MRI, this needs the ffi gem installed"
|
18
|
-
end
|
19
|
-
Jeweler::GemcutterTasks.new
|
20
|
-
rescue LoadError
|
21
|
-
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
22
|
-
end
|
23
|
-
|
24
5
|
require 'rake/rdoctask'
|
25
6
|
Rake::RDocTask.new do |rdoc|
|
26
7
|
version = Portmidi::VERSION
|
@@ -29,4 +10,4 @@ Rake::RDocTask.new do |rdoc|
|
|
29
10
|
rdoc.title = "Portmidi #{version}"
|
30
11
|
rdoc.rdoc_files.include('README*')
|
31
12
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
32
|
-
end
|
13
|
+
end
|
data/lib/portmidi.rb
CHANGED
@@ -4,9 +4,10 @@ require 'portmidi/device'
|
|
4
4
|
require 'portmidi/input'
|
5
5
|
require 'portmidi/output'
|
6
6
|
require 'portmidi/exceptions'
|
7
|
+
require 'porttime'
|
7
8
|
|
8
9
|
module Portmidi
|
9
|
-
|
10
|
+
|
10
11
|
def self.devices(rescan = false)
|
11
12
|
@@devices = []
|
12
13
|
PM_Map.Pm_CountDevices.times do |i|
|
@@ -15,17 +16,17 @@ module Portmidi
|
|
15
16
|
end
|
16
17
|
@@devices
|
17
18
|
end
|
18
|
-
|
19
|
+
|
19
20
|
def self.input_devices
|
20
21
|
self.devices.select{|device| device.type == :input }
|
21
22
|
end
|
22
23
|
def self.output_devices
|
23
24
|
self.devices.select{|device| device.type == :output }
|
24
25
|
end
|
25
|
-
|
26
|
+
|
26
27
|
# this is not a very good name, but Portmidi::initialize woulda been a worse idea
|
27
28
|
def self.start
|
28
29
|
PM_Map.Pm_Initialize
|
29
30
|
end
|
30
|
-
|
31
|
+
|
31
32
|
end
|
data/lib/portmidi/output.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Portmidi
|
2
2
|
class Output
|
3
|
-
|
3
|
+
|
4
4
|
#
|
5
5
|
# open a device with the given ID
|
6
6
|
#
|
@@ -12,19 +12,19 @@ module Portmidi
|
|
12
12
|
raise Portmidi::DeviceError, errnum, "Could not open Device #{device_id} as output device"
|
13
13
|
end
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
def close
|
17
17
|
PM_Map.Pm_Close(@out_stream)
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
#
|
21
21
|
# write a single three byte message
|
22
22
|
#
|
23
|
-
|
24
|
-
def write_short(status, data1, data2)
|
25
|
-
PM_Map.Pm_WriteShort(@out_stream,
|
23
|
+
|
24
|
+
def write_short(status, data1, data2, timestamp = 0)
|
25
|
+
PM_Map.Pm_WriteShort(@out_stream, timestamp, PM_Map.encode_message(status, data1, data2))
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
def write(messages)
|
29
29
|
buffer = FFI::MemoryPointer.new(PM_Map::Event, messages.length)
|
30
30
|
messages.length.times do |i|
|
@@ -34,12 +34,12 @@ module Portmidi
|
|
34
34
|
end
|
35
35
|
PM_Map.Pm_Write(@out_stream, buffer, messages.length)
|
36
36
|
end
|
37
|
-
|
38
|
-
|
39
37
|
|
40
|
-
|
38
|
+
|
39
|
+
|
40
|
+
#
|
41
41
|
# sends the sysex, the message should be an array of byte values
|
42
|
-
#
|
42
|
+
#
|
43
43
|
def write_sysex(sysex)
|
44
44
|
raise "Invalid Sysex Format" if (sysex.first != 0xF0 || sysex.last != 0xF7)
|
45
45
|
msg = FFI::Buffer.alloc_in(:uchar, sysex.length)
|
@@ -48,11 +48,11 @@ module Portmidi
|
|
48
48
|
end
|
49
49
|
PM_Map.Pm_WriteSysEx(@out_stream, 0, msg)
|
50
50
|
end
|
51
|
-
|
51
|
+
|
52
52
|
private
|
53
53
|
def packEvent(message)
|
54
54
|
((((message[3] || 0) << 24) & 0xFF000000) | (((message[2] || 0) << 16) & 0xFF0000) | (((message[1] || 0) << 8) & 0xFF00) | ((message[0]) & 0xFF))
|
55
55
|
end
|
56
|
-
|
56
|
+
|
57
57
|
end
|
58
|
-
end
|
58
|
+
end
|
data/lib/portmidi/pm_map.rb
CHANGED
@@ -7,7 +7,7 @@ module Portmidi
|
|
7
7
|
attach_function :Pm_CountDevices, [], :int
|
8
8
|
attach_function :Pm_Initialize, [], :void
|
9
9
|
attach_function :Pm_GetDeviceInfo,[:int], :pointer
|
10
|
-
|
10
|
+
|
11
11
|
attach_function :Pm_OpenInput, [:pointer, :int, :pointer, :int, :pointer, :pointer], :int
|
12
12
|
attach_function :Pm_OpenOutput, [:pointer, :int, :pointer, :int, :pointer, :pointer, :int32], :int
|
13
13
|
attach_function :Pm_Poll, [:pointer], :int
|
@@ -18,9 +18,14 @@ module Portmidi
|
|
18
18
|
attach_function :Pm_Close, [:pointer], :int
|
19
19
|
|
20
20
|
attach_function :Pm_GetErrorText, [:int], :string
|
21
|
-
|
21
|
+
|
22
|
+
callback :timer_function, [:int32, :pointer], :void
|
23
|
+
attach_function :Pt_Start, [:int, :timer_function, :pointer], :int
|
24
|
+
attach_function :Pt_Time, [], :int32
|
25
|
+
|
26
|
+
|
22
27
|
#attach_function :Pt_Start, [:int, :pointer, :pointer], :int
|
23
|
-
|
28
|
+
|
24
29
|
class DeviceInfo < FFI::Struct
|
25
30
|
layout :struct_version, :int,
|
26
31
|
:midi_api, :string,
|
@@ -29,14 +34,14 @@ module Portmidi
|
|
29
34
|
:output, :int,
|
30
35
|
:opened, :int
|
31
36
|
end
|
32
|
-
|
37
|
+
|
33
38
|
class Event < FFI::Struct
|
34
39
|
layout :message, :int32,
|
35
40
|
:timestamp, :int32
|
36
41
|
end
|
37
|
-
|
42
|
+
|
38
43
|
def self.encode_message(status, data1, data2)
|
39
44
|
((((data2) << 16) & 0xFF0000) | (((data1) << 8) & 0xFF00) | ((status) & 0xFF))
|
40
|
-
end
|
45
|
+
end
|
41
46
|
end
|
42
47
|
end
|
data/lib/portmidi/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
module Portmidi
|
2
|
-
VERSION = "0.0.
|
3
|
-
end
|
2
|
+
VERSION = "1.0.0-beta.1"
|
3
|
+
end
|
data/lib/porttime.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
module Porttime
|
2
|
+
TimerCallback = FFI::Function.new(:void, [:int32, :pointer]) do |timestamp, user_data|
|
3
|
+
@timer_callback.call(timestamp, user_data)
|
4
|
+
end
|
5
|
+
|
6
|
+
# Start the Porttime timer system
|
7
|
+
# * interval is in milliseconds
|
8
|
+
# * You can add arbitrary user data that will be given to the callback
|
9
|
+
# * the callback block will be called each interval seconds.
|
10
|
+
def self.start(interval=20, user_data=nil, &block)
|
11
|
+
@timer_callback = block
|
12
|
+
Portmidi::PM_Map.Pt_Start(interval, Porttime::TimerCallback, user_data)
|
13
|
+
end
|
14
|
+
|
15
|
+
# Get the current time
|
16
|
+
# * you can use that to figure out how to properly schedule events into the future
|
17
|
+
def self.time
|
18
|
+
Portmidi::PM_Map.Pt_Time
|
19
|
+
end
|
20
|
+
end
|
metadata
CHANGED
@@ -1,35 +1,39 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: portmidi
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0.pre.beta.1
|
5
5
|
platform: ruby
|
6
|
-
authors:
|
6
|
+
authors:
|
7
7
|
- Jan Krutisch
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
11
|
+
date: 2018-01-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: ffi
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.9'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.9'
|
27
|
+
description: An ffi wrapper around the cross platform midi library portmidi, part
|
28
|
+
of the portmedia framework
|
17
29
|
email: jan@krutisch.de
|
18
30
|
executables: []
|
19
|
-
|
20
31
|
extensions: []
|
21
|
-
|
22
|
-
|
23
|
-
-
|
24
|
-
files:
|
25
|
-
- .gitignore
|
26
|
-
- CHANGELOG
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- CHANGELOG.md
|
27
35
|
- README.rdoc
|
28
36
|
- Rakefile
|
29
|
-
- examples/helper.rb
|
30
|
-
- examples/read_test.rb
|
31
|
-
- examples/write_sysex_test.rb
|
32
|
-
- examples/write_test.rb
|
33
37
|
- lib/portmidi.rb
|
34
38
|
- lib/portmidi/device.rb
|
35
39
|
- lib/portmidi/exceptions.rb
|
@@ -37,42 +41,32 @@ files:
|
|
37
41
|
- lib/portmidi/output.rb
|
38
42
|
- lib/portmidi/pm_map.rb
|
39
43
|
- lib/portmidi/version.rb
|
44
|
+
- lib/porttime.rb
|
40
45
|
- license.txt
|
41
46
|
- test/helper.rb
|
42
47
|
- test/test_portmidi.rb
|
43
|
-
has_rdoc: true
|
44
48
|
homepage: http://github.com/halfbyte/portmidi
|
45
49
|
licenses: []
|
46
|
-
|
50
|
+
metadata: {}
|
47
51
|
post_install_message:
|
48
|
-
rdoc_options:
|
49
|
-
|
50
|
-
require_paths:
|
52
|
+
rdoc_options: []
|
53
|
+
require_paths:
|
51
54
|
- lib
|
52
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
-
requirements:
|
54
|
-
- - ">="
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
version: "0"
|
57
|
-
version:
|
58
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
-
requirements:
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
60
57
|
- - ">="
|
61
|
-
- !ruby/object:Gem::Version
|
62
|
-
version:
|
63
|
-
|
64
|
-
requirements:
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: 2.0.0
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">"
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: 1.3.1
|
65
|
+
requirements:
|
65
66
|
- Needs portmidi compiled as a dynamic library
|
66
|
-
- On MRI, this needs the ffi gem installed
|
67
67
|
rubyforge_project:
|
68
|
-
rubygems_version:
|
68
|
+
rubygems_version: 2.5.1
|
69
69
|
signing_key:
|
70
|
-
specification_version:
|
70
|
+
specification_version: 4
|
71
71
|
summary: An ffi wrapper around the cross platform midi library portmidi
|
72
|
-
test_files:
|
73
|
-
- test/helper.rb
|
74
|
-
- test/test_portmidi.rb
|
75
|
-
- examples/helper.rb
|
76
|
-
- examples/read_test.rb
|
77
|
-
- examples/write_sysex_test.rb
|
78
|
-
- examples/write_test.rb
|
72
|
+
test_files: []
|
data/.gitignore
DELETED
data/CHANGELOG
DELETED
data/examples/helper.rb
DELETED
data/examples/read_test.rb
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
Portmidi.input_devices.each do |dev|
|
3
|
-
puts "%d > %s" % [dev.device_id, dev.name]
|
4
|
-
end
|
5
|
-
puts "choose device id"
|
6
|
-
device_id = gets()
|
7
|
-
|
8
|
-
input = Portmidi::Input.new(device_id.to_i)
|
9
|
-
cnt = 0
|
10
|
-
data = []
|
11
|
-
running_sysex = []
|
12
|
-
sysex_is_on = false
|
13
|
-
loop do
|
14
|
-
begin
|
15
|
-
events = input.read(16)
|
16
|
-
if events
|
17
|
-
events.each do |event|
|
18
|
-
|
19
|
-
|
20
|
-
if event[:message][0] == 0xF0
|
21
|
-
running_sysex = event[:message]
|
22
|
-
sysex_is_on = true
|
23
|
-
elsif sysex_is_on
|
24
|
-
if event[:message][0] < 0x80
|
25
|
-
running_sysex += event[:message]
|
26
|
-
if event[:message].include?(0xF7)
|
27
|
-
data << running_sysex.flatten
|
28
|
-
puts running_sysex.inspect
|
29
|
-
sysex_is_on = false
|
30
|
-
end
|
31
|
-
else
|
32
|
-
puts event[:message].inspect
|
33
|
-
sysex_is_on = false
|
34
|
-
puts "cancelled sysex"
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
# data << events
|
39
|
-
else
|
40
|
-
# puts "poll" if cnt % 10000 == 0
|
41
|
-
end
|
42
|
-
rescue Portmidi::DeviceError => e
|
43
|
-
puts e.portmidi_error
|
44
|
-
end
|
45
|
-
cnt += 1
|
46
|
-
#sleep 0.002
|
47
|
-
end
|
@@ -1,11 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
sysex = [0xF0, 00, 12, 0x12, 0xF7]
|
3
|
-
|
4
|
-
Portmidi.output_devices.each do |dev|
|
5
|
-
puts "%d > %s" % [dev.device_id, dev.name]
|
6
|
-
end
|
7
|
-
puts "choose device id"
|
8
|
-
device_id = gets()
|
9
|
-
|
10
|
-
output = Portmidi::Output.new(device_id.to_i)
|
11
|
-
output.write_sysex(sysex)
|
data/examples/write_test.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
messages = [
|
3
|
-
{:message => [0x90, 0x33, 0x7F], :timestamp => 0},
|
4
|
-
{:message => [0x90, 0x33, 0x00], :timestamp => 0}
|
5
|
-
]
|
6
|
-
|
7
|
-
Portmidi.output_devices.each do |dev|
|
8
|
-
puts "%d > %s" % [dev.device_id, dev.name]
|
9
|
-
end
|
10
|
-
puts "choose device id"
|
11
|
-
device_id = gets()
|
12
|
-
|
13
|
-
output = Portmidi::Output.new(device_id.to_i)
|
14
|
-
output.write(messages)
|