Skip to content

Commit

Permalink
use stereo
Browse files Browse the repository at this point in the history
  • Loading branch information
deleolajide committed Oct 19, 2024
1 parent 99cfed0 commit 1787a1d
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 12 deletions.
36 changes: 33 additions & 3 deletions docs/assets/pedalboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,41 @@ import { overdrivePedal } from './src/pedals/overdrive.js';
import { chorusPedal } from './src/pedals/chorus.js';


window.setupPedalBoard = async function(guitarContext) {
window.setupPedalBoard = async function(guitarContext, deviceMode, deviceId) {
window.$pedalboard = document.querySelector('.pedalboard');
window.buffer = null;
window.ctx = guitarContext;
window.pedalInput = ctx.createGain();
window.pedalInput = ctx.createGain();

if (deviceMode) {
const stream = await navigator.mediaDevices.getUserMedia({deviceId, audio: {
autoGainControl: false,
noiseSuppression: false,
echoCancellation: {exact: false},
advanced: [{
echoCancellation: {exact: false}
},
{googEchoCancellation: {exact: false}},
{googExperimentalEchoCancellation: {exact: false}},
{googDAEchoCancellation: {exact: false}},
{googAutoGainControl: {exact: false}},
{googExperimentalAutoGainControl: {exact: false}},
{googNoiseSuppression: {exact: false}},
{googExperimentalNoiseSuppression: {exact: false}},
{googHighpassFilter: {exact: false}},
{googTypingNoiseDetection: {exact: false}},
{googAudioMirroring: {exact: false}},
{googNoiseReduction: {exact: false}}
],
channelCount: 2,
latency: 0,
volume: 1.0
}, video: false});

const source = ctx.createMediaStreamSource(stream);
source.connect(pedalInput);
pedalInput.gain.setValueAtTime(1, ctx.currentTime);
}

const onError = (message = '') => {
const error = document.createElement('div');
Expand Down Expand Up @@ -67,7 +97,7 @@ window.setupPedalBoard = async function(guitarContext) {
reverbPedal
];

pedalInput.connect(ctx.destination);
pedalInput.connect(ctx.destination);

const output = pedals.reduce((input, pedal, index) => {
return pedal(input, index + 1);
Expand Down
3 changes: 2 additions & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@
<tr><td><b>Pads Synth MIDI Device</b></td><td><select id="midiPadsSel" type="text" class="form-control input"></select></td><td></td></tr>
<tr><td><b>RealGuitar MIDI Device</b></td><td><select id="midiFwdSel" type="text" class="form-control input"></select></td><td></td></tr>
<tr><td><b>RealGuitar Strum Pattern</b></td><td><select id="realguitar" type="text" class="form-control input"></select></td><td></td></tr>
<tr><td><b>Audio Device</b></td><td><select id="realInstrumentDevice" type="text" class="form-control input"></select></td><td></td></tr>
<tr><td><b>Input Audio Device</b></td><td><select id="inputAudioDevice" type="text" class="form-control input"></select></td><td></td></tr>
<tr><td><b>Output Audio Device</b></td><td><select id="outputAudioDevice" type="text" class="form-control input"></select></td><td></td></tr>
<tr><td><b>Audio Chord Loop</b></td><td><select id="realchordLoop" type="text" class="form-control input"></select></td><td></td></tr>
<tr><td><b>Audio Drum Loop</b></td><td><select id="realdrumLoop" type="text" class="form-control input"></select></td><td></td></tr>
<tr>
Expand Down
59 changes: 51 additions & 8 deletions docs/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ var realGuitarStyle = "none";
var midiOutput = null;
var input = null;
var midiRealGuitar = null;
var guitarDeviceId = null;
var padsDevice = null;
var padsInitialised = false;
var chordTracker = null;
Expand Down Expand Up @@ -936,7 +937,6 @@ function onloadHandler() {
let version = "latest";
if (!!chrome.runtime?.getManifest) version = chrome.runtime.getManifest().version;
document.title = "Orin Ayo | " + version;
setupPedalBoard(guitarContext);

playButton = document.querySelector(".play");
gamePadModeButton = document.querySelector(".gamepad_mode");
Expand Down Expand Up @@ -2209,6 +2209,7 @@ async function setupUI(config,err) {

statusMsg.innerHTML = "Orin Ayo";

//guitarDeviceId = config.guitarDeviceId;
guitarVolume = config.guitarVolume ? config.guitarVolume : guitarVolume;
keyChange = config.keyChange ? config.keyChange : keyChange;
dokeyChange();
Expand Down Expand Up @@ -2801,12 +2802,14 @@ async function setupUI(config,err) {
}
saveConfig();
});

const realDrumsDevice = document.getElementById("realInstrumentDevice");

const guitarDevice = document.getElementById("inputAudioDevice");
const realDrumsDevice = document.getElementById("outputAudioDevice");
const realDrumsLoop = document.getElementById("realdrumLoop");
const realChordsLoop = document.getElementById("realchordLoop");

realDrumsDevice.options[0] = new Option("**UNUSED**", "realDrumsDevice");

guitarDevice.options[0] = new Option("**UNUSED**", "guitarDevice", false, false);
realDrumsDevice.options[0] = new Option("**UNUSED**", "realDrumsDevice", false, false);
realDrumsLoop.options[0] = new Option("**UNUSED**", "realDrumsLoop", false, false);
realChordsLoop.options[0] = new Option("**UNUSED**", "realChordsLoop", false, false);

Expand Down Expand Up @@ -2925,6 +2928,39 @@ async function setupUI(config,err) {
audioMedia.getTracks().forEach( (track) => track.stop());
const devices = await navigator.mediaDevices.enumerateDevices();
const outputs = devices.filter(({ kind }) => kind === 'audiooutput');
const inputs = devices.filter(({ kind }) => kind === 'audioinput');

for (var i=0; i<inputs.length; i++) {
let selectedDevice = false;

if (config.guitarDeviceId && config.guitarDeviceId == inputs[i].deviceId) {
selectedDevice = true;
guitarDeviceId = inputs[i].deviceId;
}
guitarDevice.options[i + 1] = new Option(inputs[i].label, inputs[i].deviceId, selectedDevice, selectedDevice);
}

guitarDevice.addEventListener("change", async function()
{
guitarDeviceId = null;

if (guitarDevice.value != "guitarDevice") {
const audioMedia = await navigator.mediaDevices.getUserMedia({audio:true});
audioMedia.getTracks().forEach( (track) => track.stop());
const devices = await navigator.mediaDevices.enumerateDevices();
const inputs = devices.filter(({ kind }) => kind === 'audioinput');

for (let input of inputs)
{
if (guitarDevice.value == input.deviceId) {
guitarDeviceId = input.deviceId;
saveConfig();
break;
}
}
console.debug("selected guitar device ", guitarDevice, guitarDevice.value);
}
});

for (var i=0; i<outputs.length; i++) {
let selectedDevice = false;
Expand Down Expand Up @@ -3032,7 +3068,13 @@ async function setupUI(config,err) {

document.querySelector("#autoFill").checked = config.autoFill;
document.querySelector("#introEnd").checked = config.introEnd;

guitarReverb.checked = config.reverb;

if (guitarReverb.checked) {
setupPedalBoard(guitarContext, (guitarName == "none" || guitarDeviceId), guitarDeviceId);
}

microphone.checked = config.microphone;
document.querySelector("#program-change").checked = config.programChange;
document.querySelector("#volume").value = (config.guitarVolume || guitarVolume) * 100;
Expand Down Expand Up @@ -3270,6 +3312,7 @@ function saveConfig() {
config.realDrum = realInstrument?.drumUrl;
config.realChord = realInstrument?.chordUrl;
config.realdrumDevice = realdrumDevice ? realdrumDevice.deviceId : null;
config.guitarDeviceId = guitarDeviceId;
config.songName = songSequence ? songSequence.name : null;
config.arrName = arrSequence ? arrSequence.name : null;
config.sf2Name = arrSynth ? arrSynth.name : null;
Expand Down Expand Up @@ -3833,7 +3876,7 @@ function playChord(chord, root, type, bass) {
const key = "key" + arrChord + "_" + arrChordType + "_" + SECTION_IDS[sectionChange];
const bassKey = "key" + (chord[0] % 12) + "_" + arrChordType + "_" + SECTION_IDS[sectionChange];

if (guitarName != "none")
if (guitarName != "none" && !guitarDeviceId)
{
if (pad.axis[STRUM] == STRUM_UP || pad.axis[STRUM] == STRUM_DOWN)
{
Expand Down Expand Up @@ -4368,7 +4411,7 @@ function stopChord() {
if (midiOutput) outputStopNote(activeChord, [4], {velocity: getVelocity()});
if (!guitarAvailable && midiRealGuitar) midiRealGuitar.stopNote(activeChord, 1, {velocity: getVelocity()});
if (padsDevice?.stopNote || padsDevice?.name == "soundfont") stopPads();
if (guitarName != "none") player.cancelQueue(guitarContext);
if (guitarName != "none" && !guitarDeviceId) player.cancelQueue(guitarContext);

if (!guitarAvailable && midiRealGuitar)
{
Expand Down Expand Up @@ -4548,7 +4591,7 @@ function doChord() {
dokeyUp();
}

if (guitarName != "none" && (pad.axis[STRUM] == STRUM_UP || pad.axis[STRUM] == STRUM_DOWN) && padsMode != 0 && padsMode != 3 && padsMode != 4 && padsMode != 5) {
if (guitarName != "none" && !guitarDeviceId && (pad.axis[STRUM] == STRUM_UP || pad.axis[STRUM] == STRUM_DOWN) && padsMode != 0 && padsMode != 3 && padsMode != 4 && padsMode != 5) {
const arrChord = (firstChord.length == 4 ? firstChord[1] : firstChord[0]) % 12;
const guitarDuration = 240 / tempo;
player.queueSnap(guitarContext, guitarSource, midiGuitar, 0, getPitches(), guitarDuration, guitarVolume/4);
Expand Down

0 comments on commit 1787a1d

Please sign in to comment.