This commit is contained in:
2023-08-28 22:45:00 +03:00
3 changed files with 22 additions and 11 deletions

View File

@ -108,10 +108,10 @@ export class UserAPI {
_logMessage = (message: any): void => { _logMessage = (message: any): void => {
console.log(message); console.log(message);
clearTimeout(this.errorTimeoutID);
clearTimeout(this.printTimeoutID); clearTimeout(this.printTimeoutID);
clearTimeout(this.errorTimeoutID);
this.app.error_line.innerHTML = message as string; this.app.error_line.innerHTML = message as string;
this.app.error_line.style.color = "color-white"; this.app.error_line.style.color = "white";
this.app.error_line.classList.remove("hidden"); this.app.error_line.classList.remove("hidden");
this.printTimeoutID = setTimeout( this.printTimeoutID = setTimeout(
() => this.app.error_line.classList.add("hidden"), () => this.app.error_line.classList.add("hidden"),
@ -234,14 +234,13 @@ export class UserAPI {
// MIDI related functions // MIDI related functions
// ============================================================= // =============================================================
public midi_outputs = (): Array<MIDIOutput> => { public midi_outputs = (): void => {
/** /**
* Prints a list of available MIDI outputs in the console. * Prints a list of available MIDI outputs in the console.
* *
* @returns A list of available MIDI outputs * @returns A list of available MIDI outputs
*/ */
this._logMessage(this.MidiConnection.listMidiOutputs()); this._logMessage(this.MidiConnection.listMidiOutputs());
return this.MidiConnection.midiOutputs;
}; };
public midi_output = (outputName: string): void => { public midi_output = (outputName: string): void => {

View File

@ -581,14 +581,25 @@ You can use Topos to play MIDI thanks to the [WebMIDI API](https://developer.moz
Your web browser is capable of sending and receiving MIDI information through the [Web MIDI API](https://developer.mozilla.org/en-US/docs/Web/API/Web_MIDI_API). The support for MIDI on browsers is a bit shaky. Please, take some time to configure and test. To our best knowledge, **Chrome** is currently leading on this feature, followed closely by **Firefox**. The other major web browsers are also starting to support this API. **There are two important functions for configuration:** Your web browser is capable of sending and receiving MIDI information through the [Web MIDI API](https://developer.mozilla.org/en-US/docs/Web/API/Web_MIDI_API). The support for MIDI on browsers is a bit shaky. Please, take some time to configure and test. To our best knowledge, **Chrome** is currently leading on this feature, followed closely by **Firefox**. The other major web browsers are also starting to support this API. **There are two important functions for configuration:**
- <icode>midi_outputs()</icode>: prints the list of available MIDI devices to the web console. You will have to open the web console using ${key_shortcut("Ctrl+Shift+I")} or sometimes ${key_shortcut("F12")}. You can also open it from the menu of your web browser. - <icode>midi_outputs()</icode>: prints the list of available MIDI devices on the screen. You will have to open the web console using ${key_shortcut("Ctrl+Shift+I")} or sometimes ${key_shortcut("F12")}. You can also open it from the menu of your web browser. **Note:** close the docs to see it printed.
${makeExample( ${makeExample(
"Listing MIDI outputs", "Listing MIDI outputs",
` `
log(midi_outputs()) midi_outputs()
`, true)} `, true)}
- <icode>midi_output(output_name: string)</icode>: enter your desired output to connect to it.
${makeExample(
"Listing MIDI outputs",
`
midi_output("MIDI Rocket-Trumpet")
`, true)}
That's it! You are now ready to play with MIDI.
## Notes ## Notes
- <icode>midi(note: number|object)</icode>: send a MIDI Note. Object can take parameters {note: number, channel: number, port: number|string, velocity: number}. - <icode>midi(note: number|object)</icode>: send a MIDI Note. Object can take parameters {note: number, channel: number, port: number|string, velocity: number}.
@ -959,7 +970,7 @@ Audio samples are dynamically loaded from the web. By default, Topos is providin
## Available audio samples ## Available audio samples
<b class="flex lg:pl-6 lg:pr-6 text-bold mb-8">Samples can take a few seconds to load. Please wait if you are not hearing anything.</b> <b class="flex lg:pl-6 lg:pr-6 text-bold mb-8">Samples can take a few seconds to load. Please wait if you are not hearing anything. Lower your volume, take it slow. Some sounds might be harsh.</b>
<div class="lg:pl-6 lg:pr-6 inline-block w-fit flex flex-row flex-wrap gap-x-2 gap-y-2"> <div class="lg:pl-6 lg:pr-6 inline-block w-fit flex flex-row flex-wrap gap-x-2 gap-y-2">
${injectAvailableSamples(application)} ${injectAvailableSamples(application)}
</div> </div>

View File

@ -119,14 +119,15 @@ export class MidiConnection{
} }
} }
public listMidiOutputs(): void { public listMidiOutputs(): string {
/** /**
* Lists all available MIDI outputs to the console. * Lists all available MIDI outputs to the console.
*/ */
console.log('Available MIDI Outputs:'); let final_string = 'Available MIDI Outputs: ';
this.midiOutputs.forEach((output, index) => { this.midiOutputs.forEach((output, index) => {
console.log(`${index + 1}. ${output.name}`); final_string += `(${index + 1}) ${output.name} `;
}); });
return final_string;
} }
public sendMidiNote(noteNumber: number, channel: number, velocity: number, duration: number, port: number|string = this.currentOutputIndex, bend: number|undefined = undefined): void { public sendMidiNote(noteNumber: number, channel: number, velocity: number, duration: number, port: number|string = this.currentOutputIndex, bend: number|undefined = undefined): void {