rhythmruby 0.1.1 → 0.1.2

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.
data/README.md CHANGED
@@ -1,9 +1,11 @@
1
1
  RhythmRuby: Midi rhythms through String manipulation
2
2
  ====================================================
3
3
 
4
- **Author**: Luuk van der Velden, (Amsterdam, 2013)
5
- **Website**:
4
+ **Author**: Luuk van der Velden, (Amsterdam, 2013)
5
+ **Website**: http://rubygems.org/gems/rhythmruby
6
6
  **Git**: https://github.com/Lvelden/rhythmruby.git
7
+ **Docs**: http://rubydoc.info/gems/rhythmruby/0.1.2/frames
8
+ **Dependency**: midilib by Jim Menard
7
9
 
8
10
  Synopsis
9
11
  --------
@@ -26,18 +28,19 @@ StringCompiler Class allows the creation of rhythm snippets and compiles them in
26
28
  These snippets capture the repetitive aspects of most rhythms.
27
29
 
28
30
  **3. countBase** is the rhythmical length that is assigned to one symbol in a string.
29
- It is measured in quartenote lengths (relative to bpm), thus countBase: 1.0, means one quarter note per symbol.
31
+ It is measured in quarter note lengths (relative to bpm), thus countBase: 1.0, means one quarter note per symbol.
30
32
 
31
33
  Classes
32
34
  -------
33
35
  The **RhythmCompiler** (class) generates rhythm snippets and combines these into rhythm strings.
36
+ **LogicalRhythms** (class) allows logical interaction between different rhythm strings.
34
37
  These can be parsed to MIDI ready data by the **RhythmParser** (class).
35
38
  The parsed output can be written to a MIDI file by the **MidiWriter** (class instance).
36
39
 
37
40
  Examples and Docs
38
41
  -----------------
39
42
 
40
- Check out the examples provided and the documentation based on YARD. The examples are aimed at
43
+ Check out the examples provided and the documentation. The examples are aimed at
41
44
  creating single and multi instrument rhythms. For instance **Meshuggah_example.rb** explains the creation of the
42
45
  intro rhythm of 'Perpetual Black Second' by Meshuggah (Nothing, 2002), using ruby scripting.
43
46
 
@@ -73,7 +76,7 @@ pmidi. pmidi can send the MIDI events to any ALSA channel f.i. the MIDI-in of th
73
76
  is a nice drum sampler and sequencer. In this way you can listen to the rhythms you create without leaving your
74
77
  IDE or editor.
75
78
 
76
- Rational
79
+ Rationale
77
80
  --------
78
81
 
79
82
  RhythmRuby's strength lies in the rhythm string abstraction. It allows easy computer
data/lib/rhythmruby.rb CHANGED
@@ -1,5 +1,6 @@
1
- # main file to load seperate class files
1
+ # main file to load separate class files
2
2
 
3
3
  require "rhythmruby/RhythmParser"
4
4
  require "rhythmruby/RhythmCompiler"
5
5
  require "rhythmruby/MidiWriter"
6
+ require "rhythmruby/LogicalRhythms"
@@ -0,0 +1,76 @@
1
+ class LogicalRhythms
2
+ @@eventMarker = '#' # symbol which denotes event or hit
3
+ @@silenceMarker = '-' # symbol that denotes silence
4
+
5
+ # logical exlusion of two rhythms, removes events from slave simultaneous
6
+ # with an event in the master rhythm
7
+ # @param [String] masterRhythm rhythm to intersect with
8
+ # @param [String] slaveRhythm rhythm to intersect
9
+ # @return [String] intersected slaveRhythm
10
+ def self.Exclusion(masterRhythm, slaveRhythm)
11
+ masterRhythm.split("").zip(slaveRhythm.split("")).each_with_index do
12
+ |symbols, index|
13
+ master,slave = symbols
14
+ if master == @@eventMarker && slave == @@eventMarker # if both have an event
15
+ slaveRhythm[index] = @@silenceMarker # replace event with silence
16
+ end
17
+ end
18
+ return slaveRhythm
19
+ end
20
+
21
+ # logical XOR of two rhythms, true except both true
22
+ # @param [String] masterRhythm rhythm to intersect with
23
+ # @param [String] slaveRhythm rhythm to intersect
24
+ # @return [String] intersected slaveRhythm
25
+ def self.XOR(rhythmA, rhythmB)
26
+ resultRhythm = ""
27
+ rhythmA.split("").zip(rhythmB.split("")).each do
28
+ |symA, symB|
29
+ if symA == @@eventMarker && symB == @@eventMarker # if both have an event
30
+ resultRhythm += @@silenceMarker # replace event with silence
31
+ elsif symA == @@eventMarker or symB == @@eventMarker
32
+ resultRhythm += @@eventMarker
33
+ else
34
+ resultRhythm += @@silenceMarker
35
+ end
36
+ end
37
+ return resultRhythm
38
+ end
39
+
40
+ # logical OR of two rhythms, thus event in result rhythm, when at least one
41
+ # of two original rhythms has an event (functionally the same as addition)
42
+ # @param [String] rhythmA, one of the rhythms to or
43
+ # @param [String] rhythmB, one of the rhythms to or
44
+ # @return [String] resultRhyhtm, result of logical or
45
+ def self.OR(rhythmA, rhythmB)
46
+ resultRhythm = ""
47
+
48
+ rhythmA.split("").zip(rhythmB.split("")).each do
49
+ |symA, symB|
50
+ if symA == @@eventMarker or symB == @@eventMarker
51
+ resultRhythm += @@eventMarker
52
+ else
53
+ resultRhythm += @@silenceMarker
54
+ end
55
+ end
56
+ return resultRhythm
57
+ end
58
+
59
+ # logical AND of two rhythms, returns only events present in both rhythms
60
+ # @param [String] rhythmA, one of the rhythms to and
61
+ # @param [String] rhythmB, one of the rhythms to and
62
+ # @return [String] resultRhythm, result of logical and
63
+ def self.AND(rhythmA, rhythmB)
64
+ resultRhythm = ""
65
+ rhythmA.split("").zip(rhythmB.split("")).each do
66
+ |symA, symB|
67
+ if symA == @@eventMarker and symB == @@eventMarker
68
+ resultRhythm += @@eventMarker
69
+ else
70
+ resultRhythm += @@silenceMarker
71
+ end
72
+ end
73
+ return resultRhythm
74
+ end
75
+
76
+ end
@@ -1,3 +1,3 @@
1
1
  module Rhythmruby
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rhythmruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-06 00:00:00.000000000 Z
12
+ date: 2013-01-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: midilib
@@ -44,6 +44,7 @@ files:
44
44
  - examples/drum_kit_example.rb
45
45
  - examples/single_rhythm_example.rb
46
46
  - lib/rhythmruby.rb
47
+ - lib/rhythmruby/LogicalRhythms.rb
47
48
  - lib/rhythmruby/MidiWriter.rb
48
49
  - lib/rhythmruby/RhythmCompiler.rb
49
50
  - lib/rhythmruby/RhythmParser.rb