Skip to content

Commit

Permalink
added subst method for Array
Browse files Browse the repository at this point in the history
  • Loading branch information
smoge committed Mar 14, 2011
1 parent 6778d55 commit a0c0b37
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 15 deletions.
74 changes: 68 additions & 6 deletions Array-ext.sc
@@ -1,26 +1,87 @@
+ Array {


/*
method for substitution of a
Number with a Structure
inside a Structure:
a = [3, 2, 1, 2, 1]
a.subst(3, [2, 1, 2]) // ==> [ 3, 2, 1, [ 2, [ 2, 1, 2 ] ], 1 ]
This actually is a subdivision of a element in our score representation
*/

subst { arg index, thisStruct;

case
{thisStruct.isKindOf(Array)}
{^this.put(index, [this.at(index), thisStruct])}

{thisStruct.isKindOf(Number)}
{^this.put(index, thisStruct)};
}


gdc {

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


asRC {


max {

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


min {

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


minSize {

^(this.collect {|i| i.size}).min
}


maxSize {

^(this.collect {|i| i.size}).max
}


asRhythmicCell {
^RhythmicCell(this)
}


asRC {
^RhythmicCell(this)
}


asRhythmicSeq {

^RhythmicSeq(this)
}


asRS {

^RhythmicSeq(this)
}


addRC { arg thisRSeq;

thisRSeq.put(this)
Expand All @@ -33,5 +94,6 @@
thisRSeq.put(i)
};
}



}
35 changes: 34 additions & 1 deletion LilyRhythm.scd
Expand Up @@ -39,6 +39,8 @@ Post << f.([1,2,3,4], 5, 8)



x.edit

a = [
[3, [1, [2, [1, 1, [1, [1, 1, 1]], 1, 1, 1]], 1, 4, 2]],
[4, [2, [2, [1, 1, 1, 1, 1, 1]], 1, 4, 2]],
Expand All @@ -50,8 +52,39 @@ a = [
[4, [4, [2, [1, 1, 1, 1, 1, 1, 1]], 2, 4, 1]]
];

a.asRS.plot
a.scramble.asRS

[[1, 2, 3, 4], [[9, 1, 2], [8, 2, 3], [7, 4, 3]]].flop
Help.gui


x = RhythmicGroup2();
x.putMeasure([2, 4, 3, 2, 3, 4, 2]);
x.putStruct([[2, 1, 3, 2, 1], [1, 2, 1, 3, 2], [2, 1, 3, 2, 1, 2, 3, 2], [2, 1, 2, 3, 1]]);
x.voiceArray

x.structMatrix
[
[2, 4, 3, 2, 3, 4, 2],
[[2, 1, 3, 2, 1], [1, 2, 1, 3, 2], [2, 1, 3, 2, 1, 2, 3, 2], [2, 1, 2, 3, 1]]
].flop


x.voice
x.plot


x.edit
x.voiceArray

x.structArray
x.measureArray
x.string

(a.scramble.asRS)
x.put(a.scramble.asRS)

x.plot


a = [[10,20],[30, 40, 50], 60, 70, [80, 90, 100]];
Expand Down
13 changes: 7 additions & 6 deletions RhythmicGroup.sc
Expand Up @@ -33,7 +33,13 @@ RhythmicGroup : LilyShowableObj {
putArray { arg thisArray;

thisArray.do { |i|
this.put(i)

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

{i.isKIndOf(Array)}
{this.put(i.asRS)};
}
}

Expand All @@ -45,7 +51,6 @@ RhythmicGroup : LilyShowableObj {
this.voiceArray.do { |i|
outString = outString ++ i.staffString
};

^outString
}

Expand All @@ -55,13 +60,9 @@ RhythmicGroup : LilyShowableObj {
var outString = String.new;

outString = outString ++ "\\score {\n\t<<\n\t\t";

outString = outString ++ this.string;

// outString = outString ++ "\n \\midi { } \n\t \\layout { }\n";

outString = outString ++ "\n >> \n}\n\n";

^outString

}
Expand Down
4 changes: 2 additions & 2 deletions RhythmicSystem.sc
@@ -1,7 +1,7 @@
/*
# Init #
"Ctk".include
a = RhythmicSystem([2, 3, 4]) // <--- Init with measures
a.putMeasure([2, 3, 2]) // <---you can add more later
Expand Down Expand Up @@ -70,7 +70,7 @@ RhythmicSystem : LilyShowableObj {


///////////////////////////////////////////
// Manipulations an measures and struct //
// Manipulations on measures and struct //
///////////////////////////////////////////

scrambleMeasures {
Expand Down

0 comments on commit a0c0b37

Please sign in to comment.