Вызываю функцию addListener из библиотеки WebMidi, третий параметр называется 'listener'. Требуется, чтобы этот параметр был функцией (В моём случае это readByKey(keyPress)
)
WebMidi.inputs[0].addListener('noteon', "all", readByKey(keyPress));
async function readByKey(keyPress) { //Key press handler (Gets data about the key pressed and reads project file)
await $.getJSON("project.json", function (proj) { //Getting the project
project = proj;
console.log(project);
});
var frame = 1; //Resetting to the 1st frame (because we want to read from the first frame, not some random value)
if (typeof keyPress != null && typeof project != null) { //Making sure everything is downloaded
do { //
switch (project["1"]["1"][keyPress.note.number][frame].act) { //Checks the action on some [frame] and acts accordingly
case "an": //"an" stands for "animation"
output.playNote(project["1"]["1"][keyPress.note.number][frame].n, { rawVelocity: 1, velocity: project["1"]["1"][keyPress.note.number][frame].v, time: project["1"]["1"][keyPress.note.number][frame].t });
break;
}
frame++;
} while (project["1"]["1"]["11"][frame].act !== "sa") // "an" stands for "animation", "sa" for "stop animation"
}
}
Я не понимаю почему моя функция не считается функцией. Есть идеи?
readByKey
на синхронный лад.readByKey
, то есть Promise.