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

Fancy hap show, include part in snapshots #291

Merged
merged 2 commits into from
Dec 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
29 changes: 27 additions & 2 deletions packages/core/hap.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,34 @@ export class Hap {
);
}

show() {
show(compact = false) {
const value = typeof this.value === 'object'
? compact
? JSON.stringify(this.value).slice(1, -1).replaceAll('"', '').replaceAll(',', ' ')
: JSON.stringify(this.value)
: this.value
var spans = '';
if (this.whole == undefined) {
spans = '~' + this.part.show;
}
else {
var is_whole = this.whole.begin.equals(this.part.begin) && this.whole.end.equals(this.part.end);
if (!this.whole.begin.equals(this.part.begin)) {
spans = this.whole.begin.show() + ' ⇜ ';
}
if (!is_whole) {
spans += '(';
}
spans += this.part.show();
if (!is_whole) {
spans += ')';
}
if (!this.whole.end.equals(this.part.end)) {
spans += ' ⇝ ' + this.whole.end.show()
}
}
return (
'(' + (this.whole == undefined ? '~' : this.whole.show()) + ', ' + this.part.show() + ', ' + this.value + ')'
'[ ' + spans + ' | ' + value + ' ]'
);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/core/timespan.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export class TimeSpan {
}

show() {
return this.begin.show() + ' -> ' + this.end.show();
return this.begin.show() + ' ' + this.end.show();
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/xen/xen.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, mod } from '@strudel.cycles/core';
import { Pattern, _mod } from '@strudel.cycles/core';

export function edo(name) {
if (!/^[1-9]+[0-9]*edo$/.test(name)) {
Expand Down Expand Up @@ -42,7 +42,7 @@ function getXenScale(scale, indices) {
}

function xenOffset(xenScale, offset, index = 0) {
const i = mod(index + offset, xenScale.length);
const i = _mod(index + offset, xenScale.length);
const oct = Math.floor(offset / xenScale.length);
return xenScale[i] * Math.pow(2, oct);
}
Expand Down
2 changes: 1 addition & 1 deletion repl/src/runtime.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ evalScope(
export const queryCode = async (code, cycles = 1) => {
const { pattern } = await evaluate(code);
const haps = pattern.queryArc(0, cycles);
return haps.map((h) => h.showWhole());
return haps.map((h) => h.show(true));
};

export const testCycles = {
Expand Down