Skip to content

Commit

Permalink
Merge pull request #484 from tidalcycles/revert-wip-390
Browse files Browse the repository at this point in the history
Revert "Another attempt at composable functions - WIP (#390)"
  • Loading branch information
felixroos committed Feb 27, 2023
2 parents 37d6723 + 961bbf6 commit e2ae627
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 326 deletions.
20 changes: 10 additions & 10 deletions packages/core/controls.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Copyright (C) 2022 Strudel contributors - see <https://github.com/tidalcycles/st
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

import { Pattern, sequence, registerControl } from './pattern.mjs';
import { Pattern, sequence } from './pattern.mjs';

const controls = {};
const generic_params = [
Expand Down Expand Up @@ -828,26 +828,26 @@ const generic_params = [

// TODO: slice / splice https://www.youtube.com/watch?v=hKhPdO0RKDQ&list=PL2lW1zNIIwj3bDkh-Y3LUGDuRcoUigoDs&index=13

const makeControl = function (name) {
const func = (...pats) => sequence(...pats).withValue((x) => ({ [name]: x }));
const setter = function (...pats) {
const _name = (name, ...pats) => sequence(...pats).withValue((x) => ({ [name]: x }));

const _setter = (func, name) =>
function (...pats) {
if (!pats.length) {
return this.fmap((value) => ({ [name]: value }));
}
return this.set(func(...pats));
};
Pattern.prototype[name] = setter;
registerControl(name, func);
return func;
};

generic_params.forEach(([type, name, description]) => {
controls[name] = makeControl(name);
controls[name] = (...pats) => _name(name, ...pats);
Pattern.prototype[name] = _setter(controls[name], name);
});

// create custom param
controls.createParam = (name) => {
return makeControl(name);
const func = (...pats) => _name(name, ...pats);
Pattern.prototype[name] = _setter(func, name);
return (...pats) => _name(name, ...pats);
};

controls.createParams = (...names) =>
Expand Down

0 comments on commit e2ae627

Please sign in to comment.