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

Browser scribble.clip output with Tone.js doesn't work with scribble.midi #103

Open
misterflippy opened this issue May 25, 2020 · 2 comments

Comments

@misterflippy
Copy link

When scribble.clip is called in a browser with Tone.js support (e.g. with a "synth" or other argument), the clip function output is a Tone.js object instead of a note array.

Scribbletune version: 3.6.1
Tone.js version: 13.3.1 or 13.8.25
OS: Windows 10
Browser: Firefox 76.0.1 (64-bit)

A couple of issues with this:

  1. This is confusing and inconsistent. I would expect scribble.clip to return the same type of output every time I call it.
  2. The Tone.js clip output object cannot be passed to scribble.midi in order to create a midi output file because scribble.midi expects the note array built by the normal scribble.clip output.
  3. Unable to use the same clip for playing in-browser and downloading. I could create one clip for playing and one for downloading, but these might not be the same if using the 'R' pattern for random notes, for example.

Example code:

 <!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/tone/13.8.25/Tone.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/scribbletune/3.6.1/scribbletune.js"></script>
</head>
<body>
    <script type="text/javascript">
        const clip1 = scribble.clip({
            notes: scribble.scale('c4 major'),
            pattern: 'xRxR',
            randomNotes: ['c4', 'd4']
        });

        console.log("Clip 1: " + clip1);

        const clip2 = scribble.clip({
            notes: scribble.scale('c4 major'),
            pattern: 'xRxR',
            randomNotes: ['c4', 'd4'],
            synth: 'PolySynth'
        });

        console.log("Clip 2: " + clip2);

        console.log("Generating midi file for Clip 1");

        //this succeeds
        const link1 = scribble.midi(clip1, 'clip1.mid');

        console.log("Generating midi file for Clip 2");

        //this fails with "TypeError: o is undefined"
        const link2 = scribble.midi(clip2, 'clip2.mid');
    </script>
</body>
</html>

Sample code console output:

Clip 1: [object Object],[object Object],[object Object],[object Object] clip_midi.html:17:17
Clip 2: Sequence clip_midi.html:26:17
Generating midi file for Clip 1 clip_midi.html:28:17
Generating midi file for Clip 2 clip_midi.html:33:17
TypeError: o is undefined
@walmik
Copy link
Collaborator

walmik commented May 26, 2020

Thank you for the detailed outline @misterflippy

I always worked in a way that I d be producing clips ether from the terminal OR play em in the browser (and if I needed to create MIDI, then I d do something similar to what you did).

Having said that, this is a perfectly valid expectation on your part and I cant imagine why I never thought of it! I want to think aloud on what we can do to address this. One option is to just not return a Tone object from clip. But then that means we ll have to provide some additional interface to create a playable Tone object from a clip for sample vs samples and synth (and monosynth). This is not impossible but it moves away from the philosophy of Scribbletune to have a minimal API.

Ideally it d be nice if the clip behaves exactly the way you expected. When passed on to the midi method within a browser, it should simply strip out the Tone.js specific props and continue to operate in a seamless sort of way. This may require us to retain the originally passed params somehow so that they can be invoked again later.

Lemme know what you think!

@misterflippy
Copy link
Author

Having an additional interface to create the Tone object fits my expectations better, but I'm also fine with a more seamless approach since that probably fits your philosophy better.

Really, my main concern would be whether I could get the same output for both the download and the browser audio.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants