import React, { useState } from 'react'; import { Tone } from '@strudel.cycles/tone'; import useRepl from '../useRepl.mjs'; import cx from '../cx'; import useHighlighting from '../useHighlighting'; import { useInView } from 'react-hook-inview'; // eval stuff start import { extend } from '@strudel.cycles/eval'; import * as strudel from '@strudel.cycles/core'; import gist from '@strudel.cycles/core/gist.js'; import { mini } from '@strudel.cycles/mini/mini.mjs'; import { Tone } from '@strudel.cycles/tone'; import * as toneHelpers from '@strudel.cycles/tone/tone.mjs'; import * as voicingHelpers from '@strudel.cycles/tonal/voicings.mjs'; import * as uiHelpers from '@strudel.cycles/tone/ui.mjs'; import * as drawHelpers from '@strudel.cycles/tone/draw.mjs'; import euclid from '@strudel.cycles/core/euclid.mjs'; import '@strudel.cycles/tone/tone.mjs'; import '@strudel.cycles/midi/midi.mjs'; import '@strudel.cycles/tonal/voicings.mjs'; import '@strudel.cycles/tonal/tonal.mjs'; import '@strudel.cycles/xen/xen.mjs'; import '@strudel.cycles/xen/tune.mjs'; import '@strudel.cycles/core/euclid.mjs'; import '@strudel.cycles/tone/pianoroll.mjs'; import '@strudel.cycles/tone/draw.mjs'; import CodeMirror6 from '../CodeMirror6'; extend(Tone, strudel, strudel.Pattern.prototype.bootstrap(), toneHelpers, voicingHelpers, drawHelpers, uiHelpers, { gist, euclid, mini, Tone, }); // eval stuff end const defaultSynth = new Tone.PolySynth().chain(new Tone.Gain(0.5), Tone.Destination).set({ oscillator: { type: 'triangle' }, envelope: { release: 0.01, }, }); // "balanced" | "interactive" | "playback"; // Tone.setContext(new Tone.Context({ latencyHint: 'playback', lookAhead: 1 })); function MiniRepl({ tune, maxHeight = 500 }) { const { code, setCode, pattern, activateCode, error, cycle, dirty, togglePlay } = useRepl({ tune, defaultSynth, autolink: false, }); const lines = code.split('\n').length; const [view, setView] = useState(); const [ref, isVisible] = useInView({ threshold: 0.01, }); useHighlighting({ view, pattern, active: cycle.started }); return (
); } export default MiniRepl;