Skip to content

Commit

Permalink
+ ChuckPatternSource
Browse files Browse the repository at this point in the history
  • Loading branch information
iani committed Jun 25, 2015
1 parent d180367 commit 7ca19db
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 53 deletions.
25 changes: 14 additions & 11 deletions Classes/Chuck/ChuckSource.sc
Expand Up @@ -136,8 +136,8 @@ ChuckFuncSynthSource : ChuckSynthSource {

ChuckPatternSource : ChuckSynthSource {
/* plays Event as EventPattern. See notes in file TODOs.org */
var <player;
var <bus, <group;
// var <player;
// var <bus, <group;

*new { | event, chuck |
if (chuck.source isKindOf: this) {
Expand All @@ -149,16 +149,19 @@ ChuckPatternSource : ChuckSynthSource {

makeSource {
hasNoDurControl = true;
source = EventPatternPlayer(source);
source = EventPattern(source);
}

prPlay {

}
/*
*new { | source, chuck |
^this.newCopyArgs( (source ?? { ["x", 0] }).asStream, chuck).init
makeSynth { | source, args |
/* source is an EventPattern.
Args are indispensable for bus and target!
Therefore copied to the event of EventPattern in source before playing.
new target group inside Chuck's target, new bus, and fade synth
are created each time that the pattern plays with makeSynth.
1. Alloc new bus (happens immediately).
2. Create group (is asynchronous - must use onStart to start synth after it)
3. Create fade synth (asynchronous, use onStart to start pattern after it)
4. Start playing EventPattern,
*/
}
*/

}
66 changes: 38 additions & 28 deletions Classes/Chuck/EventPattern.sc
Expand Up @@ -6,6 +6,10 @@ IZ Mon, Apr 21 2014, 09:58 EEST
EventPattern((dur: 0.1, degree: [-5, 12, 1].pbrown + [0, [-2, 3]].prand)).play;
shortcut:
(dur: 0.1, degree: [-5, 12, 2].pbrown + [0, [-2, 3]].prand).ep;
*/

EventPattern : Pattern {
Expand Down Expand Up @@ -57,16 +61,38 @@ EvtStream : Stream {
}
}

EventPatternPlayer {
/* Used as source in ChuckPatternSource.
pattern: An EventPattern.
player: an EventStreamPlayer.
group: Group for running the FadeSynth and all synths produced by the EventStreamPlayer
*/
var <pattern, <player, <group, <bus;

*new { | event |
^this.newCopyArgs(event).init;
// !!!!!!!!!!!!!!!! NOT DONE !!!!!!!!!!!!!!!!

EventPatternSynth : Synth {
classvar <defName = "*arlink1*";
var <pattern; // EventPattern: Its target is set to my group after that is started
var <player, <bus;

*initClass {
StartUp add: {
this.makeSynthDefs;
}
}

*makeSynthDefs {
SynthDef(defName, { | fadeIn = 0 out = 0 fadeTime = 0.02 |
Out.ar(out, In.ar(fadeIn) * // from GraphBuilder:makeFadeEnv:
EnvGen.kr(Env.new([fadeTime <= 0, 1, 0], #[1, 1], \lin, 1),
\gate.kr(1.0), 1.0, 0.0, fadeTime, 2));
}).add;
}

*new { | source, args |
/* create own group
allocate bus
set source's eventpattern's fadeBus and target
then send self
start playing eventpattern
doneAction is free self, group, and synths contained in group
onEnd: free bus and stop EventStreamPlayer
set source's chuck's output to newly created instance of self.
*/
}

init {
Expand All @@ -79,6 +105,7 @@ EventPatternPlayer {
// Called by ChuckPatternSource:makeSynth
// player = pattern.
thisMethod.notImplemented;
/*
^FadeSynth(FadeSynth.defName,
args ++ [fadeIn: bus.index, fadeTime: fadeTime],
target, \addToTail
Expand All @@ -88,25 +115,8 @@ EventPatternPlayer {
})
.onEnd(this, {
player.stop;
});
}
}

FadeSynth : Synth {
/* Created by EventPatternPlayer to pass as output to Chuck */
classvar <defName = "*arlink1*";
*initClass {
StartUp add: {
this.makeSynthDefs;
}
}

*makeSynthDefs {
SynthDef(defName, { | fadeIn = 0 out = 0 fadeTime = 0.02 |
Out.ar(out, In.ar(fadeIn) * // from GraphBuilder:makeFadeEnv:
EnvGen.kr(Env.new([fadeTime <= 0, 1, 0], #[1, 1], \lin, 1),
\gate.kr(1.0), 1.0, 0.0, fadeTime, 2));
}).add;
})
*/
}


Expand Down
5 changes: 5 additions & 0 deletions Classes/Chuck/plusEventEp.sc
@@ -0,0 +1,5 @@
+ Event {
ep { // shortcut for playing with EventPattern
^EventPattern (this).play
}
}
51 changes: 37 additions & 14 deletions Notes/TODOs.org
@@ -1,25 +1,48 @@
* Underway
** STARTED ChuckPatternSource
** STARTED ChuckPatternSource, EventPatternPlayer, FadeSynth
:PROPERTIES:
:DATE: <2015-06-22 Mon 00:54>
:END:

Play EventPatterns in a Chuck.

*** ChuckPatternSource
Notes:

- Plays Event as EventPattern
- The Event is stored in an EventPattern.
- The EventPattern is stored in source.
- The EventPattern is played through an EventStreamPlayer.
- The EventStreamPlayer is stored in player, and contains the EventStream that creates the Events.
- The ChuckPatternSource also creates a synth whose function is to fade the output of the entire pattern in and out at beginning and end using the Chuck's fadeTime.
- The Synth is used as Target for the EventStreamPlayer's synths, that play with addAction "addBefore" relative to it.
- It is created inside the GroupLink group of the Chuck's args.
- It is stored as the Chuck's output. When it stops,
- it also frees any synths created inside it by the pattern, and notifies the
- pattern to stop. --- or maybe not it only relies on its fade env. This simplifies things a bit.
- We still need a groupwhere everything is created in order to move everything around at once when recobfiguring the synth tree.
- Since a new patternplayer may have started in the meanwhile, the stopping must be done by connecting the fadeSynth with Notification to the EventStreamPlayer.
- The output of the EventPattern is directed to a private bus, that is the input of the fadeSynth.
- group and bus are persistent. Only the fade synth is started/stopped at each play of the chuck.
- Chuck's args specify in and out bus and target. Therefore they are copied to the event of EventPattern in source before playing.
- However, the Events generated by the EventPattern must play through a separate group, that is create inside the target group, and that serves to move those synths when the whole chuck needs to move to another group (target) because of linking I/O. Therefore, the target of the event of the Event of the EventPattern must be replaced by that group before the EventPattern starts playing.
- The makeSynth function of ChuckEventPattern creates an EventPatternSynth, a subclass of Synth, which creates its own group inside the target group, and overloads method =moveToTail= to move its own group to the tail of the target instead of itself. The details of EventPatternSynth are explained below.

*** EventPatternSynth
:PROPERTIES:
:DATE: <2015-06-25 Thu 00:55>
:END:


Subclass of Synth
1. uses its own SynthDef, which copies signal from input to output wrapping it in a fade-envelope.
2. Overloads =moveToTail= so that instead of moving itself to the tail of the target, it moves the group that it is contained in to the tail of the target. This is because it runs in a group created by EventPatternPlayer, which is used as target group for all synths created for the target. The purpose of the group is to enable moving all synths of the pattern to a different group when the player is moved to a different part of the node tree for linking I/O.
3. on creation, does the following:
1. Alloc new bus (happens immediately).
2. Create group inside (tail) of target group (is asynchronous, must use onStart to start synth after it).
3. Set the EventPattern's target to the newly created group.
4. Create self as fade synth (asynchronous, use onStart to start pattern after it)
5. Fade synth's doneAction frees group and all synths inside the group.
6. Fade synths's onEnd notifies ChuckPatternSource to stop playing EventPattern.
7. Start playing EventPattern.

Implementation notes for =new= method:

1. create own group
2. allocate bus
3. set source's eventpattern's fadeBus and target
4. then send self
5. start playing eventpattern
6. doneAction is free self, group, and synths contained in group
7. onEnd: free bus and stop EventStreamPlayer
8. set source's chuck's output to newly created instance of self.

** STARTED MiniSteno

Expand Down

0 comments on commit 7ca19db

Please sign in to comment.