jevstrudel.git / packages / core / test / controls.test.mjs
1/*
2controls.test.mjs - <short description TODO>
3Copyright (C) 2023 Strudel contributors - see <https://codeberg.org/uzu/strudel/src/branch/main/packages/core/test/controls.test.mjs>
4This 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/>.
5*/
6
7import { s, pan, getControlName } from '../controls.mjs';
8import { mini } from '../../mini/mini.mjs';
9import { describe, it, expect } from 'vitest';
10import Fraction from '../fraction.mjs';
11
12describe('controls', () => {
13  it('should support controls', () => {
14    expect(s('bd').firstCycleValues).toEqual([{ s: 'bd' }]);
15  });
16  it('should support compound controls', () => {
17    expect(s(mini('bd:3')).firstCycleValues).toEqual([{ s: 'bd', n: 3 }]);
18    expect(s(mini('bd:3 sd:4:1.4')).firstCycleValues).toEqual([
19      { s: 'bd', n: 3 },
20      { s: 'sd', n: 4, gain: 1.4 },
21    ]);
22  });
23  it('should support ignore extra elements in compound controls', () => {
24    expect(s(mini('bd:3:0.4 sd:4:0.5:3:17')).firstCycleValues).toEqual([
25      { s: 'bd', n: 3, gain: 0.4 },
26      { s: 'sd', n: 4, gain: 0.5 },
27    ]);
28  });
29  it('should support nested controls', () => {
30    expect(s(mini('bd').pan(1)).firstCycleValues).toEqual([{ s: 'bd', pan: 1 }]);
31    expect(s(mini('bd:1').pan(1)).firstCycleValues).toEqual([{ s: 'bd', n: 1, pan: 1 }]);
32  });
33  it('preserves step count of the left pattern', () => {
34    expect(s(mini('bd cp mt').pan(mini('1 2 3 4')))._steps).toEqual(Fraction(3));
35  });
36  it('preserves step count of the right pattern for .out', () => {
37    expect(s(mini('bd cp mt').set.out(pan(mini('1 2 3 4'))))._steps).toEqual(Fraction(4));
38  });
39  it('combines step count of the pattern for .mix as lcm', () => {
40    expect(s(mini('bd cp mt').set.mix(pan(mini('1 2 3 4'))))._steps).toEqual(Fraction(12));
41  });
42  it('finds control name by alias', () => {
43    expect(getControlName('lpf')).toEqual('cutoff');
44    expect(getControlName('cutoff')).toEqual('cutoff');
45  });
46});