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

Add useful pattern selection behavior for performing. #897

Merged
merged 35 commits into from
Jan 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
1e2c261
working
daslyfe Jan 3, 2024
1bc86c3
state
daslyfe Jan 3, 2024
02b9bd8
highlight viewing pattern
daslyfe Jan 6, 2024
3604d39
mutate viewing pattern
daslyfe Jan 6, 2024
4e0a60d
example code logic
daslyfe Jan 7, 2024
0355c35
fixed create and duplicate behavior
daslyfe Jan 7, 2024
f7fe440
handle deletion cases
daslyfe Jan 7, 2024
1ff7548
refactoring
daslyfe Jan 8, 2024
51dd408
all working
daslyfe Jan 8, 2024
e01c6dc
prettier
daslyfe Jan 8, 2024
78f6fdf
reset for example patterns
daslyfe Jan 8, 2024
e7e60d3
Merge branch 'main' into pattern_selection
felixroos Jan 13, 2024
106772e
Merge branch 'main' into pattern_selection
daslyfe Jan 15, 2024
45df7bf
making things consistent
daslyfe Jan 16, 2024
7adfe6f
fixing edge cases...
daslyfe Jan 17, 2024
6cb156d
cleaning up
daslyfe Jan 19, 2024
77a48e8
persistent pattern data
daslyfe Jan 19, 2024
9a13c58
cleaning up
daslyfe Jan 19, 2024
3431eaf
cleaning up
daslyfe Jan 19, 2024
500ddf3
Merge branch 'main' into pattern_selection
daslyfe Jan 19, 2024
7aea1b5
fixed imports
daslyfe Jan 19, 2024
af52ac3
prettier
daslyfe Jan 19, 2024
0a349e1
avoid json errors in firefox
daslyfe Jan 20, 2024
b45fd5c
fix invalid date
daslyfe Jan 20, 2024
9dca7eb
add pattern filter behaves like sounds tab
daslyfe Jan 20, 2024
3cd59cd
cleaning up
daslyfe Jan 20, 2024
4fe7514
cleanup
daslyfe Jan 20, 2024
6c28398
fix scroll
daslyfe Jan 20, 2024
1146f6b
fix annoying div
daslyfe Jan 20, 2024
d03892b
Merge branch 'tidalcycles:main' into pattern_selection
daslyfe Jan 21, 2024
d31d154
fix oven imports
daslyfe Jan 21, 2024
b1d4955
title order
daslyfe Jan 21, 2024
961e931
autoplay and reset cps on default
daslyfe Jan 21, 2024
b46e8c0
reset/autoplay when window PARENT does not exist or does not contain …
daslyfe Jan 21, 2024
15c451a
default pattern filtername
daslyfe Jan 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/core/repl.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ export function repl({
afterEval?.({ code, pattern, meta });
return pattern;
} catch (err) {
// console.warn(`[repl] eval error: ${err.message}`);
logger(`[eval] error: ${err.message}`, 'error');
updateState({ evalError: err, pending: false });
onEvalError?.(err);
Expand Down
2 changes: 1 addition & 1 deletion website/src/components/Oven/Oven.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useState, useEffect } from 'react';
import { loadFeaturedPatterns, loadPublicPatterns } from '@src/repl/util.mjs';
import { loadFeaturedPatterns, loadPublicPatterns } from '@src/user_pattern_utils.mjs';
import { MiniRepl } from '@src/docs/MiniRepl';
import { PatternLabel } from '@src/repl/panel/PatternsTab';

Expand Down
4 changes: 2 additions & 2 deletions website/src/repl/Header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function Header({ context }) {
isDirty,
activeCode,
handleTogglePlay,
handleUpdate,
handleEvaluate,
handleShuffle,
handleShare,
} = context;
Expand Down Expand Up @@ -85,7 +85,7 @@ export function Header({ context }) {
)}
</button>
<button
onClick={() => handleUpdate()}
onClick={handleEvaluate}
title="update"
className={cx(
'flex items-center space-x-1',
Expand Down
81 changes: 52 additions & 29 deletions website/src/repl/Repl.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ import { defaultAudioDeviceName } from '../settings.mjs';
import { getAudioDevices, setAudioDevice } from './util.mjs';
import { StrudelMirror, defaultSettings } from '@strudel/codemirror';
import { useCallback, useEffect, useRef, useState } from 'react';
import { settingsMap, useSettings } from '../settings.mjs';
import {
initUserCode,
setActivePattern,
setLatestCode,
settingsMap,
updateUserCode,
useSettings,
} from '../settings.mjs';
createPatternID,
userPattern,
getViewingPatternData,
setViewingPatternData,
} from '../user_pattern_utils.mjs';
import { Header } from './Header';
import Loader from './Loader';
import { Panel } from './panel/Panel';
Expand All @@ -30,7 +31,6 @@ import PlayCircleIcon from '@heroicons/react/20/solid/PlayCircleIcon';
import './Repl.css';

const { code: randomTune, name } = getRandomTune();

const { latestCode } = settingsMap.get();

let modulesLoading, presets, drawContext, clearCanvas, isIframe;
Expand All @@ -46,7 +46,6 @@ if (typeof window !== 'undefined') {
export function Repl({ embedded = false }) {
const isEmbedded = embedded || isIframe;
const { panelPosition, isZen } = useSettings();

const init = useCallback(() => {
const drawTime = [-2, 2];
const drawContext = getDrawContext();
Expand All @@ -71,11 +70,28 @@ export function Repl({ embedded = false }) {
onUpdateState: (state) => {
setReplState({ ...state });
},
afterEval: ({ code }) => {
updateUserCode(code);
// setPending(false);
afterEval: (all) => {
const { code } = all;
setLatestCode(code);
window.location.hash = '#' + code2hash(code);
const viewingPatternData = getViewingPatternData();
const data = { ...viewingPatternData, code };
let id = data.id;
const isExamplePattern = viewingPatternData.collection !== userPattern.collection;

if (isExamplePattern) {
const codeHasChanged = code !== viewingPatternData.code;
if (codeHasChanged) {
// fork example
const newPattern = userPattern.duplicate(data);
id = newPattern.id;
setViewingPatternData(newPattern.data);
}
} else {
id = userPattern.isValidID(id) ? id : createPatternID();
setViewingPatternData(userPattern.update(id, data).data);
}
setActivePattern(id);
},
bgFill: false,
});
Expand All @@ -86,7 +102,6 @@ export function Repl({ embedded = false }) {
let msg;
if (decoded) {
editor.setCode(decoded);
initUserCode(decoded);
msg = `I have loaded the code from the URL.`;
} else if (latestCode) {
editor.setCode(latestCode);
Expand All @@ -96,7 +111,6 @@ export function Repl({ embedded = false }) {
msg = `A random code snippet named "${name}" has been loaded!`;
}
logger(`Welcome to Strudel! ${msg} Press play or hit ctrl+enter to run it!`, 'highlight');
// setPending(false);
});

editorRef.current = editor;
Expand Down Expand Up @@ -138,29 +152,37 @@ export function Repl({ embedded = false }) {
// UI Actions
//

const handleTogglePlay = async () => editorRef.current?.toggle();
const handleUpdate = async (newCode, reset = false) => {
const handleTogglePlay = async () => {
editorRef.current?.toggle();
};

const resetEditor = async () => {
clearCanvas();
resetLoadedSounds();
editorRef.current.repl.setCps(1);
await prebake(); // declare default samples
};

const handleUpdate = async (patternData, reset = false) => {
setViewingPatternData(patternData);
editorRef.current.setCode(patternData.code);
if (reset) {
clearCanvas();
resetLoadedSounds();
editorRef.current.repl.setCps(1);
await prebake(); // declare default samples
}
if (newCode) {
editorRef.current.setCode(newCode);
editorRef.current.repl.evaluate(newCode);
} else if (isDirty) {
editorRef.current.evaluate();
await resetEditor();
handleEvaluate();
}
};

const handleEvaluate = () => {
editorRef.current.evaluate();
};
const handleShuffle = async () => {
// window.postMessage('strudel-shuffle');
const { code, name } = getRandomTune();
logger(`[repl] ✨ loading random tune "${name}"`);
setActivePattern(name);
const patternData = getRandomTune();
const code = patternData.code;
logger(`[repl] ✨ loading random tune "${patternData.id}"`);
setActivePattern(patternData.id);
setViewingPatternData(patternData);
clearCanvas();
resetLoadedSounds();
editorRef.current.repl.setCps(1);
await prebake(); // declare default samples
editorRef.current.setCode(code);
editorRef.current.repl.evaluate(code);
Expand All @@ -177,6 +199,7 @@ export function Repl({ embedded = false }) {
handleUpdate,
handleShuffle,
handleShare,
handleEvaluate,
};

return (
Expand Down
Loading