FoscSelection

Returns a FoscSelection.


Description

Selection of items (components / or other selections).


Attributes Summary

Instance Properties

items

Instance Methods: Special Methods

== Is true when selection and expr are of the same type and when items of selection equals items of expr. Otherwise false.
!= Is true when selection does not equal expr. Otherwise false.
++ Concatenates object to selection.
asCompileString
storeArgs

Instance Methods

any
areContiguousLogicalVoice Is true when items in selection are contiguous components in the same logical voice.
areContiguousSameParent Is true when items in selection are all contiguous components in the same parent.
areLeaves Is true when items in selection are all leaves.
areLogicalVoice Is true when items in selection are all components in the same logical voice.
at Gets item identified by index.
atAll Gets items identified by indices.
collect Collects components by predicate function.
components Select components.
copySeries Gets slice of items identified by indices.
do Iterates over items in selection.
doAdjacentPairs Iterates over adjacent pairs of items in selection.
every
first Gets first items in selection.
flat
format
groupBy (synonymous with separate)
groupByContiguity Group items in selection by contiguity.
groupByPitch Group items in selection by pitch.
groupByPitched Group items in selection by pitched and non-pitched leaves.
hash TODO: not yet implemented
illustrate Attempts to illustrate selection. The illustration will usually work for simple selections that represent a contiguous snippet of a single voice of items.
includes (abjad: contains)
indexOf
insert
isEmpty
last Gets last item in selection.
lastIndex
leafAt
leaves Selects leaves.
logicalTies Selects logical ties.
notEmpty
reverseDo Iterates over all components in selection in reverse.
partitionByDurations Partitions selection by durations.
partitionByRatio
partitionBySizes TODO: overhang argument rather than isCyclic
put
remove
removeAt
reverseDo Reverse-iterates over items in selection.
runs Select runs.
separate Groups components by predicate function.
size Gets number of components in selection.
timespan Gets timespan of contiguous selection.
tuplets Select tuplets.

Instance Methods: Display

isPlaying
pause
play
resume
stop


Usage

  1. Example

    m = [FoscNote(60, 1/4), FoscNote(62, 1/4)];
    a = FoscSelection(m);
    a.items;
    [ FoscNote(FoscPitch("C4"), FoscDuration(1, 4)), FoscNote(FoscPitch("D4"), FoscDuration(1, 4)) ]
  2. Example

    FoscSelection.dumpInterface
    FoscSelection


Instance Properties


items

  1. Example

    a = FoscSelection([FoscRest(1/4), FoscNote(60, 1/4), FoscNote(62, 1/4)]);
    a.items;
    [ FoscRest(FoscDuration(1, 4)), FoscNote(FoscPitch("C4"), FoscDuration(1, 4)), FoscNote(FoscPitch("D4"), FoscDuration(1, 4)) ]


Instance Methods: Special Methods


==

Is true when selection and expr are of the same type and when items of selection equals items of expr. Otherwise false.

Returns true or false.

  1. Example

    a = FoscSelection([FoscNote(60, 1/4), FoscNote(62, 1/4)]);
    b = FoscSelection(a.items.copy);
    c = FoscSelection([FoscNote(64, 1/4)]);
    
    a == b;
    true
    a == c;
    false


!=

Is true when selection does not equal expr. Otherwise false.

Returns true or false.

  1. Example

    a = FoscSelection([FoscNote(60, 1/4), FoscNote(62, 1/4)]);
    b = FoscSelection(a.items.copy);
    c = FoscSelection([FoscNote(64, 1/4)]);
    
    a != b;
    false
    a != c;
    true


++

Concatenates object to selection.

Returns new selection.

  1. Example

    a = FoscSelection([FoscNote(60, 1/4), FoscNote(62, 1/4)]);
    b = FoscSelection([FoscNote(64, 1/4)]);
    c = a ++ b;
    c.items.collect { |each| each.str };
    [ "c'4", "d'4", "e'4" ]


asCompileString

  1. Example

    a = FoscSelection([FoscNote(60, 1/4), FoscNote(62, 1/4)]);
    a.cs;
    FoscSelection([ FoscNote(FoscPitch("C4"), FoscDuration(1, 4)), FoscNote(FoscPitch("D4"), FoscDuration(1, 4)) ])


storeArgs


Instance Methods


any

  1. Example

    a = FoscSelection([FoscNote(60, 1/4), FoscChord(#[60,66,67], 1/4)]);
    a.any { |item| item.isKindOf(FoscNote) };
    true
    a.any { |item| item.isKindOf(FoscChord) };
    true
    a.any { |item| item.isKindOf(FoscRest) };
    false


areContiguousLogicalVoice

Is true when items in selection are contiguous components in the same logical voice.

code:: a = FoscStaff(FoscLeafMaker().(#[60,62,64,65], [1/4])); a[0..].areContiguousLogicalVoice;

code:: b = FoscSelection([a.leafAt(1), a.leafAt(3)]); b[0..].areContiguousLogicalVoice;


areContiguousSameParent

Is true when items in selection are all contiguous components in the same parent.

  1. Example

    a = FoscStaff(FoscLeafMaker().(#[60,62,64,65], [1/4]));
    a[0..].areContiguousSameParent;
    true
    b = FoscSelection([a.leafAt(1), a.leafAt(3)]);
    b[0..].areContiguousSameParent;
    false


areLeaves

Is true when items in selection are all leaves.

  1. Example

    a = FoscStaff(FoscLeafMaker().(#[60,62,64,65], [1/4]));
    a[0..].areLeaves;
    true


areLogicalVoice

Is true when items in selection are all components in the same logical voice.

  1. Example

    a = FoscStaff(FoscLeafMaker().(#[60,62,64,65], [1/4]));
    a[0..].areLogicalVoice;
    true
    b = FoscSelection([a.leafAt(1), a.leafAt(3)]);
    b[0..].areLogicalVoice;
    true


at

Gets item identified by index.

Returns component from selection.

  1. Example

    a = FoscSelection([FoscNote(60, 1/4), FoscNote(62, 1/4)]);
    a[1].str;
    d'4


atAll

Gets items identified by indices.

Returns components from selection.

  1. Example

    a = FoscSelection([FoscNote(60, 1/4), FoscNote(62, 1/4), FoscNote(64, 1/4)]);
    a.atAll(#[0,2]).collect { |each| each.str };
    [ "c'4", "e'4" ]


collect

Collects components by predicate function.

Returns a new selection.

code:: a = FoscLeafMaker().(#[60, 61, 62, 63, 64], [1/8]); b = a.collect { |each| each.writtenPitch_(each.writtenPitch + 12) }; b.items.collect { |each| each.writtenPitch.pitchNumber };


components

Select components.

Return new selection.

  1. All components

    a = FoscStaff([FoscRest(1/4), FoscNote(60, 1/4), FoscNote(62, 1/4)]);
    b = FoscSelection(a).components;
    b.items.collect { |each| each.str };
    [ "\\new Staff {
        r4
        c'4
        d'4
    }", "r4", "c'4", "d'4" ]
  2. Notes

    a = FoscStaff([FoscRest(1/4), FoscNote(60, 1/4), FoscNote(62, 1/4)]);
    b = FoscSelection(a).components(prototype: FoscNote);
    b.items.collect { |each| each.str };
    [ "c'4", "d'4" ]
  3. Notes and rests

    a = FoscStaff([FoscRest(1/4), FoscNote(60, 1/4), FoscNote(62, 1/4)]);
    b = FoscSelection(a).components(prototype: [FoscNote, FoscRest]);
    b.items.collect { |each| each.str };
    [ "r4", "c'4", "d'4" ]
  4. Notes and rests in reverse order

    a = FoscStaff([FoscRest(1/4), FoscNote(60, 1/4), FoscNote(62, 1/4)]);
    b = FoscSelection(a).components(prototype: [FoscNote, FoscRest], reverse: true);
    b.items.collect { |each| each.str };
    [ "d'4", "c'4", "r4" ]


copySeries

Gets slice of items identified by indices.

Returns a new selection.

  1. Example

    a = FoscSelection([FoscNote(60, 1/4), FoscNote(62, 1/4), FoscNote(64, 1/4)]);
    b = a[1..];
    b.items.collect { |each| each.str };
    [ "d'4", "e'4" ]


do

Iterates over items in selection.

  1. Example

    a = FoscLeafMaker().(#[60,60,62,64,65,65], [1/4,1/24,1/12,1/8,1/4,1/4]);
    a.show;

  2. Does not recurse into containers:

    FoscSelection(a).do { |each| each.postln };
    FoscSelection([ FoscNote(FoscPitch("C4"), FoscDuration(1, 4)), FoscTuplet(FoscMultiplier(2, 3), [  ]), FoscNote(FoscPitch("E4"), FoscDuration(1, 8)), FoscNote(FoscPitch("F4"), FoscDuration(1, 4)), FoscNote(FoscPitch("F4"), FoscDuration(1, 4)) ])
  3. Recurses into containers:

    FoscSelection(a).do({ |each| each.postln }, recurse: true);
    FoscSelection([ FoscNote(FoscPitch("C4"), FoscDuration(1, 4)), FoscTuplet(FoscMultiplier(2, 3), [  ]), FoscNote(FoscPitch("E4"), FoscDuration(1, 8)), FoscNote(FoscPitch("F4"), FoscDuration(1, 4)), FoscNote(FoscPitch("F4"), FoscDuration(1, 4)) ])


doAdjacentPairs

Iterates over adjacent pairs of items in selection.

  1. Example

    a = FoscSelection([FoscNote(60, 1/4), FoscNote(62, 1/4), FoscNote(64, 1/4)]);
    a.doAdjacentPairs { |a, b| [a.str, b.str].postln };
    FoscSelection([ FoscNote(FoscPitch("C4"), FoscDuration(1, 4)), FoscNote(FoscPitch("D4"), FoscDuration(1, 4)), FoscNote(FoscPitch("E4"), FoscDuration(1, 4)) ])


every

  1. Example

    a = FoscSelection([FoscNote(60, 1/4), FoscNote(62, 1/4)]);
    a.every { |item| item.isKindOf(FoscNote) };
    true
    a = FoscSelection([FoscNote(60, 1/4), FoscChord(#[60,66,67], 1/4)]);
    a.every { |item| item.isKindOf(FoscNote) };
    false


first

Gets first items in selection.

Returns component.

  1. Example

    a = FoscSelection([FoscNote(60, 1/4), FoscNote(62, 1/4), FoscNote(64, 1/4)]);
    a.first.str;
    c'4


flat

  1. Example

    a = FoscSelection([FoscNote(60, 1/4), FoscNote(62, 1/4)]);
    b = FoscSelection([FoscRest(1/4), FoscChord(#[60,66,67], 1/4)]);
    c = FoscSelection([a, b]);
    c.items;
    [ FoscSelection([ FoscNote(FoscPitch("C4"), FoscDuration(1, 4)), FoscNote(FoscPitch("D4"), FoscDuration(1, 4)) ]), FoscSelection([ FoscRest(FoscDuration(1, 4)), FoscChord(FoscPitchSegment([ FoscPitch("C4"), FoscPitch("F#4"), FoscPitch("G4") ]), FoscDuration(1, 4)) ]) ]
    d = c.flat;
    d.items;
    [ FoscNote(FoscPitch("C4"), FoscDuration(1, 4)), FoscNote(FoscPitch("D4"), FoscDuration(1, 4)), FoscRest(FoscDuration(1, 4)), FoscChord(FoscPitchSegment([ FoscPitch("C4"), FoscPitch("F#4"), FoscPitch("G4") ]), FoscDuration(1, 4)) ]


format


groupBy

(synonymous with separate)

Groups components by predicate function.

Returns a selection of selections.

  1. Example

    a = FoscLeafMaker().(#[nil, 60, 61, nil, 62, 63, 64], [1/8]);
    b = a.leaves.groupBy { |a, b| a.isPitched != b.isPitched };
    b.items.collect { |each| each.items };
    [ [ FoscRest(FoscDuration(1, 8)) ], [ FoscNote(FoscPitch("C4"), FoscDuration(1, 8)), FoscNote(FoscPitch("C#4"), FoscDuration(1, 8)) ], [ FoscRest(FoscDuration(1, 8)) ], [ FoscNote(FoscPitch("D4"), FoscDuration(1, 8)), FoscNote(FoscPitch("Eb4"), FoscDuration(1, 8)), FoscNote(FoscPitch("E4"), FoscDuration(1, 8)) ] ]


groupByContiguity

Group items in selection by contiguity.

  1. Example

    a = FoscStaff(FoscLeafMaker().(#[60,60,62,nil,64,64], [1/4,1/24,1/12,1/8,1/4,1/4]));
    m = a.selectLeaves;
    tie(m[0..1]);
    tie(m[4..]);
    a.show;

  2. Group pitched leaves by contiguity.

    m = a.selectLeaves(pitched: true);
    m = m.groupByContiguity;
    m.items.collect { |each| each.items.collect { |item| item.str } };
    [ [ "c'4", "c'16", "d'8" ], [ "e'4", "e'4" ] ]
    a.consistsCommands.add('Horizontal_bracket_engraver');
    t = #[['bracket-flare', [0,0]], ['direction', 'up'], ['staff-padding', 3]];
    m.do { |each| each.horizontalBracket(tweaks: t) };
    a.show;


groupByPitch

Group items in selection by pitch.

  1. Example

    a = FoscStaff(FoscLeafMaker().(#[60,[60,64,67],62,62,62,nil,[65,69],[65,69]], [1/8]));
    m = a.selectLeaves;
    m[2..3].tie;
    m = a.selectLogicalTies.groupByPitch;
    m.items.do { |each| each.items.collect { |item| item.str }.postln };
    a.show;


groupByPitched

Group items in selection by pitched and non-pitched leaves.

  1. Example

    a = FoscStaff(FoscLeafMaker().(#[60,[60,64,67],62,62,62,nil,[65,69],[65,69]], [1/8]));
    m = a.selectLeaves;
    m[2..3].tie;
    m = a.selectLogicalTies.groupByPitched;
    m.items.do { |each| each.items.collect { |item| item.str }.postln };
    a.show;
    prFormatCodeString interpret initial failed: a DoesNotUnderstandError
    
        a = FoscStaff(FoscLeafMaker().(#[60,[60,64,67],62,62,62,nil,[65,69],[65,69]], [1/8]));
        m = a.selectLeaves;
        m[2..3].tie;
        m = a.selectLogicalTies.groupByPitched;
        m.items.do { |each| each.items.collect { |item| item.str }.postln };
    


hash

TODO: not yet implemented


illustrate

Attempts to illustrate selection. The illustration will usually work for simple selections that represent a contiguous snippet of a single voice of items.

Returns LilyPond file.

  1. Regular staff

    a = FoscLeafMaker().(#[60,62,64,65,67,69,71,72], [1/8]);
    a.show;

  2. RhythmicStaff if all pitches = middle-c

    a = FoscLeafMaker().(60 ! 8, [1/8]);
    a.show;


includes

(abjad: contains)

Is true when expr is in selection. Otherwise false.

Returns true or false.

  1. Example

    x = FoscNote(60, 1/4);
    y = FoscNote(62, 1/4);
    a = FoscSelection([x]);
    a.includes(x);
    true
    a.includes(y);
    false


indexOf

  1. Example

    x = FoscNote(60, 1/4);
    y = FoscNote(62, 1/4);
    a = FoscSelection([x, y]);
    a.indexOf(x);
    0
    a.indexOf(y);
    1


insert

  1. Example

    a = FoscSelection([FoscNote(60, 1/4), FoscNote(62, 1/4)]);
    a.items.collect { |each| each.str };
    [ "c'4", "d'4" ]
    a.insert(1, FoscNote(72, 1/4));
    a.items.collect { |each| each.str };
    [ "c'4", "c''4", "d'4" ]


isEmpty

  1. Example

    a = FoscSelection([FoscNote(60, 1/4), FoscNote(62, 1/4)]);
    a.isEmpty;
    false
    a = FoscSelection([]);
    a.isEmpty;
    true


last

Gets last item in selection.

Returns component.

  1. Example

    a = FoscSelection([FoscNote(60, 1/4), FoscNote(62, 1/4), FoscNote(64, 1/4)]);
    a.last.str;
    e'4


lastIndex

  1. Example

    a = FoscSelection([FoscNote(60, 1/4), FoscNote(62, 1/4)]);
    a.lastIndex;
    1


leafAt

  1. Example

    a = FoscSelection([FoscNote(60, 1/4), FoscNote(62, 1/4)]);
    a.leafAt(1).str;
    d'4
    a = FoscSelection([FoscRest(1/4), FoscNote(60, 1/4), FoscNote(62, 1/4)]);
    a.leafAt(0, pitched: true).str;
    c'4


leaves

Selects leaves.

Returns new selection.

  1. All leaves

    a = FoscStaff([FoscRest(1/4), FoscNote(60, 1/4), FoscNote(62, 1/4)]);
    b = FoscSelection(a).leaves;
    b.items.collect { |each| each.str };
    [ "r4", "c'4", "d'4" ]
  2. Pitched leaves

    a = FoscStaff([FoscRest(1/4), FoscNote(60, 1/4), FoscNote(62, 1/4)]);
    b = FoscSelection(a).leaves(pitched: true);
    b.items.collect { |each| each.str };
    [ "c'4", "d'4" ]
  3. Non-pitched leaves

    a = FoscStaff([FoscRest(1/4), FoscNote(60, 1/4), FoscNote(62, 1/4)]);
    b = FoscSelection(a).leaves(pitched: false);
    b.items.collect { |each| each.str };
    [ "r4" ]
  4. Leaves in reverse order

    a = FoscStaff([FoscRest(1/4), FoscNote(60, 1/4), FoscNote(62, 1/4)]);
    b = FoscSelection(a).leaves(reverse: true);
    b.items.collect { |each| each.str };
    [ "d'4", "c'4", "r4" ]


logicalTies

Selects logical ties.

Returns new selection.

  1. Example

    a = FoscStaff(FoscLeafMaker().(#[60,60,62,nil,64,64], [1/4,1/24,1/12,1/8,1/4,1/4]));
    m = a.selectLeaves;
    tie(m[0..1]);
    tie(m[4..]);
    a.show;

  2. Select all logicalTies

    b = FoscSelection(a).logicalTies;
    b.items.collect { |each| each.items.collect { |each| each.cs } };
    [ [ "FoscNote('C4', 1/4)", "FoscNote('C4', 1/16)" ], [ "FoscNote('D4', 1/8)" ], [ "FoscRest(1/8)" ], [ "FoscNote('E4', 1/4)", "FoscNote('E4', 1/4)" ] ]
  3. Select pitched logicalTies

    b = FoscSelection(a).logicalTies(pitched: true);
    b.items.collect { |each| each.items { |each| each.cs } };
    [ [ FoscNote(FoscPitch("C4"), FoscDuration(1, 4)), FoscNote(FoscPitch("C4"), FoscDuration(1, 16)) ], [ FoscNote(FoscPitch("D4"), FoscDuration(1, 8)) ], [ FoscNote(FoscPitch("E4"), FoscDuration(1, 4)), FoscNote(FoscPitch("E4"), FoscDuration(1, 4)) ] ]
  4. Select non-pitched logicalTies

    b = FoscSelection(a).logicalTies(pitched: false);
    b.items.collect { |each| each.items.collect { |each| each.cs } };
    [ [ "FoscRest(1/8)" ] ]
  5. Select nontrivial logicalTies

    b = FoscSelection(a).logicalTies(nontrivial: true);
    b.items.collect { |each| each.items.collect { |each| each.cs } };
    [ [ "FoscNote('C4', 1/4)", "FoscNote('C4', 1/16)" ], [ "FoscNote('E4', 1/4)", "FoscNote('E4', 1/4)" ] ]
  6. Select trivial logicalTies

    b = FoscSelection(a).logicalTies(nontrivial: false);
    b.items.collect { |each| each.items.collect { |each| each.cs } };
    [ [ "FoscNote('D4', 1/8)" ], [ "FoscRest(1/8)" ] ]
  7. Select logicalTies in reverse order

    b = FoscSelection(a).logicalTies(reverse: true);
    b.items.collect { |each| each.items.collect { |each| each.cs } };
    [ [ "FoscNote('E4', 1/4)", "FoscNote('E4', 1/4)" ], [ "FoscRest(1/8)" ], [ "FoscNote('D4', 1/8)" ], [ "FoscNote('C4', 1/4)", "FoscNote('C4', 1/16)" ] ]


notEmpty

  1. Example

    a = FoscSelection([FoscNote(60, 1/4), FoscNote(62, 1/4)]);
    a.notEmpty;
    true
    a = FoscSelection([]);
    a.notEmpty;
    false


reverseDo

Iterates over all components in selection in reverse.

  1. Example

    a = FoscSelection([FoscNote(60, 1/4), FoscNote(62, 1/4)]);
    a.reverseDo { |each| each.str.postln };
    FoscSelection([ FoscNote(FoscPitch("C4"), FoscDuration(1, 4)), FoscNote(FoscPitch("D4"), FoscDuration(1, 4)) ])


partitionByDurations

Partitions selection by durations.

Parts must equal durations exactly when fill is exact.

Parts must be less than or equal to durations when fill is less.

Parts must be greater or equal to durations when fill is more.

Reads durations cyclically when isCylic is true.

Reads component durations in seconds when inSeconds is true.

Returns remaining components at end in final part when overhang is true.

Returns array of selections.

  1. Cyclically partitions leaves into parts equal to exactly 3/8, with overhang returned at end.

    a = FoscStaff(FoscLeafMaker().(#[60,62,64,65,67,69,71,72], [1/8]));
    b = a[0..].partitionByDurations([3/8], isCyclic: true, overhang: true);
    b.do { |sel| sel.items.collect { |each| each.str }.postln };
    b.do { |sel| if (sel.size > 1) { sel.slur } };
    a.show;

  2. Partitions leaves into one part equal to exactly 3/8, truncating overhang.

    a = FoscStaff(FoscLeafMaker().(#[60,62,64,65,67,69,71,72], [1/8]));
    b = a[0..].partitionByDurations([3/8], isCyclic: false, overhang: false);
    b.do { |sel| sel.items.collect { |each| each.str }.postln };
    b.do { |sel| if (sel.size > 1) { sel.slur } };
    a.show;

  3. Cyclically partitions leaves into parts equal to (or just less than) 3/16 and 1/16, with overhang returned at end.

    a = FoscStaff(FoscLeafMaker().(#[60,62,64,65,67,69,71,72], [1/8]));
    b = a[0..].partitionByDurations([3/16,1/16], isCyclic: true, fill: 'more', overhang: true);
    b.do { |sel| sel.items.collect { |each| each.str }.postln };
    b.do { |sel| if (sel.size > 1) { sel.slur } };
    a.show;

  4. Cyclically partitions leaves into parts equal to (or just less than) 3/16, truncating overhang.

    a = FoscStaff(FoscLeafMaker().(#[60,62,64,65,67,69,71,72], [1/8]));
    b = a[0..].partitionByDurations([3/16], isCyclic: true, fill: 'less', overhang: false);
    b.do { |sel| sel.items.collect { |each| each.str }.postln };
    b.do { |sel| if (sel.size > 1) { sel.slur } };
    a.show;

  5. Partitions leaves into a single part equal to (or just less than) 3/16, truncating overhang.

    a = FoscStaff(FoscLeafMaker().(#[60,62,64,65,67,69,71,72], [1/8]));
    b = a[0..].partitionByDurations([3/16], isCyclic: false, fill: 'less', overhang: false);
    b.do { |sel| sel.items.collect { |each| each.str }.postln };
    b.do { |sel| if (sel.size > 1) { sel.slur } };
    a.show;

  6. Cyclically partitions exactly 1.5 seconds at a time.

  7. Cyclically partitions exactly 1.5 seconds at a time with overhang returned at end.

  8. Partitions exactly 1.5 seconds one time.

  9. Cyclically partitions 0.75 seconds with part durations allowed to be just less than 0.75 seconds.

  10. Partitions 0.75 seconds just once with part duration allowed to be just less than 0.75 seconds.


partitionByRatio

  1. Example

    a = FoscStaff(FoscLeafMaker().(#[60,62,64,65,67,69,71,72], [1/8,1/8,1/8,1/8]));
    b = a[0..].partitionByRatio(#[5, 11, 4]);
    b.do { |sel| sel.items.collect { |each| each.str }.postln };
    b.do { |sel| if (sel.size > 1) { sel.slur } };
    b.items.postln;
    a.show;


partitionBySizes

TODO: overhang argument rather than isCyclic

  1. Example

    a = FoscLeafMaker().((60..72), [1/8]);
    a = a.partitionBySizes([2,3,5,2,1]);
    a.do { |each| if (each.size > 1) { each.attach(FoscSlur('below')) } };
    a.show;

  2. Example

    a = FoscLeafMaker().((60..72), [1/8]);
    a = a.partitionBySizes([2,3], isCyclic: true);
    a.do { |each| if (each.size > 1) { each.attach(FoscSlur('below')) } };
    a.show;


put

  1. Example

    a = FoscSelection([FoscNote(60, 1/4), FoscNote(62, 1/4)]);
    a.items.collect { |each| each.str };
    [ "c'4", "d'4" ]
  2. Example

    a.put(1, FoscNote(72, 1/4));
    a.items.collect { |each| each.str };
    [ "c'4", "c''4" ]


remove

  1. Example

    x = FoscNote(60, 1/4);
    y = FoscNote(62, 1/4);
    a = FoscSelection([x, y]);
    a.items.collect { |each| each.str };
    [ "c'4", "d'4" ]
    a.remove(x);
    a.items.collect { |each| each.str };
    [ "d'4" ]


removeAt

  1. Example

    x = FoscNote(60, 1/4);
    y = FoscNote(62, 1/4);
    a = FoscSelection([x, y]);
    a.items.collect { |each| each.str };
    [ "c'4", "d'4" ]
    a.removeAt(0);
    a.items.collect { |each| each.str };
    [ "d'4" ]


reverseDo

Reverse-iterates over items in selection.

  1. Example

    a = FoscLeafMaker().(#[60,60,62,64,65,65], [1/4,1/24,1/12,1/8,1/4,1/4]);
    a.show;

  2. Does not recurse into containers:

    FoscSelection(a).reverseDo { |each| each.postln };
    FoscSelection([ FoscNote(FoscPitch("C4"), FoscDuration(1, 4)), FoscTuplet(FoscMultiplier(2, 3), [  ]), FoscNote(FoscPitch("E4"), FoscDuration(1, 8)), FoscNote(FoscPitch("F4"), FoscDuration(1, 4)), FoscNote(FoscPitch("F4"), FoscDuration(1, 4)) ])
  3. Recurses into containers:

    FoscSelection(a).reverseDo({ |each| each.postln }, recurse: true);
    FoscSelection([ FoscNote(FoscPitch("C4"), FoscDuration(1, 4)), FoscTuplet(FoscMultiplier(2, 3), [  ]), FoscNote(FoscPitch("E4"), FoscDuration(1, 8)), FoscNote(FoscPitch("F4"), FoscDuration(1, 4)), FoscNote(FoscPitch("F4"), FoscDuration(1, 4)) ])


runs

Select runs.

  1. Attach horizontal bracket to each run.

    a = FoscStaff(FoscLeafMaker().(#[60,60,62,nil,64,64], [1/4,1/24,1/12,1/8,1/4,1/4]));
    a.consistsCommands.add('Horizontal_bracket_engraver');
    m = a.selectLeaves;
    tie(m[0..1]);
    tie(m[4..]);
    m.runs.do { |each| each.horizontalBracket(tweaks: #[['direction', 'up']]) };
    a.show;


separate

Groups components by predicate function.

Returns a selection of selections.

  1. Example

    a = FoscLeafMaker().(#[nil, 60, 61, nil, 62, 63, 64], [1/8]);
    b = a.leaves.separate { |a, b| a.isPitched != b.isPitched };
    b.items.collect { |each| each.items };
    [ [ FoscRest(FoscDuration(1, 8)) ], [ FoscNote(FoscPitch("C4"), FoscDuration(1, 8)), FoscNote(FoscPitch("C#4"), FoscDuration(1, 8)) ], [ FoscRest(FoscDuration(1, 8)) ], [ FoscNote(FoscPitch("D4"), FoscDuration(1, 8)), FoscNote(FoscPitch("Eb4"), FoscDuration(1, 8)), FoscNote(FoscPitch("E4"), FoscDuration(1, 8)) ] ]


size

Gets number of components in selection.

Returns integer.

  1. Example

    a = FoscSelection([FoscNote(60, 1/4), FoscNote(62, 1/4)]);
    a.size;
    2


timespan

Gets timespan of contiguous selection.

Returns timespan.

  1. FIXME ERROR: Message prGetTimespan not understood

    a = FoscVoice({ FoscNote(60, [1, 8]) } ! 8);
    b = a.select.byLeaf[1..6];
    b.timespan;
    [b.timespan.startOffset.pair, b.timespan.stopOffset.pair].postln;
    FoscTimespan.superclass.dumpInterface;
    a = FoscMeasure([4, 4], [FoscNote(60, [1, 32]), FoscNote(62, [7, 8]), FoscNote(62, [1, 16]), FoscNote(64, [1, 32])]);
    a[1..2].attach(FoscTie());
    x = FoscStaff([FoscMeasure([2, 4], [FoscNote(60, [2, 4])]), a]);
    m = FoscMeterManager.iterateRewriteInputs(a).all;
    m.do { |logicalTie|
        t = logicalTie.timespan;
        [t.startOffset.pair, t.stopOffset.pair].postln
    };
    // lost when measure is added to staff
    a[0].prGetTimespan.startOffset.pair;
    a[1].prGetTimespan.startOffset.pair;
    a[2].prGetTimespan.startOffset.pair;
    a[0].timespan.startOffset.pair;
    a[1].timespan.startOffset.pair;
    a[2].timespan.startOffset.pair;


tuplets

Select tuplets.

  1. Attach horizontal bracket to each tuplet.

    a = FoscStaff(FoscLeafMaker().(#[60,60,62,nil,64,64], [1/4,1/24,1/12,1/8,1/4,1/4]));
    a.consistsCommands.add('Horizontal_bracket_engraver');
    m = a.selectLeaves;
    tie(m[0..1]);
    tie(m[4..]);
    FoscSelection(a).tuplets.items.collect { |each| each.str };
    [ "\\times 2/3 {
        c'16
        d'8
    }" ]


Instance Methods: Display


isPlaying

  1. Example

    a = FoscLeafMaker().(#[60,62,nil].wrapExtend(12), [3/8,1/8,5/16,1/16]);
    a.play;
    a.isPlaying;
    true
    a.stop;
    a.isPlaying;
    false


pause

  1. Example

    a = FoscLeafMaker().(#[60,62,nil].wrapExtend(12), [3/8,1/8,5/16,1/16]);
    a.play;
    a.pause;
    a.resume;


play

  1. Example

    a = FoscLeafMaker().(#[60,62,nil].wrapExtend(12), [3/8,1/8,5/16,1/16]);
    a.play;
    a.stop;


resume

  1. Example

    a = FoscLeafMaker().(#[60,62,nil].wrapExtend(12), [3/8,1/8,5/16,1/16]);
    a.play;
    a.pause;
    a.resume;


stop

  1. Example

    a = FoscLeafMaker().(#[60,62,nil].wrapExtend(12), [3/8,1/8,5/16,1/16]);
    a.play;
    a.stop;