Skip to content

Commit

Permalink
Docs update 1.0.2459
Browse files Browse the repository at this point in the history
  • Loading branch information
cesaref committed Apr 22, 2024
1 parent 3971ac1 commit a39eed2
Show file tree
Hide file tree
Showing 16 changed files with 147 additions and 41 deletions.
2 changes: 1 addition & 1 deletion assets/example_patches/808/cmaj_808.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// This file contains a Javascript/Webassembly/WebAudio export of the Cmajor
// patch '808.cmajorpatch'.
//
// This file was auto-generated by the Cmajor toolkit v1.0.2458
// This file was auto-generated by the Cmajor toolkit v1.0.2459
//
// To use it, import this module into your HTML/Javascript code and call
// `createAudioWorkletNodePatchConnection()`. The AudioWorkletPatchConnection
Expand Down
2 changes: 1 addition & 1 deletion assets/example_patches/CompuFart/cmaj_CompuFart.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// This file contains a Javascript/Webassembly/WebAudio export of the Cmajor
// patch 'CompuFartSynth.cmajorpatch'.
//
// This file was auto-generated by the Cmajor toolkit v1.0.2458
// This file was auto-generated by the Cmajor toolkit v1.0.2459
//
// To use it, import this module into your HTML/Javascript code and call
// `createAudioWorkletNodePatchConnection()`. The AudioWorkletPatchConnection
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion assets/example_patches/GuitarLSTM/cmaj_GuitarLSTM.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion assets/example_patches/HelloWorld/cmaj_Hello_World.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// This file contains a Javascript/Webassembly/WebAudio export of the Cmajor
// patch 'HelloWorld.cmajorpatch'.
//
// This file was auto-generated by the Cmajor toolkit v1.0.2458
// This file was auto-generated by the Cmajor toolkit v1.0.2459
//
// To use it, import this module into your HTML/Javascript code and call
// `createAudioWorkletNodePatchConnection()`. The AudioWorkletPatchConnection
Expand Down
2 changes: 1 addition & 1 deletion assets/example_patches/Piano/cmaj_Piano.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// This file contains a Javascript/Webassembly/WebAudio export of the Cmajor
// patch 'Piano.cmajorpatch'.
//
// This file was auto-generated by the Cmajor toolkit v1.0.2458
// This file was auto-generated by the Cmajor toolkit v1.0.2459
//
// To use it, import this module into your HTML/Javascript code and call
// `createAudioWorkletNodePatchConnection()`. The AudioWorkletPatchConnection
Expand Down
2 changes: 1 addition & 1 deletion assets/example_patches/PirkleFilters/cmaj_vafilters.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion assets/example_patches/Pro54/cmaj_Pro54.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// This file contains a Javascript/Webassembly/WebAudio export of the Cmajor
// patch 'Pro54.cmajorpatch'.
//
// This file was auto-generated by the Cmajor toolkit v1.0.2458
// This file was auto-generated by the Cmajor toolkit v1.0.2459
//
// To use it, import this module into your HTML/Javascript code and call
// `createAudioWorkletNodePatchConnection()`. The AudioWorkletPatchConnection
Expand Down
2 changes: 1 addition & 1 deletion assets/example_patches/Replicant/cmaj_Replicant.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion assets/example_patches/RingMod/cmaj_Ring_Mod_Demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// This file contains a Javascript/Webassembly/WebAudio export of the Cmajor
// patch 'RingMod.cmajorpatch'.
//
// This file was auto-generated by the Cmajor toolkit v1.0.2458
// This file was auto-generated by the Cmajor toolkit v1.0.2459
//
// To use it, import this module into your HTML/Javascript code and call
// `createAudioWorkletNodePatchConnection()`. The AudioWorkletPatchConnection
Expand Down
2 changes: 1 addition & 1 deletion assets/example_patches/STunedBar6/cmaj_STunedBar6.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion assets/example_patches/Tremolo/cmaj_Tremolo.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// This file contains a Javascript/Webassembly/WebAudio export of the Cmajor
// patch 'Tremolo.cmajorpatch'.
//
// This file was auto-generated by the Cmajor toolkit v1.0.2458
// This file was auto-generated by the Cmajor toolkit v1.0.2459
//
// To use it, import this module into your HTML/Javascript code and call
// `createAudioWorkletNodePatchConnection()`. The AudioWorkletPatchConnection
Expand Down
2 changes: 1 addition & 1 deletion assets/example_patches/ZitaReverb/cmaj_Zita_Reverb.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// This file contains a Javascript/Webassembly/WebAudio export of the Cmajor
// patch 'ZitaReverb.cmajorpatch'.
//
// This file was auto-generated by the Cmajor toolkit v1.0.2458
// This file was auto-generated by the Cmajor toolkit v1.0.2459
//
// To use it, import this module into your HTML/Javascript code and call
// `createAudioWorkletNodePatchConnection()`. The AudioWorkletPatchConnection
Expand Down
Binary file modified cmaj_api/cmaj-compiler-wasm.wasm
Binary file not shown.
24 changes: 17 additions & 7 deletions cmaj_api/cmaj-embedded-compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,24 +205,34 @@ export default class CmajorCompiler
return content;
}

/** Tries to read and return the content of a file as a string. */
async getSourceFileContentAsString (path)
{
const content = await this.getSourceFileContent (path);

if (typeof content === "string")
return content;

const decoder = new TextDecoder('utf-8');
return await decoder.decode (content);
}

/** Tries to read and return the manifest as a JSON object. */
async readManifest()
{
const getContent = async () =>
const getManifestPath = () =>
{
if (this.manifestPath)
return await this.getSourceFileContent (this.manifestPath);
return this.manifestPath;

for (const f of sources)
for (const f of this.sources)
if (f.path.endsWith (".cmajorpatch"))
return f.content;
return f.path;

throw new Error ("Couldn't find a manifest file");
}

const decoder = new TextDecoder('utf-8');
const content = await decoder.decode (await getContent());
return JSON.parse (content);
return JSON.parse (await this.getSourceFileContentAsString (getManifestPath()));
}

/** @private */
Expand Down
138 changes: 117 additions & 21 deletions cmaj_api/embedded-compiler-demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,85 @@
your own URL to try it with any other .cmajorpatch file.</p>

<div>
<div class="example-patch" onclick="loadPatch('https://cmajor.dev/assets/ExampleSource/HelloWorld/HelloWorld.cmajorpatch')">HelloWorld</div>
<div class="example-patch" onclick="loadPatch('https://cmajor.dev/assets/ExampleSource/ElectricPiano/ElectricPiano.cmajorpatch')">ElectricPiano</div>
<div class="example-patch" onclick="loadPatch('https://cmajor.dev/assets/ExampleSource/808/808.cmajorpatch')">808</div>
<div class="example-patch" onclick="loadPatch('https://cmajor.dev/assets/ExampleSource/Piano/Piano.cmajorpatch')">Piano</div>
<div class="example-patch" onclick="loadPatch('https://cmajor.dev/assets/ExampleSource/Tremolo/Tremolo.cmajorpatch')">Tremolo</div>
<div class="example-patch" onclick="loadPatch('https://cmajor.dev/assets/ExampleSource/RingMod/RingMod.cmajorpatch')">RingMod</div>
<div class="example-patch" onclick="loadPatch('https://cmajor.dev/assets/ExampleSource/ZitaReverb/ZitaReverb.cmajorpatch')">ZitaReverb</div>
<div class="example-patch" onclick="loadPatch('https://cmajor.dev/assets/ExampleSource/Pro54/Pro54.cmajorpatch')">Pro54</div>
<div class="example-patch" onclick="loadPatch('https://cmajor.dev/assets/ExampleSource/GuitarLSTM/GuitarLSTM.cmajorpatch')">GuitarLSTM</div>
<div class="example-patch" onclick="loadPatch('https://cmajor.dev/assets/ExampleSource/PirkleFilters/vafilters.cmajorpatch')">PirkleFilters</div>
<div class="example-patch" onclick="loadPatch('https://cmajor.dev/assets/ExampleSource/Replicant/replicant.cmajorpatch')">Replicant</div>
<div class="example-patch" onclick="loadPatch('https://cmajor.dev/assets/ExampleSource/STunedBar6/STunedBar6.cmajorpatch')">STunedBar6</div>
<div class="example-patch" onclick="loadPatch('https://cmajor.dev/assets/ExampleSource/CompuFart/CompuFartSynth.cmajorpatch')">CompuFart</div>
<div class="example-patch" onclick="loadPatchFromURL('https://cmajor.dev/assets/ExampleSource/HelloWorld/HelloWorld.cmajorpatch')">HelloWorld</div>
<div class="example-patch" onclick="loadPatchFromURL('https://cmajor.dev/assets/ExampleSource/ElectricPiano/ElectricPiano.cmajorpatch')">ElectricPiano</div>
<div class="example-patch" onclick="loadPatchFromURL('https://cmajor.dev/assets/ExampleSource/808/808.cmajorpatch')">808</div>
<div class="example-patch" onclick="loadPatchFromURL('https://cmajor.dev/assets/ExampleSource/Piano/Piano.cmajorpatch')">Piano</div>
<div class="example-patch" onclick="loadPatchFromURL('https://cmajor.dev/assets/ExampleSource/Tremolo/Tremolo.cmajorpatch')">Tremolo</div>
<div class="example-patch" onclick="loadPatchFromURL('https://cmajor.dev/assets/ExampleSource/RingMod/RingMod.cmajorpatch')">RingMod</div>
<div class="example-patch" onclick="loadPatchFromURL('https://cmajor.dev/assets/ExampleSource/ZitaReverb/ZitaReverb.cmajorpatch')">ZitaReverb</div>
<div class="example-patch" onclick="loadPatchFromURL('https://cmajor.dev/assets/ExampleSource/Pro54/Pro54.cmajorpatch')">Pro54</div>
<div class="example-patch" onclick="loadPatchFromURL('https://cmajor.dev/assets/ExampleSource/GuitarLSTM/GuitarLSTM.cmajorpatch')">GuitarLSTM</div>
<div class="example-patch" onclick="loadPatchFromURL('https://cmajor.dev/assets/ExampleSource/PirkleFilters/vafilters.cmajorpatch')">PirkleFilters</div>
<div class="example-patch" onclick="loadPatchFromURL('https://cmajor.dev/assets/ExampleSource/Replicant/replicant.cmajorpatch')">Replicant</div>
<div class="example-patch" onclick="loadPatchFromURL('https://cmajor.dev/assets/ExampleSource/STunedBar6/STunedBar6.cmajorpatch')">STunedBar6</div>
<div class="example-patch" onclick="loadPatchFromURL('https://cmajor.dev/assets/ExampleSource/CompuFart/CompuFartSynth.cmajorpatch')">CompuFart</div>
</div>

<label>Load a patch from a URL:<input type="url" id="load-url" name="Patch URL" required size="50" onchange="loadPatch(this.value)"/></label>
<label>Or load a patch from a URL:<input type="url" id="load-url" name="Patch URL" required size="50" onchange="loadPatchFromURL(this.value)"/></label>

<div>
<p>Or paste in a manifest and some source file content:</p>

<textarea id="manifest" name="manifest" rows="10" cols="50">{
"CmajorVersion": 1,
"ID": "dev.cmajor.examples.helloworld",
"version": "1.0",
"name": "Hello World",
"description": "The classic audio Hello World",
"manufacturer": "Cmajor Software Ltd",
"category": "generator",
"isInstrument": false,

"source": "test.cmajor"
} </textarea>

<textarea id="source" name="source" rows="10" cols="50">processor HelloWorld
{
output stream float out;

// This simple struct holds a note + duration for our melody
struct Note
{
int pitch, length;

void play() const
{
let numFrames = this.length * framesPerQuarterNote;
let frequency = std::notes::noteToFrequency (this.pitch);
let phaseDelta = float (frequency * processor.period * twoPi);

loop (numFrames)
{
out <- volume * sin (phase);
phase = addModulo2Pi (phase, phaseDelta);
advance();
}
}
}

// This is our processor's entry-point function, which is invoked
// by the system
void main()
{
let melody = Note[] ( (79, 1), (77, 1), (69, 2), (71, 2),
(76, 1), (74, 1), (65, 2), (67, 2),
(74, 1), (72, 1), (64, 2), (67, 2),
(72, 4) );

for (wrap<melody.size> i)
melody[i].play();
}

// We'll define a couple of constants here to set the volume and tempo
let volume = 0.15f;
let framesPerQuarterNote = int (processor.frequency / 7);

float phase;
}
</textarea>
<button id="build" onclick="loadPatchFromTextBoxContent()">Build</button>
</div>
</div>
<div id="cmaj-view-container"></div>
</body>
Expand Down Expand Up @@ -83,6 +146,18 @@
margin: 0.5rem;
}

textarea {
background: rgb(172, 172, 172);
margin: 0.5rem;
}

button {
display: block;
margin: 0.5rem;
padding: 0.5rem;
background: lightblue;
}

#cmaj-view-container {
padding: 0.5rem;
display: block;
Expand All @@ -105,15 +180,11 @@

let audioContext;

window.loadPatch = async function (url)
async function loadPatch (prepareCompiler)
{
const parts = url.split ("/");
const manifestPath = parts.pop();
const baseURL = new URL (parts.join ("/") + "/");

const viewContainer = document.getElementById ("cmaj-view-container");

viewContainer.innerHTML = `Building ${manifestPath}...`;
viewContainer.innerHTML = `Building...`;
await audioContext?.close();

try
Expand All @@ -123,7 +194,7 @@

const compiler = new CmajorCompiler();

compiler.setManifestURL (baseURL, manifestPath);
prepareCompiler (compiler);

const connection = await compiler.createAudioWorkletNodePatchConnection (audioContext, "cmaj-worklet-processor");

Expand All @@ -150,5 +221,30 @@
}
}

window.loadPatchFromURL = async function (url)
{
loadPatch ((compiler) =>
{
const parts = url.split ("/");
const manifestPath = parts.pop();
const baseURL = new URL (parts.join ("/") + "/");

compiler.setManifestURL (baseURL, manifestPath);
});
}

window.loadPatchFromTextBoxContent = async function()
{
loadPatch ((compiler) =>
{
const manifestBox = document.getElementById ("manifest");
const sourceBox = document.getElementById ("source");

compiler.addSourceFile ("test.cmajorpatch", manifestBox.value);
compiler.addSourceFile ("test.cmajor", sourceBox.value);
});
}


</script>
</html>

0 comments on commit a39eed2

Please sign in to comment.