This commit is contained in:
Felix Roos 2022-03-24 19:46:38 +01:00
parent 6d02f4c264
commit b3c853ee26
7 changed files with 72 additions and 19 deletions

View File

@ -463,6 +463,9 @@ class Pattern {
const binary_pat = sequence(binary_pats);
return binary_pat.fmap((b) => (val) => b ? val : void 0).appRight(this)._removeUndefineds();
}
_color(color) {
return this._withContext((context) => ({...context, color}));
}
_segment(rate) {
return this.struct(pure(true).fast(rate));
}
@ -536,6 +539,12 @@ class Pattern {
stut(times, feedback, time) {
return this.stutWith(times, time, (pat, i) => pat.velocity(Math.pow(feedback, i)));
}
echoWith(times, time, func) {
return stack(...range(0, times - 1).map((i) => func(this.late(i * time), i)));
}
echo(times, time, feedback) {
return this.echoWith(times, time, (pat, i) => pat.velocity(Math.pow(feedback, i)));
}
iter(times) {
return slowcat(...range(0, times - 1).map((i) => this.early(i / times)));
}
@ -562,7 +571,7 @@ class Pattern {
return this._withContext((context) => ({...context, velocity: (context.velocity || 1) * velocity}));
}
}
Pattern.prototype.patternified = ["apply", "fast", "slow", "cpm", "early", "late", "duration", "legato", "velocity", "segment"];
Pattern.prototype.patternified = ["apply", "fast", "slow", "cpm", "early", "late", "duration", "legato", "velocity", "segment", "color"];
Pattern.prototype.factories = {pure, stack, slowcat, fastcat, cat, timeCat, sequence, polymeter, pm, polyrhythm, pr};
const silence = new Pattern((_) => []);
function pure(value) {

View File

@ -25,7 +25,8 @@ export const markEvent = (editor) => (time, event) => {
if (!locs || !editor) {
return;
}
const marks = locs.map(({start, end}) => editor.getDoc().markText({line: start.line - 1, ch: start.column}, {line: end.line - 1, ch: end.column}, {css: "outline: 1px solid #FFCA28; box-sizing:border-box"}));
const col = event.context?.color || "#FFCA28";
const marks = locs.map(({start, end}) => editor.getDoc().markText({line: start.line - 1, ch: start.column}, {line: end.line - 1, ch: end.column}, {css: "outline: 1px solid " + col + "; box-sizing:border-box"}));
setTimeout(() => {
marks.forEach((mark) => mark.clear());
}, event.duration * 1e3);

View File

@ -17,14 +17,16 @@ Pattern.prototype.pianoroll = function({
ctx.fillRect(0, 0, w, h);
events.forEach((event) => {
const isActive = event.whole.begin <= t && event.whole.end >= t;
ctx.fillStyle = isActive ? active : inactive;
ctx.fillStyle = event.context?.color || inactive;
ctx.strokeStyle = event.context?.color || active;
ctx.globalAlpha = event.context.velocity ?? 1;
const x = Math.round(event.whole.begin / timeframe * w);
const width = Math.round((event.whole.end - event.whole.begin) / timeframe * w);
const y = Math.round(h - (Number(event.value) - minMidi) / midiRange * h);
const offset = t / timeframe * w;
const margin = 0;
ctx.fillRect(x - offset + margin + 1, y + 1, width - 2, height - 2);
const coords = [x - offset + margin + 1, y + 1, width - 2, height - 2];
isActive ? ctx.strokeRect(...coords) : ctx.fillRect(...coords);
});
}, timeframe, 2);
return this;

29
docs/dist/tunes.js vendored
View File

@ -560,9 +560,8 @@ stack(
.legato(cosine.struct("x*8").add(4/5).mul(4/5).fast(8))
.velocity(sine.struct("x*8").add(3/5).mul(2/5).fast(8))
.tone((await piano()).chain(out())).fast(3/4)`;
export const undergroundPlumber = `backgroundImage('https://images.nintendolife.com/news/2016/08/video_exploring_the_funky_inspiration_for_the_super_mario_bros_underground_theme/large.jpg',{
className:'darken'
})
export const undergroundPlumber = `backgroundImage('https://images.nintendolife.com/news/2016/08/video_exploring_the_funky_inspiration_for_the_super_mario_bros_underground_theme/large.jpg',{ className:'darken' })
const drums = await players({
bd: 'bd/BT0A0D0.wav',
sn: 'sn/ST0T0S3.wav',
@ -578,9 +577,27 @@ stack(
.slow(2)
.tone(synth({...osc('sawtooth7'),...adsr(0,.3,0)}).chain(out())),
"[g2,[c3 eb3]]".iter(4)
.stutWith(4, 1/4, (x,n)=>x.transpose(n*12).velocity(Math.pow(.4,n)))
.stutWith(4, 1/8, (x,n)=>x.transpose(n*12).velocity(Math.pow(.4,n)))
.legato(.1)
)
.transpose("<0@2 5 0 7 5 0 -5>/2")
.pianoroll({minMidi:21,maxMidi:180, background:'transparent',inactive:'#3F8F90',active:'#DE3123'})
)`;
)
.fast(2/3)
.pianoroll({minMidi:21,maxMidi:180, background:'transparent',inactive:'#3F8F90',active:'#DE3123'})`;
export const bridgeIsOver = `const breaks = (await players({mad:'https://freesound.org/data/previews/22/22274_109943-lq.mp3'})).chain(out())
stack(
stack(
"c3*2 [[c3@1.4 bb2] ab2] gb2*2 <[[gb2@1.4 ab2] bb2] gb2>".legato(".5 1".fast(2)).velocity(.8),
"0 ~".scale('c4 whole tone')
.euclidLegato(3,8).slow(2).mask("x ~")
.stutWith(8, 1/16, (x,n)=>x.scaleTranspose(n).velocity(Math.pow(.7,n)))
.scaleTranspose("<0 1 2 3 4 3 2 1>")
.fast(2)
.velocity(.7)
.legato(.5)
.stut(3, .5, 1/8)
).transpose(-1).tone((await piano()).chain(out())),
"mad".slow(2).tone(breaks)
).cpm(78).slow(4).pianoroll()
`;

View File

@ -42743,6 +42743,13 @@ class Pattern {
return binary_pat.fmap((b)=>(val)=>b ? val : undefined
).appRight(this)._removeUndefineds();
}
_color(color) {
return this._withContext((context)=>({
...context,
color
})
);
}
_segment(rate) {
return this.struct(pure(true).fast(rate));
}
@ -42839,6 +42846,15 @@ class Pattern {
return this.stutWith(times, time, (pat, i)=>pat.velocity(Math.pow(feedback, i))
);
}
// these might change with: https://github.com/tidalcycles/Tidal/issues/902
echoWith(times, time, func) {
return stack(...range(0, times - 1).map((i)=>func(this.late(i * time), i)
));
}
echo(times, time, feedback) {
return this.echoWith(times, time, (pat, i)=>pat.velocity(Math.pow(feedback, i))
);
}
iter(times) {
return slowcat(...range(0, times - 1).map((i)=>this.early(i / times)
));
@ -42886,7 +42902,8 @@ Pattern.prototype.patternified = [
'duration',
'legato',
'velocity',
'segment'
'segment',
'color'
];
// methods that create patterns, which are added to patternified Pattern methods
Pattern.prototype.factories = {
@ -136426,17 +136443,23 @@ _strudelMjs.Pattern.prototype.pianoroll = function({ timeframe =10 , inactive ='
ctx.fillRect(0, 0, w, h);
events.forEach((event)=>{
const isActive = event.whole.begin <= t && event.whole.end >= t;
ctx.fillStyle = isActive ? active : inactive;
ctx.fillStyle = event.context?.color || inactive;
ctx.strokeStyle = event.context?.color || active;
ctx.globalAlpha = event.context.velocity ?? 1;
const x = Math.round(event.whole.begin / timeframe * w);
const width = Math.round((event.whole.end - event.whole.begin) / timeframe * w);
const y = Math.round(h - (Number(event.value) - minMidi) / midiRange * h);
const offset = t / timeframe * w;
const margin = 0;
ctx.fillRect(x - offset + margin + 1, y + 1, width - 2, height - 2);
const coords = [
x - offset + margin + 1,
y + 1,
width - 2,
height - 2
];
isActive ? ctx.strokeRect(...coords) : ctx.fillRect(...coords);
});
}, timeframe, 2 // lookaheadCycles
);
}, timeframe, 2);
return this;
};
@ -172037,6 +172060,7 @@ exports.default = CodeMirror;
const markEvent = (editor)=>(time, event)=>{
const locs = event.context.locations;
if (!locs || !editor) return;
const col = event.context?.color || '#FFCA28';
// mark active event
const marks = locs.map(({ start , end })=>editor.getDoc().markText({
line: start.line - 1,
@ -172046,7 +172070,7 @@ const markEvent = (editor)=>(time, event)=>{
ch: end.column
}, //{ css: 'background-color: #FFCA28; color: black' } // background-color is now used by parent marking
{
css: 'outline: 1px solid #FFCA28; box-sizing:border-box'
css: 'outline: 1px solid ' + col + '; box-sizing:border-box'
})
);
//Tone.Transport.schedule(() => { // problem: this can be cleared by scheduler...
@ -183333,4 +183357,4 @@ exports.default = cx;
},{"@parcel/transformer-js/src/esmodule-helpers.js":"gkKU3"}]},["3uVTb"], "3uVTb", "parcelRequire94c2")
//# sourceMappingURL=index.74a36131.js.map
//# sourceMappingURL=index.fbb7f699.js.map

File diff suppressed because one or more lines are too long

View File

@ -11,6 +11,6 @@
<body>
<div id="root"></div>
<noscript>You need to enable JavaScript to run this app.</noscript>
<script src="/tutorial/index.74a36131.js" defer=""></script>
<script src="/tutorial/index.fbb7f699.js" defer=""></script>
</body>
</html>