code format
This commit is contained in:
parent
67ad82d52e
commit
bf1ba6efc0
17 changed files with 75 additions and 78 deletions
|
|
@ -16,7 +16,7 @@ evalScope(
|
|||
import('@strudel.cycles/tonal'),
|
||||
);
|
||||
|
||||
setStringParser(mini)
|
||||
setStringParser(mini);
|
||||
|
||||
const { evaluate } = repl({
|
||||
defaultOutput: webaudioOutput,
|
||||
|
|
|
|||
|
|
@ -80,16 +80,16 @@ export class Hap {
|
|||
}
|
||||
|
||||
show(compact = false) {
|
||||
const value = typeof this.value === 'object'
|
||||
? compact
|
||||
const value =
|
||||
typeof this.value === 'object'
|
||||
? compact
|
||||
? JSON.stringify(this.value).slice(1, -1).replaceAll('"', '').replaceAll(',', ' ')
|
||||
: JSON.stringify(this.value)
|
||||
: this.value
|
||||
: this.value;
|
||||
var spans = '';
|
||||
if (this.whole == undefined) {
|
||||
spans = '~' + this.part.show;
|
||||
}
|
||||
else {
|
||||
} 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() + ' ⇜ ';
|
||||
|
|
@ -102,12 +102,10 @@ export class Hap {
|
|||
spans += ')';
|
||||
}
|
||||
if (!this.whole.end.equals(this.part.end)) {
|
||||
spans += ' ⇝ ' + this.whole.end.show()
|
||||
spans += ' ⇝ ' + this.whole.end.show();
|
||||
}
|
||||
}
|
||||
return (
|
||||
'[ ' + spans + ' | ' + value + ' ]'
|
||||
);
|
||||
return '[ ' + spans + ' | ' + value + ' ]';
|
||||
}
|
||||
|
||||
showWhole(compact = false) {
|
||||
|
|
|
|||
|
|
@ -541,35 +541,34 @@ export class Pattern {
|
|||
defragmentHaps() {
|
||||
// remove continuous haps
|
||||
const pat = this.discreteOnly();
|
||||
|
||||
|
||||
return pat.withHaps((haps) => {
|
||||
const result = [];
|
||||
for (var i=0; i < haps.length; ++i) {
|
||||
for (var i = 0; i < haps.length; ++i) {
|
||||
var searching = true;
|
||||
var a = haps[i];
|
||||
while (searching) {
|
||||
const a_value = JSON.stringify(haps[i].value);
|
||||
var found = false;
|
||||
|
||||
for(var j=i+1; j<haps.length; j++) {
|
||||
for (var j = i + 1; j < haps.length; j++) {
|
||||
const b = haps[j];
|
||||
|
||||
if (a.whole.equals(b.whole)) {
|
||||
if (a.part.begin.eq(b.part.end)) {
|
||||
if (a_value === JSON.stringify(b.value)) {
|
||||
// eat the matching hap into 'a'
|
||||
a = new Hap(a.whole, new TimeSpan(b.part.begin, a.part.end), a.value)
|
||||
haps.splice(j,1);
|
||||
a = new Hap(a.whole, new TimeSpan(b.part.begin, a.part.end), a.value);
|
||||
haps.splice(j, 1);
|
||||
// restart the search
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (b.part.begin.eq(a.part.end)) {
|
||||
} else if (b.part.begin.eq(a.part.end)) {
|
||||
if (a_value == JSON.stringify(b.value)) {
|
||||
// eat the matching hap into 'a'
|
||||
a = new Hap(a.whole, new TimeSpan(a.part.begin, b.part.end), a.value)
|
||||
haps.splice(j,1);
|
||||
a = new Hap(a.whole, new TimeSpan(a.part.begin, b.part.end), a.value);
|
||||
haps.splice(j, 1);
|
||||
// restart the search
|
||||
found = true;
|
||||
break;
|
||||
|
|
@ -577,7 +576,7 @@ export class Pattern {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
searching = found;
|
||||
}
|
||||
result.push(a);
|
||||
|
|
|
|||
|
|
@ -917,20 +917,18 @@ describe('Pattern', () => {
|
|||
});
|
||||
describe('defragmentHaps', () => {
|
||||
it('Can merge two touching haps with same whole and value', () => {
|
||||
expect(stack(pure('a').mask(1,0), pure('a').mask(0,1)).defragmentHaps().firstCycle().length)
|
||||
.toStrictEqual(1);
|
||||
expect(stack(pure('a').mask(1, 0), pure('a').mask(0, 1)).defragmentHaps().firstCycle().length).toStrictEqual(1);
|
||||
});
|
||||
it('Doesnt merge two overlapping haps', () => {
|
||||
expect(stack(pure('a').mask(1,1,0), pure('a').mask(0,1)).defragmentHaps().firstCycle().length)
|
||||
.toStrictEqual(2);
|
||||
expect(stack(pure('a').mask(1, 1, 0), pure('a').mask(0, 1)).defragmentHaps().firstCycle().length).toStrictEqual(
|
||||
2,
|
||||
);
|
||||
});
|
||||
it('Doesnt merge two touching haps with different values', () => {
|
||||
expect(stack(pure('a').mask(1,0), pure('b').mask(0,1)).defragmentHaps().firstCycle().length)
|
||||
.toStrictEqual(2);
|
||||
expect(stack(pure('a').mask(1, 0), pure('b').mask(0, 1)).defragmentHaps().firstCycle().length).toStrictEqual(2);
|
||||
});
|
||||
it('Doesnt merge two touching haps with different wholes', () => {
|
||||
expect(stack(sequence('a', silence), pure('a').mask(0,1)).defragmentHaps().firstCycle().length)
|
||||
.toStrictEqual(2);
|
||||
expect(stack(sequence('a', silence), pure('a').mask(0, 1)).defragmentHaps().firstCycle().length).toStrictEqual(2);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -20,9 +20,9 @@ export class TimeSpan {
|
|||
|
||||
// Support zero-width timespans
|
||||
if (begin.equals(end)) {
|
||||
return([new TimeSpan(begin, end)]);
|
||||
return [new TimeSpan(begin, end)];
|
||||
}
|
||||
|
||||
|
||||
while (end.gt(begin)) {
|
||||
// If begin and end are in the same cycle, we're done.
|
||||
if (begin.sam().equals(end_sam)) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue