unimidi 0.4.8 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: bf68a7b6957f53fe2ccdb7922af43d3ee59bcc8e
4
- data.tar.gz: ad6dc382083631d6f8277e319d39af5e5bc27cad
2
+ SHA256:
3
+ metadata.gz: 8a01014709788ce8d62b5331aa871210c5b52caf3172fa88abf737ea0ab1da6e
4
+ data.tar.gz: 2afe488142025675ce6fcf6413183a4b354b091215199bccecb46fa92b3c0400
5
5
  SHA512:
6
- metadata.gz: 8386b3217cae71e3712d12644c2371b6fd9b6bbcf11fb3b1537a38773a4fc077da771ef3713e417bca1248d6a4f1f6ab605dbd505a5aa0a686377b60b8605b88
7
- data.tar.gz: 630f39aa818ad71e336dca7597e14a8c5b9bdf1237e9d8839aede3e50f504b763aa60f1a7512426903163f3e270f43d785c246f1bff0950adf84d2f2508868c4
6
+ metadata.gz: cb09c7b5e9ba139f3e4161c2881af05ae6e0536857001118d41e47b611322e093a562995bd3840cc82790d1a84ad8317533948b7f6d098460a7eb1922ecda532
7
+ data.tar.gz: 954b97c19189b650ab55643d99989d4b88603938f762cf0289f6360672c6174e753202086ad24acd3cdf955db4191fcdda0f256eb1cb18c180389de204e55095
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2010-2017 Ari Russo
1
+ Copyright 2010-2022 Ari Russo
2
2
 
3
3
  Licensed under the Apache License, Version 2.0 (the "License");
4
4
  you may not use this file except in compliance with the License.
data/README.md CHANGED
@@ -84,4 +84,4 @@ See below for additional notes on testing with JRuby
84
84
 
85
85
  Apache 2.0, See the file LICENSE
86
86
 
87
- Copyright (c) 2010-2017 Ari Russo
87
+ Copyright (c) 2010-2022 Ari Russo
@@ -1,15 +1,13 @@
1
- require "alsa-rawmidi"
1
+ # frozen_string_literal: true
2
2
 
3
- module UniMIDI
3
+ require 'alsa-rawmidi'
4
4
 
5
+ module UniMIDI
5
6
  module Adapter
6
-
7
7
  # Load underlying devices using the alsa-rawmidi gem
8
8
  module AlsaRawMIDI
9
-
10
9
  module Loader
11
-
12
- extend self
10
+ module_function
13
11
 
14
12
  # @return [Array<AlsaRawMIDI::Input>]
15
13
  def inputs
@@ -20,11 +18,7 @@ module UniMIDI
20
18
  def outputs
21
19
  ::AlsaRawMIDI::Device.all_by_type[:output]
22
20
  end
23
-
24
21
  end
25
-
26
22
  end
27
-
28
23
  end
29
-
30
24
  end
@@ -1,15 +1,13 @@
1
- require "coremidi"
1
+ # frozen_string_literal: true
2
2
 
3
- module UniMIDI
3
+ require 'coremidi'
4
4
 
5
+ module UniMIDI
5
6
  module Adapter
6
-
7
7
  # Load underlying devices using the coremidi gem
8
8
  module CoreMIDI
9
-
10
9
  module Loader
11
-
12
- extend self
10
+ module_function
13
11
 
14
12
  # @return [Array<CoreMIDI::Source>]
15
13
  def inputs
@@ -20,11 +18,7 @@ module UniMIDI
20
18
  def outputs
21
19
  ::CoreMIDI::Endpoint.all_by_type[:destination]
22
20
  end
23
-
24
21
  end
25
-
26
22
  end
27
-
28
23
  end
29
-
30
24
  end
@@ -1,15 +1,13 @@
1
- require "midi-jruby"
1
+ # frozen_string_literal: true
2
2
 
3
- module UniMIDI
3
+ require 'midi-jruby'
4
4
 
5
+ module UniMIDI
5
6
  module Adapter
6
-
7
7
  # Load underlying devices using the midi-jruby gem
8
8
  module MIDIJRuby
9
-
10
9
  module Loader
11
-
12
- extend self
10
+ module_function
13
11
 
14
12
  # @return [Array<MIDIJRuby::Input>]
15
13
  def inputs
@@ -20,11 +18,7 @@ module UniMIDI
20
18
  def outputs
21
19
  ::MIDIJRuby::Device.all_by_type[:output]
22
20
  end
23
-
24
21
  end
25
-
26
22
  end
27
-
28
23
  end
29
-
30
24
  end
@@ -1,15 +1,13 @@
1
- require "midi-winmm"
1
+ # frozen_string_literal: true
2
2
 
3
- module UniMIDI
3
+ require 'midi-winmm'
4
4
 
5
+ module UniMIDI
5
6
  module Adapter
6
-
7
7
  # Load underlying devices using the midi-winmm gem
8
8
  module MIDIWinMM
9
-
10
9
  module Loader
11
-
12
- extend self
10
+ module_function
13
11
 
14
12
  # @return [Array<MIDIWinMM::Input>]
15
13
  def inputs
@@ -20,11 +18,7 @@ module UniMIDI
20
18
  def outputs
21
19
  ::MIDIWinMM::Device.all_by_type[:output]
22
20
  end
23
-
24
21
  end
25
-
26
22
  end
27
-
28
23
  end
29
-
30
24
  end
@@ -1,26 +1,24 @@
1
- module UniMIDI
1
+ # frozen_string_literal: true
2
2
 
3
+ module UniMIDI
3
4
  # Module for command-line use of UniMIDI. Used by the bin/unimidi script
4
5
  module Command
5
-
6
- extend self
6
+ module_function
7
7
 
8
8
  # Execute a command
9
9
  # @param [Symbol] command
10
10
  # @param [Hash] options
11
11
  # @return [Boolean]
12
- def exec(command, options = {})
13
- if [:l, :list, :list_devices].include?(command)
14
- puts "input:"
12
+ def exec(command, _options = {})
13
+ if %i[l list list_devices].include?(command)
14
+ puts 'input:'
15
15
  Input.list
16
- puts "output:"
16
+ puts 'output:'
17
17
  Output.list
18
18
  true
19
19
  else
20
- raise "Command #{command.to_s} not found"
21
- end
20
+ raise "Command #{command} not found"
21
+ end
22
22
  end
23
-
24
23
  end
25
-
26
24
  end
@@ -1,16 +1,15 @@
1
- module UniMIDI
1
+ # frozen_string_literal: true
2
2
 
3
+ module UniMIDI
3
4
  # Common logic that is shared by both Input and Output devices
4
5
  module Device
5
-
6
6
  # Methods that are shared by both Input and Output classes
7
7
  module ClassMethods
8
-
9
8
  include Enumerable
10
9
 
11
10
  # Iterate over all devices of this direction (eg Input, Output)
12
11
  def each(&block)
13
- all.each { |device| yield(device) }
12
+ all.each(&block)
14
13
  end
15
14
 
16
15
  # Prints ids and names of each device to the console
@@ -35,16 +34,20 @@ module UniMIDI
35
34
  def gets(&block)
36
35
  device = nil
37
36
  direction = get_direction
38
- puts ""
37
+ puts ''
39
38
  puts "Select a MIDI #{direction}..."
40
39
  while device.nil?
41
40
  list
42
- print "> "
41
+ print '> '
43
42
  selection = $stdin.gets.chomp
44
- if selection != ""
45
- selection = Integer(selection) rescue nil
46
- device = all.find { |d| d.id == selection } unless selection.nil?
43
+ next unless selection != ''
44
+
45
+ selection = begin
46
+ Integer(selection)
47
+ rescue StandardError
48
+ nil
47
49
  end
50
+ device = all.find { |d| d.id == selection } unless selection.nil?
48
51
  end
49
52
  device.open(&block)
50
53
  device
@@ -73,7 +76,7 @@ module UniMIDI
73
76
  end
74
77
  use_device(at(index), &block)
75
78
  end
76
- alias_method :open, :use
79
+ alias open use
77
80
 
78
81
  # Select the device at the given index
79
82
  # @param [Integer] index
@@ -81,14 +84,14 @@ module UniMIDI
81
84
  def at(index)
82
85
  all[index]
83
86
  end
84
- alias_method :[], :at
87
+ alias [] at
85
88
 
86
89
  private
87
90
 
88
91
  # The direction of the device eg "input", "output"
89
92
  # @return [String]
90
93
  def get_direction
91
- name.split("::").last.downcase
94
+ name.split('::').last.downcase
92
95
  end
93
96
 
94
97
  # Enable the given device
@@ -102,12 +105,10 @@ module UniMIDI
102
105
  end
103
106
  device
104
107
  end
105
-
106
108
  end
107
109
 
108
110
  # Methods that are shared by both Input and Output instances
109
111
  module InstanceMethods
110
-
111
112
  # @param [AlsaRawMIDI::Input, AlsaRawMIDI::Output, CoreMIDI::Destination, CoreMIDI::Source, MIDIJRuby::Input, MIDIJRuby::Output, MIDIWinMM::Input, MIDIWinMM::Output] device
112
113
  def initialize(device)
113
114
  @device = device
@@ -121,7 +122,7 @@ module UniMIDI
121
122
  # Can be passed a block to which the device will be passed in as the yieldparam
122
123
  # @param [*Object] args
123
124
  # @return [Input, Output] self
124
- def open(*args, &block)
125
+ def open(*args)
125
126
  unless @enabled
126
127
  @device.open(*args)
127
128
  @enabled = true
@@ -182,9 +183,9 @@ module UniMIDI
182
183
  # Populate the direction attribute
183
184
  def populate_direction
184
185
  @direction = case @device.type
185
- when :source, :input then :input
186
- when :destination, :output then :output
187
- end
186
+ when :source, :input then :input
187
+ when :destination, :output then :output
188
+ end
188
189
  end
189
190
 
190
191
  # Populate attributes from the underlying device object
@@ -193,9 +194,6 @@ module UniMIDI
193
194
  @name = @device.name
194
195
  populate_direction
195
196
  end
196
-
197
197
  end
198
-
199
198
  end
200
-
201
199
  end
@@ -1,9 +1,8 @@
1
- module UniMIDI
1
+ # frozen_string_literal: true
2
2
 
3
+ module UniMIDI
3
4
  class Input
4
-
5
5
  module BufferAccess
6
-
7
6
  # The device buffer
8
7
  # @return [Array<Hash>]
9
8
  def buffer
@@ -20,7 +19,7 @@ module UniMIDI
20
19
  # the messages from the buffer or have any effect on the StreamReader pointer position
21
20
  # @param [*Object] args
22
21
  # @return [Array<Hash>]
23
- def gets_buffer(*args)
22
+ def gets_buffer(*_args)
24
23
  @device.buffer
25
24
  end
26
25
 
@@ -28,20 +27,20 @@ module UniMIDI
28
27
  # the messages from the buffer or have any effect on the StreamReader pointer position
29
28
  # @param [*Object] args
30
29
  # @return [Array<Hash>]
31
- def gets_buffer_s(*args)
32
- @device.buffer.map { |msg| msg[:data] = TypeConversion.numeric_byte_array_to_hex_string(msg[:data]); msg }
30
+ def gets_buffer_s(*_args)
31
+ @device.buffer.map do |msg|
32
+ msg[:data] = TypeConversion.numeric_byte_array_to_hex_string(msg[:data])
33
+ msg
34
+ end
33
35
  end
34
36
 
35
37
  # Gets any messages in the buffer in the same format as Input#gets_data. . This doesn't remove
36
38
  # the messages from the buffer or have any effect on the StreamReader pointer position
37
39
  # @param [*Object] args
38
40
  # @return [Array<Integer>]
39
- def gets_buffer_data(*args)
41
+ def gets_buffer_data(*_args)
40
42
  @device.buffer.map { |msg| msg[:data] }
41
43
  end
42
-
43
44
  end
44
-
45
45
  end
46
-
47
46
  end
@@ -1,9 +1,8 @@
1
- module UniMIDI
1
+ # frozen_string_literal: true
2
2
 
3
+ module UniMIDI
3
4
  class Input
4
-
5
5
  module StreamReader
6
-
7
6
  # Returns any data in the input buffer that have been received since the last call to a
8
7
  # StreamReader method. If a StreamReader method has not yet been called, all data received
9
8
  # since the program was initialized will be returned
@@ -45,8 +44,8 @@ module UniMIDI
45
44
  rescue SystemExit, Interrupt
46
45
  exit
47
46
  end
48
- alias_method :gets_bytestr, :gets_s
49
- alias_method :gets_hex, :gets_s
47
+ alias gets_bytestr gets_s
48
+ alias gets_hex gets_s
50
49
 
51
50
  # Returns any data in the input buffer that have been received since the last call to a
52
51
  # StreamReader method. If a StreamReader method has not yet been called, all data received
@@ -75,11 +74,8 @@ module UniMIDI
75
74
  arr = gets_bytestr(*args)
76
75
  arr.map { |msg| msg[:data] }.join
77
76
  end
78
- alias_method :gets_data_bytestr, :gets_data_s
79
- alias_method :gets_data_hex, :gets_data_s
80
-
77
+ alias gets_data_bytestr gets_data_s
78
+ alias gets_data_hex gets_data_s
81
79
  end
82
-
83
80
  end
84
-
85
81
  end
data/lib/unimidi/input.rb CHANGED
@@ -1,11 +1,11 @@
1
- require "unimidi/input/buffer_access"
2
- require "unimidi/input/stream_reader"
1
+ # frozen_string_literal: true
3
2
 
4
- module UniMIDI
3
+ require 'unimidi/input/buffer_access'
4
+ require 'unimidi/input/stream_reader'
5
5
 
6
+ module UniMIDI
6
7
  # A MIDI input device
7
8
  class Input
8
-
9
9
  extend Device::ClassMethods
10
10
  include BufferAccess
11
11
  include Device::InstanceMethods
@@ -14,9 +14,7 @@ module UniMIDI
14
14
  # All MIDI input devices -- used to populate the class
15
15
  # @return [Array<Input>]
16
16
  def self.all
17
- Loader.devices(:direction => :input)
17
+ Loader.devices(direction: :input)
18
18
  end
19
-
20
19
  end
21
-
22
20
  end
@@ -1,10 +1,9 @@
1
- module UniMIDI
1
+ # frozen_string_literal: true
2
2
 
3
+ module UniMIDI
3
4
  # Populate UniMIDI devices using the underlying device objects from the platform-specific gems
4
5
  class Loader
5
-
6
6
  class << self
7
-
8
7
  # Use the given platform-specific adapter to load devices
9
8
  # @param [UniMIDI::Adapter::Loader] loader
10
9
  def use(loader)
@@ -20,14 +19,12 @@ module UniMIDI
20
19
  inputs = @loader.inputs.map { |device| ::UniMIDI::Input.new(device) }
21
20
  outputs = @loader.outputs.map { |device| ::UniMIDI::Output.new(device) }
22
21
  @devices = {
23
- :input => inputs,
24
- :output => outputs
22
+ input: inputs,
23
+ output: outputs
25
24
  }
26
25
  end
27
26
  options[:direction].nil? ? @devices.values.flatten : @devices[options[:direction]]
28
27
  end
29
-
30
28
  end
31
-
32
29
  end
33
30
  end
@@ -1,15 +1,15 @@
1
- module UniMIDI
1
+ # frozen_string_literal: true
2
2
 
3
+ module UniMIDI
3
4
  # A MIDI output device
4
5
  class Output
5
-
6
6
  extend Device::ClassMethods
7
7
  include Device::InstanceMethods
8
8
 
9
9
  # All MIDI output devices -- used to populate the class
10
10
  # @return [Array<Output>]
11
11
  def self.all
12
- Loader.devices(:direction => :output)
12
+ Loader.devices(direction: :output)
13
13
  end
14
14
 
15
15
  # Sends a message to the output.
@@ -46,8 +46,8 @@ module UniMIDI
46
46
  @device.puts_s(*messages)
47
47
  messages.count < 2 ? messages[0] : messages
48
48
  end
49
- alias_method :puts_bytestr, :puts_s
50
- alias_method :puts_hex, :puts_s
49
+ alias puts_bytestr puts_s
50
+ alias puts_hex puts_s
51
51
 
52
52
  # Sends a message to the output in a form of bytes eg output.puts_bytes(0x90, 0x40, 0x40).
53
53
  # This method does not do type checking.
@@ -57,7 +57,5 @@ module UniMIDI
57
57
  @device.puts_bytes(*messages)
58
58
  messages.count < 2 ? messages[0] : messages
59
59
  end
60
-
61
60
  end
62
-
63
61
  end
@@ -1,8 +1,8 @@
1
- module UniMIDI
1
+ # frozen_string_literal: true
2
2
 
3
+ module UniMIDI
3
4
  # Deal with different dependencies between different user environments
4
5
  module Platform
5
-
6
6
  extend self
7
7
 
8
8
  # Loads the proper MIDI library and adapter for the user's environment
@@ -15,22 +15,20 @@ module UniMIDI
15
15
 
16
16
  def platform_lib
17
17
  case RUBY_PLATFORM
18
- when /darwin/ then "ffi-coremidi"
19
- when /java/ then "midi-jruby"
20
- when /linux/ then "alsa-rawmidi"
21
- when /mingw/ then "midi-winmm"
18
+ when /darwin/ then 'ffi-coremidi'
19
+ when /java/ then 'midi-jruby'
20
+ when /linux/ then 'alsa-rawmidi'
21
+ when /mingw/ then 'midi-winmm'
22
22
  end
23
23
  end
24
24
 
25
25
  def platform_module
26
26
  case RUBY_PLATFORM
27
- when /darwin/ then Adapter::CoreMIDI
28
- when /java/ then Adapter::MIDIJRuby
29
- when /linux/ then Adapter::AlsaRawMIDI
30
- when /mingw/ then Adapter::MIDIWinMM
27
+ when /darwin/ then Adapter::CoreMIDI
28
+ when /java/ then Adapter::MIDIJRuby
29
+ when /linux/ then Adapter::AlsaRawMIDI
30
+ when /mingw/ then Adapter::MIDIWinMM
31
31
  end
32
32
  end
33
-
34
33
  end
35
-
36
34
  end
@@ -1,9 +1,9 @@
1
- module UniMIDI
1
+ # frozen_string_literal: true
2
2
 
3
+ module UniMIDI
3
4
  # Utility for converting between different data formats
4
5
  module TypeConversion
5
-
6
- extend self
6
+ module_function
7
7
 
8
8
  # Convert an array of numeric bytes to string of hex bytes
9
9
  # @param [Array<Integer>] byte An array of numeric bytes eg [0x90, 0x40, 0x40]
@@ -11,7 +11,5 @@ module UniMIDI
11
11
  def numeric_byte_array_to_hex_string(bytes)
12
12
  bytes.map { |b| b.to_s(16) }.join
13
13
  end
14
-
15
14
  end
16
-
17
15
  end
data/lib/unimidi.rb CHANGED
@@ -1,26 +1,26 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #
2
4
  # UniMIDI
3
5
  # Realtime MIDI IO for Ruby
4
6
  #
5
- # (c)2010-2017 Ari Russo
7
+ # (c)2010-2022 Ari Russo
6
8
  # Licensed under the Apache 2.0 License
7
9
  #
8
10
 
9
11
  # modules
10
- require "unimidi/command"
11
- require "unimidi/device"
12
- require "unimidi/platform"
13
- require "unimidi/type_conversion"
12
+ require 'unimidi/command'
13
+ require 'unimidi/device'
14
+ require 'unimidi/platform'
15
+ require 'unimidi/type_conversion'
14
16
 
15
17
  # classes
16
- require "unimidi/input"
17
- require "unimidi/loader"
18
- require "unimidi/output"
18
+ require 'unimidi/input'
19
+ require 'unimidi/loader'
20
+ require 'unimidi/output'
19
21
 
20
22
  module UniMIDI
21
-
22
- VERSION = "0.4.8"
23
+ VERSION = '0.5.0'
23
24
 
24
25
  Platform.bootstrap
25
-
26
26
  end
metadata CHANGED
@@ -1,95 +1,75 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unimidi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.8
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ari Russo
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-07 00:00:00.000000000 Z
11
+ date: 2022-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: minitest
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '5.5'
20
- - - ">="
21
- - !ruby/object:Gem::Version
22
- version: 5.5.0
23
- type: :development
24
- prerelease: false
25
- version_requirements: !ruby/object:Gem::Requirement
26
- requirements:
27
- - - "~>"
28
- - !ruby/object:Gem::Version
29
- version: '5.5'
30
- - - ">="
31
- - !ruby/object:Gem::Version
32
- version: 5.5.0
33
- - !ruby/object:Gem::Dependency
34
- name: mocha
14
+ name: rake
35
15
  requirement: !ruby/object:Gem::Requirement
36
16
  requirements:
37
17
  - - "~>"
38
18
  - !ruby/object:Gem::Version
39
- version: '1.1'
19
+ version: '13.0'
40
20
  - - ">="
41
21
  - !ruby/object:Gem::Version
42
- version: 1.1.0
22
+ version: 13.0.6
43
23
  type: :development
44
24
  prerelease: false
45
25
  version_requirements: !ruby/object:Gem::Requirement
46
26
  requirements:
47
27
  - - "~>"
48
28
  - !ruby/object:Gem::Version
49
- version: '1.1'
29
+ version: '13.0'
50
30
  - - ">="
51
31
  - !ruby/object:Gem::Version
52
- version: 1.1.0
32
+ version: 13.0.6
53
33
  - !ruby/object:Gem::Dependency
54
- name: rake
34
+ name: rspec
55
35
  requirement: !ruby/object:Gem::Requirement
56
36
  requirements:
57
37
  - - "~>"
58
38
  - !ruby/object:Gem::Version
59
- version: '10.4'
39
+ version: '3.11'
60
40
  - - ">="
61
41
  - !ruby/object:Gem::Version
62
- version: 10.4.2
42
+ version: 3.11.0
63
43
  type: :development
64
44
  prerelease: false
65
45
  version_requirements: !ruby/object:Gem::Requirement
66
46
  requirements:
67
47
  - - "~>"
68
48
  - !ruby/object:Gem::Version
69
- version: '10.4'
49
+ version: '3.11'
70
50
  - - ">="
71
51
  - !ruby/object:Gem::Version
72
- version: 10.4.2
52
+ version: 3.11.0
73
53
  - !ruby/object:Gem::Dependency
74
- name: shoulda-context
54
+ name: rubocop
75
55
  requirement: !ruby/object:Gem::Requirement
76
56
  requirements:
77
57
  - - "~>"
78
58
  - !ruby/object:Gem::Version
79
- version: '1.2'
59
+ version: '1.25'
80
60
  - - ">="
81
61
  - !ruby/object:Gem::Version
82
- version: 1.2.1
62
+ version: 1.25.1
83
63
  type: :development
84
64
  prerelease: false
85
65
  version_requirements: !ruby/object:Gem::Requirement
86
66
  requirements:
87
67
  - - "~>"
88
68
  - !ruby/object:Gem::Version
89
- version: '1.2'
69
+ version: '1.25'
90
70
  - - ">="
91
71
  - !ruby/object:Gem::Version
92
- version: 1.2.1
72
+ version: 1.25.1
93
73
  - !ruby/object:Gem::Dependency
94
74
  name: alsa-rawmidi
95
75
  requirement: !ruby/object:Gem::Requirement
@@ -193,19 +173,11 @@ files:
193
173
  - lib/unimidi/output.rb
194
174
  - lib/unimidi/platform.rb
195
175
  - lib/unimidi/type_conversion.rb
196
- - test/helper.rb
197
- - test/integration/helper.rb
198
- - test/integration/input_test.rb
199
- - test/integration/io_test.rb
200
- - test/unit/device_test.rb
201
- - test/unit/helper.rb
202
- - test/unit/platform_test.rb
203
- - test/unit/type_conversion_test.rb
204
176
  homepage: http://github.com/arirusso/unimidi
205
177
  licenses:
206
178
  - Apache-2.0
207
179
  metadata: {}
208
- post_install_message:
180
+ post_install_message:
209
181
  rdoc_options: []
210
182
  require_paths:
211
183
  - lib
@@ -220,9 +192,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
220
192
  - !ruby/object:Gem::Version
221
193
  version: 1.3.6
222
194
  requirements: []
223
- rubyforge_project: unimidi
224
- rubygems_version: 2.6.8
225
- signing_key:
195
+ rubygems_version: 3.3.3
196
+ signing_key:
226
197
  specification_version: 4
227
198
  summary: Realtime MIDI IO for Ruby
228
199
  test_files: []
data/test/helper.rb DELETED
@@ -1,11 +0,0 @@
1
- dir = File.dirname(File.expand_path(__FILE__))
2
- $LOAD_PATH.unshift("#{dir}/../lib")
3
-
4
- require "minitest/autorun"
5
- require "mocha/test_unit"
6
- require "shoulda-context"
7
- require "unimidi"
8
-
9
- module TestHelper
10
-
11
- end
@@ -1,76 +0,0 @@
1
- require "helper"
2
- require "minitest/autorun"
3
- require "mocha/test_unit"
4
- require "shoulda-context"
5
- require "unimidi"
6
-
7
- module TestHelper
8
-
9
- module Integration
10
-
11
- extend self
12
-
13
- def sysex_ok?
14
- ENV["_system_name"] != "OSX" || !RUBY_PLATFORM.include?("java")
15
- end
16
-
17
- def devices
18
- if @devices.nil?
19
- @devices = {}
20
- { :input => UniMIDI::Input, :output => UniMIDI::Output }.each do |type, klass|
21
- @devices[type] = klass.gets
22
- end
23
- end
24
- @devices
25
- end
26
-
27
- def bytestrs_to_ints(arr)
28
- data = arr.map { |m| m[:data] }.join
29
- output = []
30
- until (bytestr = data.slice!(0,2)).eql?("")
31
- output << bytestr.hex
32
- end
33
- output
34
- end
35
-
36
- class MIDIObj
37
- def initialize(*bytes)
38
- @bytes = bytes
39
- end
40
- def to_bytes
41
- @bytes
42
- end
43
- end
44
-
45
- def message_objects
46
- numeric_messages.map { |message| MIDIObj.new(*message) }
47
- end
48
-
49
- def numeric_messages
50
- messages = [
51
- [0x90, 100, 100], # note on
52
- [0x90, 43, 100], # note on
53
- [0x90, 76, 100], # note on
54
- [0x90, 60, 100], # note on
55
- [0x80, 100, 100] # note off
56
- ]
57
- if sysex_ok?
58
- messages << [0xF0, 0x41, 0x10, 0x42, 0x12, 0x40, 0x00, 0x7F, 0x00, 0x41, 0xF7]
59
- end
60
- messages
61
- end
62
-
63
- def string_messages
64
- messages = [
65
- "906440", # note on
66
- "804340" # note off
67
- ]
68
- if sysex_ok?
69
- messages << "F04110421240007F0041F7"
70
- end
71
- messages
72
- end
73
-
74
- end
75
-
76
- end
@@ -1,44 +0,0 @@
1
- require "integration/helper"
2
-
3
- class UniMIDI::InputTest < Minitest::Test
4
-
5
- context "Input" do
6
-
7
- context "#buffer" do
8
-
9
- setup do
10
- sleep(1)
11
- @input = TestHelper::Integration.devices[:input].open
12
- @output = TestHelper::Integration.devices[:output].open
13
- @messages = TestHelper::Integration.numeric_messages
14
- @bytes = []
15
- end
16
-
17
- teardown do
18
- @input.close
19
- @output.close
20
- end
21
-
22
- should "add received messages to the buffer" do
23
-
24
- @input.buffer.clear
25
-
26
- @messages.each do |message|
27
-
28
- p "sending: #{message}"
29
- @output.puts(message)
30
- @bytes += message
31
- sleep(1)
32
- buffer = @input.buffer.map { |m| m[:data] }.flatten
33
- p "received: #{buffer}"
34
- assert_equal(@bytes, buffer)
35
-
36
- end
37
-
38
- assert_equal(@bytes.length, @input.buffer.map { |m| m[:data] }.flatten.length)
39
-
40
- end
41
-
42
- end
43
- end
44
- end
@@ -1,113 +0,0 @@
1
- require "integration/helper"
2
-
3
- class UniMIDI::IoTest < Minitest::Test
4
-
5
- # ** these tests assume that TestOutput is connected to TestInput
6
- context "UniMIDI" do
7
-
8
- setup do
9
- @input = TestHelper::Integration.devices[:input].open
10
- @output = TestHelper::Integration.devices[:output].open
11
- end
12
-
13
- teardown do
14
- @input.close
15
- @output.close
16
- end
17
-
18
- context "full IO" do
19
-
20
- context "using numeric bytes" do
21
-
22
- setup do
23
- @messages = TestHelper::Integration.numeric_messages
24
- @messages_arr = @messages.inject(&:+).flatten
25
- @received_arr = []
26
- @pointer = 0
27
- end
28
-
29
- should "do IO" do
30
-
31
- @messages.each do |message|
32
- p "sending: #{message}"
33
-
34
- @output.puts(message)
35
- sleep(1)
36
- received = @input.gets.map { |m| m[:data] }.flatten
37
-
38
- p "received: #{received}"
39
-
40
- assert_equal(@messages_arr.slice(@pointer, received.length), received)
41
- @pointer += received.length
42
- @received_arr += received
43
- end
44
- assert_equal(@messages_arr.length, @received_arr.length)
45
- end
46
- end
47
-
48
- context "using byte Strings" do
49
-
50
- setup do
51
- @messages = TestHelper::Integration.string_messages
52
- @messages_str = @messages.join
53
- @received_str = ""
54
- @pointer = 0
55
- end
56
-
57
- should "do IO" do
58
-
59
- @messages.each do |message|
60
-
61
- p "sending: #{message}"
62
-
63
- @output.puts(message)
64
- sleep(1)
65
- received = @input.gets_bytestr.map { |m| m[:data] }.flatten.join
66
- p "received: #{received}"
67
-
68
- assert_equal(@messages_str.slice(@pointer, received.length), received)
69
- @pointer += received.length
70
- @received_str += received
71
- end
72
- assert_equal(@messages_str, @received_str)
73
-
74
- end
75
-
76
- end
77
-
78
- context "using MIDIMessages" do
79
-
80
- setup do
81
- @messages = TestHelper::Integration.message_objects
82
- @messages_arr = @messages.map(&:to_bytes).flatten
83
- @received_arr = []
84
- @pointer = 0
85
- end
86
-
87
- should "do IO" do
88
-
89
- @messages.each do |message|
90
-
91
- p "sending: #{message}"
92
-
93
- @output.puts(message)
94
- sleep(1)
95
- received = @input.gets.map { |m| m[:data] }.flatten
96
-
97
- p "received: #{received}"
98
-
99
- assert_equal(@messages_arr.slice(@pointer, received.length), received)
100
- @pointer += received.length
101
- @received_arr += received
102
- end
103
- assert_equal(@messages_arr.length, @received_arr.length)
104
-
105
- end
106
-
107
- end
108
-
109
- end
110
-
111
- end
112
-
113
- end
@@ -1,197 +0,0 @@
1
- require "unit/helper"
2
-
3
- class UniMIDI::DeviceTest < Minitest::Test
4
-
5
- context "Device" do
6
-
7
- setup do
8
- UniMIDI::Input.stubs(:all).returns(TestHelper::Unit.mock_devices[:input])
9
- UniMIDI::Output.stubs(:all).returns(TestHelper::Unit.mock_devices[:output])
10
- end
11
-
12
- teardown do
13
- UniMIDI::Input.unstub(:all)
14
- UniMIDI::Output.unstub(:all)
15
- end
16
-
17
- context "InstanceMethods" do
18
-
19
- context "Device#type" do
20
-
21
- context "input" do
22
-
23
- setup do
24
- @input = UniMIDI::Input.all.sample
25
- end
26
-
27
- should "be an input" do
28
- assert_equal(:input, @input.type)
29
- end
30
-
31
- end
32
-
33
- context "output" do
34
-
35
- setup do
36
- UniMIDI::Input.stubs(:all).returns(TestHelper::Unit.mock_devices[:input])
37
- @output = UniMIDI::Output.all.sample
38
- end
39
-
40
- should "be an output" do
41
- assert_equal(:output, @output.type)
42
- end
43
-
44
- end
45
-
46
- end
47
-
48
- end
49
-
50
- context "ClassMethods" do
51
-
52
- context ".find_by_name" do
53
-
54
- setup do
55
- @name = UniMIDI::Output.all.map(&:name).sample
56
- @output = UniMIDI::Output.find_by_name(@name)
57
- end
58
-
59
- should "select the correct input" do
60
- assert_equal(@name, @output.name)
61
- end
62
-
63
- end
64
-
65
- context ".first" do
66
-
67
- setup do
68
- @output_to_test = UniMIDI::Output.all[0]
69
- @output_to_test.expects(:open).returns(true)
70
- @output_to_test.expects(:enabled?).returns(true)
71
- @output = UniMIDI::Output.first
72
- end
73
-
74
- teardown do
75
- @output_to_test.unstub(:open)
76
- @output_to_test.unstub(:enabled?)
77
- end
78
-
79
- should "return the first output" do
80
- assert_equal(@output_to_test, @output)
81
- end
82
-
83
- end
84
-
85
- context ".last" do
86
-
87
- setup do
88
- @output_to_test = UniMIDI::Output.all.last
89
- @output_to_test.expects(:open).returns(true)
90
- @output_to_test.expects(:enabled?).returns(true)
91
- @output = UniMIDI::Output.last
92
- end
93
-
94
- teardown do
95
- @output_to_test.unstub(:open)
96
- @output_to_test.unstub(:enabled?)
97
- end
98
-
99
- should "return the last output" do
100
- assert_equal @output_to_test, @output
101
- end
102
-
103
- end
104
-
105
- context ".[]" do
106
-
107
- setup do
108
- @device_to_test = UniMIDI::Input.all[0]
109
- @device_to_test.expects(:open).returns(true)
110
- @device_to_test.expects(:enabled?).returns(true)
111
- @device = UniMIDI::Input[0]
112
- end
113
-
114
- teardown do
115
- @device_to_test.unstub(:open)
116
- @device_to_test.unstub(:enabled?)
117
- end
118
-
119
- should "return correct input" do
120
- assert_equal(@device_to_test, @device)
121
- end
122
-
123
- end
124
-
125
- context ".use" do
126
-
127
- context "block given" do
128
-
129
- setup do
130
- @device_to_test = UniMIDI::Input.all.sample
131
- @index = UniMIDI::Input.all.index(@device_to_test)
132
- @device_to_test.expects(:open).returns(true)
133
- @device_to_test.expects(:enabled?).at_least_once.returns(true)
134
- end
135
-
136
- teardown do
137
- @device_to_test.unstub(:open)
138
- @device_to_test.unstub(:enabled?)
139
- end
140
-
141
- should "return and enable an input" do
142
- @device = nil
143
- UniMIDI::Input.use(@index) do |device|
144
- @device = device
145
- assert(@device.enabled?)
146
- end
147
- assert_equal(UniMIDI::Input.at(@index), @device)
148
- end
149
-
150
- end
151
-
152
- context "with symbol" do
153
-
154
- setup do
155
- @device_to_test = UniMIDI::Output.all.sample
156
- @index = UniMIDI::Output.all.index(@device_to_test)
157
- @device_to_test.expects(:open).returns(true)
158
- @device_to_test.expects(:enabled?).at_least_once.returns(true)
159
- end
160
-
161
- teardown do
162
- @device_to_test.unstub(:open)
163
- @device_to_test.unstub(:enabled?)
164
- end
165
-
166
- should "return an enabled input" do
167
- @device = UniMIDI::Output.use(@index)
168
- assert(@device.enabled?)
169
- assert_equal(UniMIDI::Output.at(@index), @device)
170
- end
171
-
172
- end
173
-
174
- end
175
-
176
- context ".count" do
177
-
178
- setup do
179
- @inputs = UniMIDI::Input.all
180
- @outputs = UniMIDI::Output.all
181
- end
182
-
183
- should "have the correct number of inputs" do
184
- assert_equal(@inputs.count, UniMIDI::Input.count)
185
- end
186
-
187
- should "have the correct number of outputs" do
188
- assert_equal(@outputs.count, UniMIDI::Output.count)
189
- end
190
-
191
- end
192
-
193
- end
194
-
195
- end
196
-
197
- end
data/test/unit/helper.rb DELETED
@@ -1,40 +0,0 @@
1
- require "helper"
2
- require "minitest/autorun"
3
- require "mocha/test_unit"
4
- require "shoulda-context"
5
- require "unimidi"
6
-
7
- module TestHelper
8
-
9
- module Unit
10
-
11
- extend self
12
-
13
- def sysex_ok?
14
- ENV["_system_name"] != "OSX" || !RUBY_PLATFORM.include?("java")
15
- end
16
-
17
- def mock_devices
18
- if @mock_devices.nil?
19
- @mock_devices = {
20
- input: [],
21
- output: []
22
- }
23
- 2.times do |i|
24
- input = Object.new
25
- input.stubs(:type).returns(:input)
26
- input.stubs(:name).returns("MIDI Input #{i}")
27
- @mock_devices[:input] << input
28
- end
29
- 3.times do |i|
30
- input = Object.new
31
- input.stubs(:type).returns(:output)
32
- input.stubs(:name).returns("MIDI Output #{i}")
33
- @mock_devices[:output] << input
34
- end
35
- end
36
- @mock_devices
37
- end
38
-
39
- end
40
- end
@@ -1,37 +0,0 @@
1
- require "unit/helper"
2
-
3
- class UniMIDI::PlatformTest < Minitest::Test
4
-
5
- context "Platform" do
6
-
7
- context ".bootstrap" do
8
-
9
- if RUBY_PLATFORM.include?("java")
10
- should "recognize java" do
11
- assert_equal(UniMIDI::Adapter::MIDIJRuby::Loader, UniMIDI::Loader.instance_variable_get("@loader"))
12
- end
13
- end
14
-
15
- if RUBY_PLATFORM.include?("linux")
16
- should "recognize linux" do
17
- assert_equal(UniMIDI::Adapter::AlsaRawMIDI::Loader, UniMIDI::Loader.instance_variable_get("@loader"))
18
- end
19
- end
20
-
21
- if RUBY_PLATFORM.include?("darwin")
22
- should "recognize osx" do
23
- assert_equal(UniMIDI::Adapter::CoreMIDI::Loader, UniMIDI::Loader.instance_variable_get("@loader"))
24
- end
25
- end
26
-
27
- if RUBY_PLATFORM.include?("mingw")
28
- should "recognize windows" do
29
- assert_equal(UniMIDI::Adapter::MIDIWinMM::Loader, UniMIDI::Loader.instance_variable_get("@loader"))
30
- end
31
- end
32
-
33
- end
34
-
35
- end
36
-
37
- end
@@ -1,18 +0,0 @@
1
- require "unit/helper"
2
-
3
- class UniMIDI::TypeConversionTest < Minitest::Test
4
-
5
- context "TypeConversion" do
6
-
7
- context "#numeric_byte_array_to_hex_string" do
8
-
9
- should "convert byte array to hex string" do
10
- result = UniMIDI::TypeConversion.numeric_byte_array_to_hex_string([0x90, 0x40, 0x40])
11
- assert "904040", result
12
- end
13
-
14
- end
15
-
16
- end
17
-
18
- end