This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'json' | |
class Array | |
def to_h | |
inject({}) { |memo, kv| key, value = *kv; memo[key] = value; memo } | |
end | |
end | |
class Struct | |
def to_h |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module RuleBook | |
def RuleBook.add_rules(object, instance_or_class, rules) | |
instance_or_class = instance_or_class.to_s.downcase.strip.to_sym | |
raise(ArgumentError, "'instance_or_class' must equal :instance or :class") unless [:instance, :class].include?(instance_or_class) | |
raise(ArgumentError, "'rules' must be a Hash") unless rules.is_a?(Hash) | |
unless object.instance_variable_get(:@_rulebook_initiated) # Class instance variable. Not class variable. Not instance variable. Is confusing. | |
object.instance_variable_set(:@_rulebook_initiated, true) | |
object.instance_variable_set(:@_rulebook, {:instance=>{}, :class=>{}}) # @_rulebook is actually two rulebooks, instance and class | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
my_proj = Project.new do | |
drum_kit do | |
kick "kick.wav" | |
closed_hi_hat "closedhihat.wav" | |
snare "snare.wav" | |
end | |
patterns do | |
simple do | |
kick | |
kick & snare |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'ffi' | |
# http://msdn.microsoft.com/en-us/library/aa383751(VS.85).aspx | |
# DWORD appears to be an :int (32 bits that is, so :int should work well) | |
# HWND appears to be a :pointer see this thread for why you should not actually read from the value it points to. You may as well just use a :long or :ulong. | |
# LPDWORD is a pointer (the P standing for pointer) | |
# LPARAM appears to be a long (hence the L) | |
# WPARAM appears to be a long (i.e. 64 bits on 64bit OS). | |
# BOOL is an :int |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'midi-winmm' | |
class Numeric | |
def to_hex | |
"%02x" % self | |
end | |
end | |
class String | |
def to_hex |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "windows.h" | |
#include "mmsystem.h" | |
#include "ruby.h" | |
static VALUE rb_mMIDI_devices(VALUE self) | |
{ | |
VALUE rb_hash_inputDeviceList, rb_hash_outputDeviceList, rb_hash_resultDeviceList; | |
unsigned long midiInNumDevs, midiOutNumDevs, i; | |
MIDIOUTCAPS moc; | |
MIDIINCAPS mic; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$LOAD_PATH.unshift(File.dirname(__FILE__)) | |
require 'midi-winmm' | |
# tested with midi-winmm, but I assume will work with alsa-rawmidi | |
class Numeric | |
def to_hex_str | |
"%02x" % self | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Node | |
attr_accessor :index, :next, :value | |
def initialize(index, value) | |
@index, @value, @next = index, value, nil | |
end | |
end | |
class NodeList | |
include Enumerable |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module MIDI | |
# Source: http://www.midi.org/techspecs/manid.php | |
Manufacturers = { | |
"Ta Horng Musical Instrument" => [0x00, 0x00, 0x74], | |
"e-Tek Labs (Forte Tech)" => [0x00, 0x00, 0x75], | |
"Electro-Voice" => [0x00, 0x00, 0x76], | |
"Midisoft Corporation" => [0x00, 0x00, 0x77], | |
"QSound Labs" => [0x00, 0x00, 0x78], | |
"Westrex" => [0x00, 0x00, 0x79], | |
"Nvidia" => [0x00, 0x00, 0x7A], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
user system total real | |
load YAML | |
doc["manufacturers"]["Roland"] 65 | |
0.093000 0.156000 0.249000 ( 0.241016) | |
load Consts | |
MIDI::CC_FOOT_CONTROLLER: 4 | |
0.000000 0.000000 0.000000 ( 0.003001) | |
load Manufacturers | |
Roland Corporation: [65] | |
0.000000 0.000000 0.000000 ( 0.004000) |