mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-25 04:28:30 +00:00
Merge remote-tracking branch 'origin/main' into clip-support-floats
This commit is contained in:
commit
92da70a7ae
@ -1582,6 +1582,24 @@ export const range2 = register('range2', function (min, max, pat) {
|
|||||||
return pat.fromBipolar()._range(min, max);
|
return pat.fromBipolar()._range(min, max);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allows dividing numbers via list notation using ":".
|
||||||
|
* Returns a new pattern with just numbers.
|
||||||
|
* @name ratio
|
||||||
|
* @memberof Pattern
|
||||||
|
* @returns Pattern
|
||||||
|
* @example
|
||||||
|
* ratio("1, 5:4, 3:2").mul(110).freq().s("piano").slow(2)
|
||||||
|
*/
|
||||||
|
export const ratio = register('ratio', (pat) =>
|
||||||
|
pat.fmap((v) => {
|
||||||
|
if (!Array.isArray(v)) {
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
return v.slice(1).reduce((acc, n) => acc / n, v[0]);
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
// Structural and temporal transformations
|
// Structural and temporal transformations
|
||||||
|
|
||||||
|
|||||||
@ -2,12 +2,12 @@ import React, { useMemo } from 'react';
|
|||||||
import _CodeMirror from '@uiw/react-codemirror';
|
import _CodeMirror from '@uiw/react-codemirror';
|
||||||
import { EditorView, Decoration } from '@codemirror/view';
|
import { EditorView, Decoration } from '@codemirror/view';
|
||||||
import { StateField, StateEffect } from '@codemirror/state';
|
import { StateField, StateEffect } from '@codemirror/state';
|
||||||
import { javascript } from '@codemirror/lang-javascript';
|
import { javascript, javascriptLanguage } from '@codemirror/lang-javascript';
|
||||||
import strudelTheme from '../themes/strudel-theme';
|
import strudelTheme from '../themes/strudel-theme';
|
||||||
import './style.css';
|
import './style.css';
|
||||||
import { useCallback } from 'react';
|
import { useCallback } from 'react';
|
||||||
import { autocompletion } from '@codemirror/autocomplete';
|
import { autocompletion } from '@codemirror/autocomplete';
|
||||||
//import { strudelAutocomplete } from './Autocomplete';
|
import { strudelAutocomplete } from './Autocomplete';
|
||||||
import { vim } from '@replit/codemirror-vim';
|
import { vim } from '@replit/codemirror-vim';
|
||||||
import { emacs } from '@replit/codemirror-emacs';
|
import { emacs } from '@replit/codemirror-emacs';
|
||||||
|
|
||||||
@ -92,9 +92,7 @@ const staticExtensions = [
|
|||||||
javascript(),
|
javascript(),
|
||||||
highlightField,
|
highlightField,
|
||||||
flashField,
|
flashField,
|
||||||
// javascriptLanguage.data.of({ autocomplete: strudelAutocomplete }),
|
javascriptLanguage.data.of({ autocomplete: strudelAutocomplete }),
|
||||||
// autocompletion({ override: [strudelAutocomplete] }),
|
|
||||||
autocompletion({ override: [] }), // wait for https://github.com/uiwjs/react-codemirror/pull/458
|
|
||||||
];
|
];
|
||||||
|
|
||||||
export default function CodeMirror({
|
export default function CodeMirror({
|
||||||
@ -105,6 +103,7 @@ export default function CodeMirror({
|
|||||||
theme,
|
theme,
|
||||||
keybindings,
|
keybindings,
|
||||||
isLineNumbersDisplayed,
|
isLineNumbersDisplayed,
|
||||||
|
isAutoCompletionEnabled,
|
||||||
fontSize = 18,
|
fontSize = 18,
|
||||||
fontFamily = 'monospace',
|
fontFamily = 'monospace',
|
||||||
options,
|
options,
|
||||||
@ -116,12 +115,14 @@ export default function CodeMirror({
|
|||||||
},
|
},
|
||||||
[onChange],
|
[onChange],
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleOnCreateEditor = useCallback(
|
const handleOnCreateEditor = useCallback(
|
||||||
(view) => {
|
(view) => {
|
||||||
onViewChanged?.(view);
|
onViewChanged?.(view);
|
||||||
},
|
},
|
||||||
[onViewChanged],
|
[onViewChanged],
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleOnUpdate = useCallback(
|
const handleOnUpdate = useCallback(
|
||||||
(viewUpdate) => {
|
(viewUpdate) => {
|
||||||
if (viewUpdate.selectionSet && onSelectionChange) {
|
if (viewUpdate.selectionSet && onSelectionChange) {
|
||||||
@ -130,16 +131,27 @@ export default function CodeMirror({
|
|||||||
},
|
},
|
||||||
[onSelectionChange],
|
[onSelectionChange],
|
||||||
);
|
);
|
||||||
|
|
||||||
const extensions = useMemo(() => {
|
const extensions = useMemo(() => {
|
||||||
|
let _extensions = [...staticExtensions];
|
||||||
let bindings = {
|
let bindings = {
|
||||||
vim,
|
vim,
|
||||||
emacs,
|
emacs,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (bindings[keybindings]) {
|
if (bindings[keybindings]) {
|
||||||
return [...staticExtensions, bindings[keybindings]()];
|
_extensions.push(bindings[keybindings]());
|
||||||
}
|
}
|
||||||
return staticExtensions;
|
|
||||||
}, [keybindings]);
|
if (isAutoCompletionEnabled) {
|
||||||
|
_extensions.push(javascriptLanguage.data.of({ autocomplete: strudelAutocomplete }));
|
||||||
|
} else {
|
||||||
|
_extensions.push(autocompletion({ override: [] }));
|
||||||
|
}
|
||||||
|
|
||||||
|
return _extensions;
|
||||||
|
}, [keybindings, isAutoCompletionEnabled]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div style={{ fontSize, fontFamily }} className="w-full">
|
<div style={{ fontSize, fontFamily }} className="w-full">
|
||||||
<_CodeMirror
|
<_CodeMirror
|
||||||
|
|||||||
@ -24,3 +24,7 @@
|
|||||||
.cm-theme-light {
|
.cm-theme-light {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
footer {
|
||||||
|
z-index: 0 !important;
|
||||||
|
}
|
||||||
|
|||||||
@ -3193,6 +3193,23 @@ exports[`runs examples > example "rarely" example index 0 1`] = `
|
|||||||
]
|
]
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`runs examples > example "ratio" example index 0 1`] = `
|
||||||
|
[
|
||||||
|
"[ (0/1 → 1/1) ⇝ 2/1 | freq:110 s:piano ]",
|
||||||
|
"[ (0/1 → 1/1) ⇝ 2/1 | freq:137.5 s:piano ]",
|
||||||
|
"[ (0/1 → 1/1) ⇝ 2/1 | freq:165 s:piano ]",
|
||||||
|
"[ 0/1 ⇜ (1/1 → 2/1) | freq:110 s:piano ]",
|
||||||
|
"[ 0/1 ⇜ (1/1 → 2/1) | freq:137.5 s:piano ]",
|
||||||
|
"[ 0/1 ⇜ (1/1 → 2/1) | freq:165 s:piano ]",
|
||||||
|
"[ (2/1 → 3/1) ⇝ 4/1 | freq:110 s:piano ]",
|
||||||
|
"[ (2/1 → 3/1) ⇝ 4/1 | freq:137.5 s:piano ]",
|
||||||
|
"[ (2/1 → 3/1) ⇝ 4/1 | freq:165 s:piano ]",
|
||||||
|
"[ 2/1 ⇜ (3/1 → 4/1) | freq:110 s:piano ]",
|
||||||
|
"[ 2/1 ⇜ (3/1 → 4/1) | freq:137.5 s:piano ]",
|
||||||
|
"[ 2/1 ⇜ (3/1 → 4/1) | freq:165 s:piano ]",
|
||||||
|
]
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`runs examples > example "release" example index 0 1`] = `
|
exports[`runs examples > example "release" example index 0 1`] = `
|
||||||
[
|
[
|
||||||
"[ 0/1 → 1/4 | note:c3 release:0 ]",
|
"[ 0/1 → 1/4 | note:c3 release:0 ]",
|
||||||
|
|||||||
@ -139,6 +139,10 @@ This group of functions allows to modify the value of events.
|
|||||||
|
|
||||||
<JsDoc client:idle name="Pattern.range2" h={0} />
|
<JsDoc client:idle name="Pattern.range2" h={0} />
|
||||||
|
|
||||||
|
## ratio
|
||||||
|
|
||||||
|
<JsDoc client:idle name="Pattern.ratio" h={0} />
|
||||||
|
|
||||||
# Custom Parameters
|
# Custom Parameters
|
||||||
|
|
||||||
You can also create your own parameters:
|
You can also create your own parameters:
|
||||||
|
|||||||
@ -364,7 +364,8 @@ const fontFamilyOptions = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function SettingsTab({ scheduler }) {
|
function SettingsTab({ scheduler }) {
|
||||||
const { theme, keybindings, isLineNumbersDisplayed, fontSize, fontFamily } = useSettings();
|
const { theme, keybindings, isLineNumbersDisplayed, isAutoCompletionEnabled, fontSize, fontFamily } = useSettings();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="text-foreground p-4 space-y-4">
|
<div className="text-foreground p-4 space-y-4">
|
||||||
{/* <FormItem label="Tempo">
|
{/* <FormItem label="Tempo">
|
||||||
@ -406,7 +407,7 @@ function SettingsTab({ scheduler }) {
|
|||||||
/>
|
/>
|
||||||
</FormItem>
|
</FormItem>
|
||||||
</div>
|
</div>
|
||||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
<div className="grid grid-cols-1 md:grid-cols-3 gap-4">
|
||||||
<FormItem label="Keybindings">
|
<FormItem label="Keybindings">
|
||||||
<ButtonGroup
|
<ButtonGroup
|
||||||
value={keybindings}
|
value={keybindings}
|
||||||
@ -419,6 +420,11 @@ function SettingsTab({ scheduler }) {
|
|||||||
onChange={(cbEvent) => settingsMap.setKey('isLineNumbersDisplayed', cbEvent.target.checked)}
|
onChange={(cbEvent) => settingsMap.setKey('isLineNumbersDisplayed', cbEvent.target.checked)}
|
||||||
value={isLineNumbersDisplayed}
|
value={isLineNumbersDisplayed}
|
||||||
/>
|
/>
|
||||||
|
<Checkbox
|
||||||
|
label="Enable auto-completion"
|
||||||
|
onChange={(cbEvent) => settingsMap.setKey('isAutoCompletionEnabled', cbEvent.target.checked)}
|
||||||
|
value={isAutoCompletionEnabled}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<FormItem label="Reset Settings">
|
<FormItem label="Reset Settings">
|
||||||
<button
|
<button
|
||||||
|
|||||||
@ -105,7 +105,7 @@ export function Repl({ embedded = false }) {
|
|||||||
const [lastShared, setLastShared] = useState();
|
const [lastShared, setLastShared] = useState();
|
||||||
const [pending, setPending] = useState(true);
|
const [pending, setPending] = useState(true);
|
||||||
|
|
||||||
const { theme, keybindings, fontSize, fontFamily, isLineNumbersDisplayed } = useSettings();
|
const { theme, keybindings, fontSize, fontFamily, isLineNumbersDisplayed, isAutoCompletionEnabled } = useSettings();
|
||||||
|
|
||||||
const { code, setCode, scheduler, evaluate, activateCode, isDirty, activeCode, pattern, started, stop, error } =
|
const { code, setCode, scheduler, evaluate, activateCode, isDirty, activeCode, pattern, started, stop, error } =
|
||||||
useStrudel({
|
useStrudel({
|
||||||
@ -272,6 +272,7 @@ export function Repl({ embedded = false }) {
|
|||||||
value={code}
|
value={code}
|
||||||
keybindings={keybindings}
|
keybindings={keybindings}
|
||||||
isLineNumbersDisplayed={isLineNumbersDisplayed}
|
isLineNumbersDisplayed={isLineNumbersDisplayed}
|
||||||
|
isAutoCompletionEnabled={isAutoCompletionEnabled}
|
||||||
fontSize={fontSize}
|
fontSize={fontSize}
|
||||||
fontFamily={fontFamily}
|
fontFamily={fontFamily}
|
||||||
onChange={handleChangeCode}
|
onChange={handleChangeCode}
|
||||||
|
|||||||
@ -5,6 +5,7 @@ export const defaultSettings = {
|
|||||||
activeFooter: 'intro',
|
activeFooter: 'intro',
|
||||||
keybindings: 'codemirror',
|
keybindings: 'codemirror',
|
||||||
isLineNumbersDisplayed: true,
|
isLineNumbersDisplayed: true,
|
||||||
|
isAutoCompletionEnabled: false,
|
||||||
theme: 'strudelTheme',
|
theme: 'strudelTheme',
|
||||||
fontFamily: 'monospace',
|
fontFamily: 'monospace',
|
||||||
fontSize: 18,
|
fontSize: 18,
|
||||||
@ -21,6 +22,7 @@ export function useSettings() {
|
|||||||
...state,
|
...state,
|
||||||
isZen: [true, 'true'].includes(state.isZen) ? true : false,
|
isZen: [true, 'true'].includes(state.isZen) ? true : false,
|
||||||
isLineNumbersDisplayed: [true, 'true'].includes(state.isLineNumbersDisplayed) ? true : false,
|
isLineNumbersDisplayed: [true, 'true'].includes(state.isLineNumbersDisplayed) ? true : false,
|
||||||
|
isAutoCompletionEnabled: [true, 'true'].includes(state.isAutoCompletionEnabled) ? true : false,
|
||||||
fontSize: Number(state.fontSize),
|
fontSize: Number(state.fontSize),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user