Skip to content

Commit

Permalink
added some RhythmicCell manipulations
Browse files Browse the repository at this point in the history
  • Loading branch information
smoge committed Mar 11, 2011
1 parent 519d6f6 commit bc1ef52
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 60 deletions.
33 changes: 22 additions & 11 deletions Array-ext.sc
@@ -1,26 +1,37 @@
+ Array {


gdc {

if(this.containsSeqColl.not, {
^this.reduce({arg a, b; a gcd: b})
^this.reduce({arg a, b; a.asInteger gcd: b.asInteger})
});
}


asRC {

^RhythmCell(this)
^RhythmicCell(this)
}


asPseudoBar {
asRS {

var thisLenght, thisStruct;
^RhythmicSeq(this)
}


addRC { arg thisRSeq;

#thisLenght, thisStruct = this;
thisLenght = (thisLenght.asFloat / 8).round(0.5);
^[thisLenght, thisStruct];
thisRSeq.put(this)
}


addRS { arg thisRSeq;

this.do { |i|
thisRSeq.put(i)
};
}

}
41 changes: 14 additions & 27 deletions LilyRhythm.scd
@@ -1,42 +1,29 @@

a = RhythmCell([3, [[2, [1, 1, 1]], 1, 1, 1]] )

a.lyHeads
a.heads
a.subHeads
a.string

a.lenght
a.struct
a.edit
a.string
a.miniLenght
a.noTimeSigString
b = a.adjustedStruct[0]
b.asRC.noTimeSigString
b.string
a.lenght.class
c = [8, [1, 1, 1]].asPseudoBar
c.asRC
a = RhythmicCell([3, [2, [2, [1, 1, 1, 1, 1, 1]], 1, 4, 2]] )
a.plot

c[1].class
[1, [1, 1, 1]].asRC.string
c.asRC.string

a = [
[3, [2, [2, [1, 1, 1, 1, 1, 1]], 1, 4, 2]],
[3, [2, [2, [1, 1, 1, 1, 1, 1]], 1, 4, 2]],
[3, [2, [2, [1, 1, 1, 1, 1, 1]], 1, 4, 2]],
[3, [2, [2, [1, 1, 1, 1, 1, 1]], 1, 4, 2]]
].asRS.plot

4 -> 0.5
8 -> 1
16 -> 2
32 -> 4
x = rhythmicseq(a)
x.put(a)
x.plot

a.plot
a.string

a.lenght
a.struct
a.heads
a.heads.sum
a.factor
a.tuplet
a = [2, [1, 1, 1, 1, 1, 1, 1, 2, 1]].asRC.plo
a = [2, [1, 1, 1, 1, 1, 1, 1, 2, 1]].asRC
a.hasTuplet
a.struct
a.adjustedStruct
Expand Down
31 changes: 31 additions & 0 deletions RhythmCell.sc
Expand Up @@ -7,6 +7,7 @@ RhythmicCell : LilyRhythmObj {


*new { arg thisCell;

^super.new.initRhythmCell(thisCell);
}

Expand All @@ -18,6 +19,7 @@ RhythmicCell : LilyRhythmObj {
}



heads {

^this.getHeads(struct);
Expand Down Expand Up @@ -251,4 +253,33 @@ RhythmicCell : LilyRhythmObj {
}


////////////////////////////
// Rhythmic Manipulations //
////////////////////////////


lenghtAdd { arg thisNumber;

this.lenght_(this.lenght + thisNumber)
}


lenghtMul { arg thisNumber;

this.lenght_(this.lenght * thisNumber)
}


// substitute an element:
subst { arg thisIndex, thisItem;

this.struct_(this.struct.put(thisIndex, thisItem))
}


reshapeLike { arg other;
// TODO other index operators: \foldAt \clipAt \at
this.struct_(this.struct.reshapeLike(other.struct));
}

}
51 changes: 29 additions & 22 deletions RhythmicSeq.sc
@@ -1,37 +1,40 @@

RhythmicSeq : LilyShowableObj {

var <>eventArray;

*new {arg event;
^super.new.init(event);

^super.new.init(event);
}


init { arg eventList=nil;

eventArray = Array.new;
this.put(eventList);

}

put { arg thisEvent;

case
{(thisEvent.class == RhythmicCell)}
{eventArray = eventArray.add(thisEvent)}

{ (thisEvent.isKindOf(Array)).and(thisEvent.size == 2).and(thisEvent.at(0).isKindOf(Number)) }
{ this.putArray(thisEvent.asRC) }

{ (thisEvent.isKindOf(Array)).and(thisEvent.at(0).isKindOf(Array))}
{
thisEvent.do({ arg stuffIn;
this.put(stuffIn)
});
};



{thisEvent.isKindOf(Array)}
{
thisEvent.do { |i|

case
{i.isKindOf(RhythmicCell)}
{this.put(i)}

// it must be a valid RhythmmicCell
// need more checks here
{i.isKindOf(Array)}
{this.put(RhythmicCell(i))};
}
};
}

string {
Expand All @@ -47,8 +50,12 @@ RhythmicSeq : LilyShowableObj {


musicString {

// overrides to print on a one-line staff
^("\\new RhythmicStaff {" ++ this.string ++ "\n}"
^(
"\\score { \n" ++
"\\new RhythmicStaff {" ++ this.string ++ "\n}" ++
"\n \\midi { } \n\t \\layout { }\t}"
)

}
Expand Down

0 comments on commit bc1ef52

Please sign in to comment.