Class: LogicalRhythms
- Inherits:
-
Object
- Object
- LogicalRhythms
- Defined in:
- lib/rhythmruby/LogicalRhythms.rb
Constant Summary collapse
- @@eventMarker =
symbol which denotes event or hit
'#'
- @@silenceMarker =
symbol that denotes silence
'-'
Class Method Summary collapse
-
.AND(rhythmA, rhythmB) ⇒ String
logical AND of two rhythms, returns only events present in both rhythms.
-
.Exclusion(masterRhythm, slaveRhythm) ⇒ String
logical exlusion of two rhythms, removes events from slave simultaneous with an event in the master rhythm.
-
.OR(rhythmA, rhythmB) ⇒ String
logical OR of two rhythms, thus event in result rhythm, when at least one of two original rhythms has an event (functionally the same as addition).
-
.XOR(rhythmA, rhythmB) ⇒ String
logical XOR of two rhythms, true except both true or both false.
Class Method Details
.AND(rhythmA, rhythmB) ⇒ String
logical AND of two rhythms, returns only events present in both rhythms
63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/rhythmruby/LogicalRhythms.rb', line 63 def self.AND(rhythmA, rhythmB) resultRhythm = "" rhythmA.split("").zip(rhythmB.split("")).each do |symA, symB| if symA == @@eventMarker and symB == @@eventMarker resultRhythm += @@eventMarker else resultRhythm += @@silenceMarker end end return resultRhythm end |
.Exclusion(masterRhythm, slaveRhythm) ⇒ String
logical exlusion of two rhythms, removes events from slave simultaneous with an event in the master rhythm
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/rhythmruby/LogicalRhythms.rb', line 10 def self.Exclusion(masterRhythm, slaveRhythm) masterRhythm.split("").zip(slaveRhythm.split("")).each_with_index do |symbols, index| master,slave = symbols if master == @@eventMarker && slave == @@eventMarker # if both have an event slaveRhythm[index] = @@silenceMarker # replace event with silence end end return slaveRhythm end |
.OR(rhythmA, rhythmB) ⇒ String
logical OR of two rhythms, thus event in result rhythm, when at least one of two original rhythms has an event (functionally the same as addition)
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/rhythmruby/LogicalRhythms.rb', line 45 def self.OR(rhythmA, rhythmB) resultRhythm = "" rhythmA.split("").zip(rhythmB.split("")).each do |symA, symB| if symA == @@eventMarker or symB == @@eventMarker resultRhythm += @@eventMarker else resultRhythm += @@silenceMarker end end return resultRhythm end |
.XOR(rhythmA, rhythmB) ⇒ String
logical XOR of two rhythms, true except both true or both false
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/rhythmruby/LogicalRhythms.rb', line 25 def self.XOR(rhythmA, rhythmB) resultRhythm = "" rhythmA.split("").zip(rhythmB.split("")).each do |symA, symB| if symA == @@eventMarker && symB == @@eventMarker # if both have an event resultRhythm += @@silenceMarker # replace event with silence elsif symA == @@eventMarker or symB == @@eventMarker resultRhythm += @@eventMarker else resultRhythm += @@silenceMarker end end return resultRhythm end |