rtmidi 0.2.1 → 0.2.2

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
2
  SHA1:
3
- metadata.gz: a7296f8034f41a26f21bbe45d3dfcc31c66a4b62
4
- data.tar.gz: 53af0cdf65ae9250f0aa2da07d379b61d1f154f6
3
+ metadata.gz: 951dc43b29adbc7d76f79f191f1e4a9ad6c034fd
4
+ data.tar.gz: 4733255fee9f6e321cc690594afafa8fa9e520af
5
5
  SHA512:
6
- metadata.gz: 63f9593bc6a9f405d923607fd2fa82405f8fdaf217ed808386b46f864b1442083874632bc048a8ec36bcbe75906be14dc9e1c30856cc412458abdff40ae7ba6d
7
- data.tar.gz: 5c64d24a84430a1296bdb28a88510cfdf302bc20f639c014200f2b417500e007f3259b9cb51b162f39d0c8ef2dcdb6a12f41b31268ab3361774fb3effe9f82ef
6
+ metadata.gz: 9777c38f05c57c90f63c731279cb0c3d4ca3064049758d4c28c21bcd8a458900a0d51c33fff557d449bd4d7fdbfadcd6d1ecd7b4aa324f98ece78af57dc3849b
7
+ data.tar.gz: 897d148e298d4b9d76ebf953234bfe35bc5e3c76457f4395e8728cf519dacc77400a8d56375b68afbb30499b07e3c0b5587ddb45a525e1c699d74e4a9059e17d
data/README.md CHANGED
@@ -4,7 +4,6 @@ Ruby-RtMidi
4
4
  [Ruby](http://www.ruby-lang.org/) wrapper for [RtMidi](http://www.music.mcgill.ca/~gary/rtmidi/index.html),
5
5
  a cross-platform C++ library for realtime MIDI input and output.
6
6
 
7
- <br>
8
7
  Features:
9
8
 
10
9
  * List MIDI I/O ports
@@ -15,32 +14,39 @@ In other words, it can handle [channel messages](http://www.cs.cf.ac.uk/Dave/Mul
15
14
  (notes, control change, pitch bend, pressure, program),
16
15
  but there is no support for [SySex](https://en.wikipedia.org/wiki/SysEx#System_Exclusive_messages) messages yet.
17
16
 
18
- <br>
19
17
  Supported Platforms:
20
18
 
21
19
  * OS X
22
- * Windows with [MinGW](http://www.mingw.org/)
23
- * Linux? It compiles on Linux with [JACK](http://jackaudio.org/) but is otherwise untested.
20
+ * Windows
21
+ * Linux with [JACK](http://jackaudio.org/) or [ALSA](http://www.alsa-project.org)
24
22
 
25
- <br>
26
23
 
27
24
  Requirements
28
25
  ============
29
26
 
30
- To install, you need `gcc` and `g++` on your PATH. Here's the recommended approach for your system:
27
+ To install, you need `gcc` and `g++` on your PATH.
28
+
29
+ On Windows, you can use Visual Studio's `cl.exe` compiler instead.
30
+
31
+ Here's the recommended approach for your system:
31
32
 
32
33
  OS X Setup
33
34
  ----------
34
35
 
35
36
  * Install XCode via the Apple AppStore.
36
- * Open Preferences and install the "Command Line Tools" from the Downloads tab.
37
+ * Open XCode's Preferences and install "Command Line Tools" in the Downloads tab.
37
38
 
38
39
  See [this stackoverflow discussion](http://stackoverflow.com/questions/9329243/xcode-4-4-command-line-tools) for help.
39
40
 
40
41
  Windows Setup
41
42
  -------------
42
43
 
43
- * [Install MinGW](http://sourceforge.net/projects/mingw/files/) (see "Looking for the latest version?" link)
44
+ ### with [Visual Studio](http://www.microsoft.com/visualstudio) (cl.exe)
45
+ * Install [Visual Studio](http://www.microsoft.com/visualstudio) (Tested with Visual C++ 2010 Express. Any recent version with a C++ compiler should work.)
46
+ * Use the "Visual Studio Command Prompt" to install
47
+
48
+ ### with [MinGW](http://www.mingw.org/) (gcc/g++)
49
+ * [Install MinGW](http://sourceforge.net/projects/mingw/files/latest/download)
44
50
  * During installation, on the "Select Components" screen, install the following:
45
51
  * C Compiler
46
52
  * C++ Compiler
@@ -55,7 +61,6 @@ Linux Setup (Ubuntu)
55
61
  sudo apt-get install jackd
56
62
  sudo apt-get install libjack-dev
57
63
 
58
- <br>
59
64
 
60
65
  Installation
61
66
  ============
@@ -64,7 +69,6 @@ Assuming you have Ruby installed, and are ready to compile C++ code with `gcc`,
64
69
 
65
70
  gem install rtmidi
66
71
 
67
- <br>
68
72
 
69
73
  Usage
70
74
  =====
@@ -75,8 +79,15 @@ See the following examples:
75
79
  * [MIDI output](http://rdoc.info/github/adamjmurray/ruby-rtmidi/file/examples/play_notes.rb)
76
80
  * [MIDI input](http://rdoc.info/github/adamjmurray/ruby-rtmidi/file/examples/monitor_input.rb)
77
81
 
78
- <br>
79
82
 
80
83
  Documentation
81
84
  =============
82
- [http://rdoc.info/github/adamjmurray/ruby-rtmidi/frames](http://rdoc.info/github/adamjmurray/ruby-rtmidi/frames)
85
+ [http://rdoc.info/github/adamjmurray/ruby-rtmidi/frames](http://rdoc.info/github/adamjmurray/ruby-rtmidi/frames)
86
+
87
+
88
+ Changelog
89
+ =========
90
+
91
+ * 0.2.2 - Compilable with Visual Studio on Windows
92
+ * 0.2.1 - Linux support (thanks to [@quark-zju](https://github.com/quark-zju))
93
+ * 0.2 - First stable release
data/ext/Rakefile CHANGED
@@ -25,15 +25,26 @@ def run(cmd)
25
25
  end
26
26
 
27
27
 
28
+ require "mkmf"
29
+ COMPILER = if WINDOWS and find_executable "cl.exe"
30
+ :cl
31
+ else
32
+ if find_executable "gcc" and find_executable "g++"
33
+ :gcc
34
+ else
35
+ abort "Cannot find gcc/g++ #{'or cl.exe ' if WINDOWS}compiler"
36
+ end
37
+ end
38
+
28
39
  PREDEFINE, SYSTEM_LIBS = *case
29
- when OS_X then ["-D__MACOSX_CORE__", "-framework CoreMIDI -framework CoreAudio -framework CoreFoundation"]
30
- when WINDOWS then ["-D__WINDOWS_MM__", "-lwinmm"]
40
+ when OS_X then ["__MACOSX_CORE__", "-framework CoreMIDI -framework CoreAudio -framework CoreFoundation"]
41
+ when WINDOWS then ["__WINDOWS_MM__", "-lwinmm"]
31
42
  when LINUX then
32
43
  defines, libs = '', ''
33
44
  {:alsa => '__LINUX_ALSA__', :jack => '__UNIX_JACK__'}.select do |pkg, _|
34
45
  system "pkg-config --exists #{pkg}"
35
46
  end.each do |pkg, macro|
36
- defines << "-D#{macro} "
47
+ defines << "#{macro} "
37
48
  libs << `pkg-config --libs #{pkg}`.chomp
38
49
  end
39
50
  if defines.empty?
@@ -43,22 +54,44 @@ PREDEFINE, SYSTEM_LIBS = *case
43
54
  else
44
55
  end
45
56
 
57
+
58
+ def compile_rtmidi
59
+ cd RTMIDI_DIR
60
+ if COMPILER == :gcc
61
+ run "g++ -O3 -Wall -Iinclude -fPIC -D#{PREDEFINE} -o RtMidi.o -c RtMidi.cpp"
62
+ else
63
+ run "cl /O2 /Iinclude /D#{PREDEFINE} /EHsc /FoRtMidi.obj /c RtMidi.cpp"
64
+ end
65
+ end
66
+
67
+ def compile_ruby_rtmidi_wrapper
68
+ cd EXT_DIR
69
+ if COMPILER == :gcc
70
+ run "g++ -g -Wall -I#{RTMIDI_DIR} -fPIC -o ruby-rtmidi.o -c ruby-rtmidi.cpp"
71
+ else
72
+ run "cl /I#{RTMIDI_DIR} /D__RUBY_RTMIDI_DLL__ /EHsc /Foruby-rtmidi.obj /c ruby-rtmidi.cpp"
73
+ end
74
+ end
75
+
76
+ def create_shared_library
77
+ cd EXT_DIR
78
+ if COMPILER == :gcc
79
+ run "g++ -g -Wall -I#{RTMIDI_DIR} -I#{RTMIDI_DIR}/include -D#{PREDEFINE} -fPIC -shared -o ruby-rtmidi.so " +
80
+ "ruby-rtmidi.o #{RTMIDI_DIR}/RtMidi.o #{SYSTEM_LIBS}"
81
+ else
82
+ run "cl /I#{RTMIDI_DIR} /I#{RTMIDI_DIR}/include /D#{PREDEFINE} /LD ruby-rtmidi.obj #{RTMIDI_DIR}/RtMidi.obj winmm.lib"
83
+ end
84
+ end
85
+
86
+
46
87
  desc 'run the make task'
47
88
  task :default => :make
48
89
 
49
- desc 'build the RtMidi C++ code'
90
+ desc 'build the RtMidi C++ library with Ruby FFI wrapper'
50
91
  task :make do
51
- require "mkmf"
52
- abort "missing gcc" unless find_executable "gcc"
53
- abort "missing g++" unless find_executable "g++"
54
-
55
- cd RTMIDI_DIR
56
- run "g++ -O3 -Wall -Iinclude -fPIC #{PREDEFINE} -c RtMidi.cpp -o RtMidi.o"
92
+ compile_rtmidi
57
93
  puts
58
-
59
- cd EXT_DIR
60
- run "g++ -g -Wall -I#{RTMIDI_DIR} -fPIC -c ruby-rtmidi.cpp"
94
+ compile_ruby_rtmidi_wrapper
61
95
  puts
62
- run "g++ -g -Wall -I#{RTMIDI_DIR} -I#{RTMIDI_DIR}/include #{PREDEFINE} -fPIC -shared -o ruby-rtmidi.so " +
63
- "ruby-rtmidi.o #{RTMIDI_DIR}/RtMidi.o #{SYSTEM_LIBS}"
96
+ create_shared_library
64
97
  end
data/ext/ruby-rtmidi.cpp CHANGED
@@ -1,6 +1,7 @@
1
1
  #include "RtMidi.h"
2
2
  #include "RtError.h"
3
3
  #include <vector>
4
+ #include <cstring>
4
5
  #include <iostream> // TODO: can probably stop including this later when done debugging
5
6
 
6
7
  #include "ruby-rtmidi.h"
@@ -23,8 +24,13 @@ int midiin_port_count(rtmidi_ptr p) {
23
24
  }
24
25
 
25
26
  const char* midiin_port_name(rtmidi_ptr p, int port_index) {
26
- RtMidiIn *midiin = static_cast<RtMidiIn *>(p);
27
- return midiin->getPortName(port_index).c_str(); // getPortName returns a std::string, use c_str() to be convert to char*
27
+ RtMidiIn *midiin = static_cast<RtMidiIn *>(p);
28
+ std::string name = midiin->getPortName(port_index);
29
+ // std::string will be freed from memory at end of scope, so copy into a c string before returning.
30
+ // returning name directly caused noticeable problems when compiled with cl.exe
31
+ char* cstr = new char [name.length()+1];
32
+ std::strcpy(cstr, name.c_str());
33
+ return cstr;
28
34
  }
29
35
 
30
36
  void midiin_open_port(rtmidi_ptr p, int port_index) {
@@ -84,8 +90,13 @@ int midiout_port_count(rtmidi_ptr p) {
84
90
  }
85
91
 
86
92
  const char* midiout_port_name(rtmidi_ptr p, int port_index) {
87
- RtMidiOut *midiout = static_cast<RtMidiOut *>(p);
88
- return midiout->getPortName(port_index).c_str(); // getPortName returns a std::string, use c_str() to be convert to char*
93
+ RtMidiOut *midiout = static_cast<RtMidiOut *>(p);
94
+ std::string name = midiout->getPortName(port_index);
95
+ // std::string will be freed from memory at end of scope, so copy into a c string before returning.
96
+ // returning name directly caused noticeable problems when compiled with cl.exe
97
+ char* cstr = new char [name.length()+1];
98
+ std::strcpy(cstr, name.c_str());
99
+ return cstr;
89
100
  }
90
101
 
91
102
  void midiout_open_port(rtmidi_ptr p, int port_index) {
data/ext/ruby-rtmidi.h CHANGED
@@ -1,3 +1,9 @@
1
+ #ifdef __RUBY_RTMIDI_DLL__
2
+ #define DLL_EXPORT __declspec( dllexport ) // export function definitions for Windows DLL compiled via cl.exe
3
+ #else
4
+ #define DLL_EXPORT
5
+ #endif
6
+
1
7
  extern "C"
2
8
  {
3
9
  typedef void* rtmidi_ptr;
@@ -6,39 +12,39 @@ extern "C"
6
12
  //================================================
7
13
  // INPUT
8
14
 
9
- rtmidi_ptr midiin_new();
15
+ DLL_EXPORT rtmidi_ptr midiin_new();
10
16
 
11
- void midiin_delete(rtmidi_ptr midiin);
17
+ DLL_EXPORT void midiin_delete(rtmidi_ptr midiin);
12
18
 
13
- int midiin_port_count(rtmidi_ptr midiin);
19
+ DLL_EXPORT int midiin_port_count(rtmidi_ptr midiin);
14
20
 
15
- const char* midiin_port_name(rtmidi_ptr midiin, int port_index);
21
+ DLL_EXPORT const char* midiin_port_name(rtmidi_ptr midiin, int port_index);
16
22
 
17
- void midiin_open_port(rtmidi_ptr p, int port_index);
23
+ DLL_EXPORT void midiin_open_port(rtmidi_ptr p, int port_index);
18
24
 
19
- void midiin_close_port(rtmidi_ptr p);
25
+ DLL_EXPORT void midiin_close_port(rtmidi_ptr p);
20
26
 
21
- void midiin_ignore_types(rtmidi_ptr p, bool sysex, bool timing, bool active_sensing);
27
+ DLL_EXPORT void midiin_ignore_types(rtmidi_ptr p, bool sysex, bool timing, bool active_sensing);
22
28
 
23
- void midiin_set_callback(rtmidi_ptr p, rtmidi_callback callback);
29
+ DLL_EXPORT void midiin_set_callback(rtmidi_ptr p, rtmidi_callback callback);
24
30
 
25
- void midiin_cancel_callback(rtmidi_ptr p);
31
+ DLL_EXPORT void midiin_cancel_callback(rtmidi_ptr p);
26
32
 
27
33
 
28
34
  //================================================
29
35
  // OUTPUT
30
36
 
31
- rtmidi_ptr midiout_new();
37
+ DLL_EXPORT rtmidi_ptr midiout_new();
32
38
 
33
- void midiout_delete(rtmidi_ptr midiout);
39
+ DLL_EXPORT void midiout_delete(rtmidi_ptr midiout);
34
40
 
35
- int midiout_port_count(rtmidi_ptr midiout);
41
+ DLL_EXPORT int midiout_port_count(rtmidi_ptr midiout);
36
42
 
37
- const char* midiout_port_name(rtmidi_ptr midiout, int port_index);
43
+ DLL_EXPORT const char* midiout_port_name(rtmidi_ptr midiout, int port_index);
38
44
 
39
- void midiout_open_port(rtmidi_ptr p, int port_index);
45
+ DLL_EXPORT void midiout_open_port(rtmidi_ptr p, int port_index);
40
46
 
41
- void midiout_close_port(rtmidi_ptr p);
47
+ DLL_EXPORT void midiout_close_port(rtmidi_ptr p);
42
48
 
43
- void midiout_send_message(rtmidi_ptr p, int byte1, int byte2, int byte3);
49
+ DLL_EXPORT void midiout_send_message(rtmidi_ptr p, int byte1, int byte2, int byte3);
44
50
  };
data/ext/ruby-rtmidi.o CHANGED
Binary file
data/ext/ruby-rtmidi.so CHANGED
Binary file
data/lib/rtmidi/in.rb CHANGED
@@ -28,7 +28,7 @@ module RtMidi
28
28
  # @see #port_name
29
29
  # @see #open_port
30
30
  def port_names
31
- @port_namess ||= (
31
+ @port_names ||= (
32
32
  names = []
33
33
  port_count.times{|i| names << Interface::midiin_port_name(@midiin, i) }
34
34
  names
@@ -5,7 +5,10 @@ module RtMidi
5
5
  # @see RtMidi::Out
6
6
  module Interface
7
7
  extend FFI::Library
8
- ffi_lib File.expand_path("../../ext/ruby-rtmidi.so", File.dirname(__FILE__))
8
+ ffi_lib [
9
+ File.expand_path("../../ext/ruby-rtmidi.so", File.dirname(__FILE__)),
10
+ File.expand_path("../../ext/ruby-rtmidi.dll", File.dirname(__FILE__))
11
+ ]
9
12
 
10
13
  #####################################
11
14
  # INPUT
data/lib/rtmidi/out.rb CHANGED
@@ -28,7 +28,7 @@ module RtMidi
28
28
  # @see #port_name
29
29
  # @see #open_port
30
30
  def port_names
31
- @port_namess ||= (
31
+ @port_names ||= (
32
32
  names = []
33
33
  port_count.times{|i| names << Interface::midiout_port_name(@midiout, i) }
34
34
  names
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rtmidi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Murray