Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paper #98

Merged
merged 31 commits into from
Apr 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
a54b6f0
Merge remote-tracking branch 'origin/osc' into paper
felixroos Apr 2, 2022
f698078
add sound synonm
felixroos Apr 2, 2022
05c900d
patch osc-js browser version
felixroos Apr 2, 2022
95e4239
pattern comparison snippets
felixroos Apr 2, 2022
068b95e
add shapeshifter snippets
felixroos Apr 2, 2022
b20467d
add more shapeshifter flags
felixroos Apr 2, 2022
fd28cfc
dont create defaultSynth on start
felixroos Apr 5, 2022
0e7b345
some more sprinkles of text
felixroos Apr 5, 2022
fb1976a
add .range
felixroos Apr 5, 2022
0f003ab
Merge remote-tracking branch 'origin/HEAD' into paper
felixroos Apr 9, 2022
914bc11
some loose references
felixroos Apr 11, 2022
7182894
reference links
yaxu Apr 12, 2022
0ad80c1
fix citations
yaxu Apr 12, 2022
023da09
A bit of background
yaxu Apr 13, 2022
369604a
Merge branch 'main' of github.com:tidalcycles/strudel into paper
yaxu Apr 13, 2022
21e3285
A bit more blah blah
yaxu Apr 14, 2022
f278c85
more citations
yaxu Apr 14, 2022
8993488
initial demo submission
yaxu Apr 15, 2022
a32d77b
Merge commit '47717e872b87f497990d7c1d6c3d54bfb96f2003' into paper
felixroos Apr 24, 2022
dc66dab
future outlook + links
felixroos Apr 24, 2022
8564daf
Merge branch 'main' into paper
yaxu Apr 24, 2022
b80d7d2
Merge branch 'paper' of github.com:tidalcycles/strudel into paper
yaxu Apr 24, 2022
d595703
fix citations, build
yaxu Apr 24, 2022
11f697f
Tweak copyright
yaxu Apr 24, 2022
602cac5
tweak copyright
yaxu Apr 24, 2022
fe13a7f
build
yaxu Apr 24, 2022
07b22a2
Tweaks, more inspirations, and figure
yaxu Apr 25, 2022
0c5903d
Merge remote-tracking branch 'origin/HEAD' into paper
felixroos Apr 25, 2022
d3a0407
remove duplicate range
felixroos Apr 25, 2022
8da4217
remove old patched osc-js
felixroos Apr 25, 2022
7f8cdfa
revert sound function
felixroos Apr 25, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 22 additions & 9 deletions packages/eval/shapeshifter.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ const isNote = (name) => /^[a-gC-G][bs]?[0-9]$/.test(name);

const addLocations = true;
export const addMiniLocations = true;
export const minifyStrings = true;
export const wrappedAsync = true;

export default (_code) => {
const { code, addReturn } = wrapAsync(_code);
Expand All @@ -38,18 +40,18 @@ export default (_code) => {
}

// replace template string `xxx` with mini(`xxx`)
if (isBackTickString(node)) {
if (minifyStrings && isBackTickString(node)) {
return minifyWithLocation(node, node, ast.locations, artificialNodes);
}
// allows to use top level strings, which are normally directives... but we don't need directives
if (node.directives?.length === 1 && !node.statements?.length) {
if (minifyStrings && node.directives?.length === 1 && !node.statements?.length) {
const str = new LiteralStringExpression({ value: node.directives[0].rawValue });
const wrapped = minifyWithLocation(str, node.directives[0], ast.locations, artificialNodes);
return { ...node, directives: [], statements: [wrapped] };
}

// replace double quote string "xxx" with mini('xxx')
if (isStringWithDoubleQuotes(node, ast.locations, code)) {
if (minifyStrings && isStringWithDoubleQuotes(node, ast.locations, code)) {
return minifyWithLocation(node, node, ast.locations, artificialNodes);
}

Expand Down Expand Up @@ -117,17 +119,21 @@ export default (_code) => {
},
});
// add return to last statement (because it's wrapped in an async function artificially)
addReturn(shifted);
if (wrappedAsync) {
addReturn(shifted);
}
const generated = codegen(shifted);
return generated;
};

function wrapAsync(code) {
// wrap code in async to make await work on top level => this will create 1 line offset to locations
// this is why line offset is -1 in getLocationObject calls below
code = `(async () => {
if (wrappedAsync) {
code = `(async () => {
${code}
})()`;
}
const addReturn = (ast) => {
const body = ast.statements[0].expression.callee.body; // actual code ast inside async function body
body.statements = body.statements
Expand Down Expand Up @@ -204,9 +210,10 @@ function hasModifierCall(parent) {
parent?.type === 'StaticMemberExpression' && Object.keys(Pattern.prototype.composable).includes(parent.property)
);
}
const factories = Object.keys(Pattern.prototype.factories).concat(['mini']);

function isPatternFactory(node) {
return node?.type === 'CallExpression' && Object.keys(Pattern.prototype.factories).includes(node.callee.name);
return node?.type === 'CallExpression' && factories.includes(node.callee.name);
}

function canBeOverloaded(node) {
Expand All @@ -233,9 +240,14 @@ function reifyWithLocation(literalNode, node, locations, artificialNodes) {
// with this, the reified pattern can pass its location to the event, to know where to highlight when it's active
function minifyWithLocation(literalNode, node, locations, artificialNodes) {
const args = getLocationArguments(node, locations);
const wrapped = wrapFunction('mini', literalNode);
if (!addMiniLocations) {
artificialNodes.push(wrapped);
return wrapped;
}
const withLocation = new CallExpression({
callee: new StaticMemberExpression({
object: wrapFunction('mini', literalNode),
object: wrapped,
property: 'withMiniLocation',
}),
arguments: args,
Expand All @@ -246,17 +258,18 @@ function minifyWithLocation(literalNode, node, locations, artificialNodes) {

function getLocationArguments(node, locations) {
const loc = locations.get(node);
const lineOffset = wrappedAsync ? -1 : 0;
return [
new ArrayExpression({
elements: [
new LiteralNumericExpression({ value: loc.start.line - 1 }), // the minus 1 assumes the code has been wrapped in async iife
new LiteralNumericExpression({ value: loc.start.line + lineOffset }), // the minus 1 assumes the code has been wrapped in async iife
new LiteralNumericExpression({ value: loc.start.column }),
new LiteralNumericExpression({ value: loc.start.offset }),
],
}),
new ArrayExpression({
elements: [
new LiteralNumericExpression({ value: loc.end.line - 1 }), // the minus 1 assumes the code has been wrapped in async iife
new LiteralNumericExpression({ value: loc.end.line + lineOffset }), // the minus 1 assumes the code has been wrapped in async iife
new LiteralNumericExpression({ value: loc.end.column }),
new LiteralNumericExpression({ value: loc.end.offset }),
],
Expand Down
527 changes: 527 additions & 0 deletions paper/citation-cache.json

Large diffs are not rendered by default.