Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #36293

Re: onMidiSuccess, "fake a midiMessage with mouse and charkeys", create a midiMessage object using mouse or keyboard"

Newsgroups comp.lang.javascript
Date 2019-04-01 04:13 -0700
References <b3e03db3-11de-4696-9a7a-038187855e6c@googlegroups.com> <926dc41f-0f92-49c2-be9a-233a6090e5cf@googlegroups.com>
Message-ID <62739a8b-b69d-4dcf-b306-63f0a245fdcb@googlegroups.com> (permalink)
Subject Re: onMidiSuccess, "fake a midiMessage with mouse and charkeys", create a midiMessage object using mouse or keyboard"
From Jonas Thörnvall <jonas.thornvall@gmail.com>

Show all headers | View raw


Den måndag 1 april 2019 kl. 12:56:35 UTC+2 skrev Jonas Thörnvall:
> Den måndag 1 april 2019 kl. 10:05:56 UTC+2 skrev Jonas Thörnvall:
> > If midiport initialisations goes well "success(midi) called", it will start listen to midi In port, and send each received message to a function celled onMIDIMessage.
> > 
> > function success(midi) {
> >   MidiPort=true;
> >   mid = midi;
> >   inputs = mid.inputs.values();
> >   // inputs outputs are Iterators
> >   for (input = inputs.next(); input && !input.done; input = inputs.next()) {
> >     //SEND EACH MIDI INPUT TO OUT
> >     console.log("going to playup midi message");
> >     input.value.onmidimessage = onMIDIMessage;
> >   }
> > }
> > 
> > So the message object is something the system create, when your keyboard generate a message for example keypress.
> > //MESSAGES SENT TO PORTS
> > function onMIDIMessage(message) {
> >   mess = message;
> >   clock = performance.now() - Rstarttime;
> >   if ((message.data[0] > 127 && message.data[0] < 166) || message.data[0] == 224 || message.data[0] == 176) {
> >     if (recordmidi) {
> >       console.log("I am recording");
> >       record(message);
> >     }     
> >     playbackPort(message);
> >     if(drawpiroll==true){
> >        pianoroll.push({
> >        time: clock,
> >        data0: message.data[0],
> >        data1: message.data[1],
> >        data2: message.data[2]
> >        });
> >     }
> >     if (SFLoad) {sf2synth(message);}
> >     if (echo) {
> >      echoNotesCanvas();
> >      checkMessageType();
> >     }
> >   } else {
> >      checkMessageType();
> >   }
> > }
> > 
> > 
> > Now you may want other input devices like mouse and keyboard and create a function to take care of it, and send messages to onMIDIMessage(message).
> > Problem is data the message object do not exist unless a midikey already been pressed. I want all messages to take same path weither they generated from midikeyboard, character keyboard or mouse.
> > 
> > So how can i "fake" generate the midiMessage object so it is not underfined, when using keyboard "message.data[0],messagee.data[1],message.data[2]" that is the object that a press on midikeyboard create.
> > 
> > ***UNDEFINED*** message object 
> > function playNote(A,B){
> > synth.NoteOn(143+channelTRX,A,B);
> > if (recordmidi) {
> >     clock = performance.now() - Rstarttime;
> >     clock = clock + rs;
> >     console.log("Clock="+clock);
> >     midievent++;
> >     message.data[0]=143+channelTRX; //UNDEFINED unless midikeboard created it
> >     message.data[1]=A;              //UNDEFINED 
> >     message.data[2]=B;              //UNDEFINED
> >     onMIDImessage(message);
> >    }
> > }
> 
> This is probably terrible programming practise beyondrepair but this is how i solved it.
> 
> function success(midi) {
>   mid = midi;
>   inputs = mid.inputs.values();
>   // inputs outputs are Iterators
>   for (input = inputs.next(); input && !input.done; input = inputs.next()) {
>     //SEND EACH MIDI INPUT TO OUT
>     console.log("going to playup midi message");
>     input.value.onmidimessage = onMIDIMessage;
>   }
> bigtest=onMIDIMessage;
> }
> 
> mymess = {
>   data : [],
> };
> 
> function playNote(A,B){
> synth.NoteOn(143+channelTRX,A,B);
> if (recordmidi) {
>     clock = performance.now() - Rstarttime;
>     clock = clock + rs;
>     console.log("Clock="+clock);
>     midievent++;
>     mymess.data[0]=143+channelTRX;
>     mymess.data[1]=A;
>     mymess.data[2]=B;
>     bigtest(mymess);
>    }
> }
> 
> How would a real programmer done it LoL
Try record from keyboard and drummachine on "different tracks". 
http://anybase.co.nf

Back to comp.lang.javascript | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

onMidiSuccess, "fake a midiMessage with mouse and charkeys", create a midiMessage object using mouse or keyboard" Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-04-01 01:05 -0700
  Re: onMidiSuccess, "fake a midiMessage with mouse and charkeys", create a midiMessage object using mouse or keyboard" Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-04-01 03:32 -0700
    Re: onMidiSuccess, "fake a midiMessage with mouse and charkeys", create a midiMessage object using mouse or keyboard" "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2019-04-01 15:31 +0200
      Re: onMidiSuccess, "fake a midiMessage with mouse and charkeys", create a midiMessage object using mouse or keyboard" Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-04-01 09:09 -0700
        Re: onMidiSuccess, "fake a midiMessage with mouse and charkeys", create a midiMessage object using mouse or keyboard" "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2019-04-01 23:38 +0200
          Re: onMidiSuccess, "fake a midiMessage with mouse and charkeys", create a midiMessage object using mouse or keyboard" Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-04-02 11:07 -0700
            Re: onMidiSuccess, "fake a midiMessage with mouse and charkeys", create a midiMessage object using mouse or keyboard" "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2019-04-02 23:21 +0200
              Re: onMidiSuccess, "fake a midiMessage with mouse and charkeys", create a midiMessage object using mouse or keyboard" "Mark-" <nospam@mapson.xyz> - 2019-04-03 00:35 +0000
                Re: onMidiSuccess, "fake a midiMessage with mouse and charkeys", create a midiMessage object using mouse or keyboard" "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2019-04-03 10:56 +0200
                Re: onMidiSuccess, "fake a midiMessage with mouse and charkeys", create a midiMessage object using mouse or keyboard" "Mark-" <nospam@mapson.xyz> - 2019-04-03 13:17 +0000
                Re: onMidiSuccess, "fake a midiMessage with mouse and charkeys", create a midiMessage object using mouse or keyboard" "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2019-04-03 18:41 +0200
                Re: onMidiSuccess, "fake a midiMessage with mouse and charkeys", create a midiMessage object using mouse or keyboard" "Mark-" <nospam@mapson.xyz> - 2019-04-03 16:52 +0000
                Re: onMidiSuccess, "fake a midiMessage with mouse and charkeys", create a midiMessage object using mouse or keyboard" "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2019-04-03 22:54 +0200
                Re: onMidiSuccess, "fake a midiMessage with mouse and charkeys", create a midiMessage object using mouse or keyboard" "Mark-" <nospam@mapson.xyz> - 2019-04-03 21:35 +0000
                Re: onMidiSuccess, "fake a midiMessage with mouse and charkeys", create a midiMessage object using mouse or keyboard" Flng Fck <nothanks@invalid.invalid> - 2019-04-04 08:35 +0200
                Re: onMidiSuccess, "fake a midiMessage with mouse and charkeys", create a midiMessage object using mouse or keyboard" "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2019-04-04 09:59 +0200
                Re: onMidiSuccess, "fake a midiMessage with mouse and charkeys", create a midiMessage object using mouse or keyboard" Flng Fck <nothanks@invalid.invalid> - 2019-04-04 10:05 +0200
                Re: onMidiSuccess, "fake a midiMessage with mouse and charkeys", create a midiMessage object using mouse or keyboard" Gene Wirchenko <genew@telus.net> - 2019-04-04 10:27 -0700
                Re: onMidiSuccess, "fake a midiMessage with mouse and charkeys", create a midiMessage object using mouse or keyboard" "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2019-04-04 22:21 +0200
                Re: onMidiSuccess, "fake a midiMessage with mouse and charkeys", create a midiMessage object using mouse or keyboard" John G Harris <niam@jghnorth.org.uk.invalid> - 2019-04-04 20:02 +0100
  Re: onMidiSuccess, "fake a midiMessage with mouse and charkeys", create a midiMessage object using mouse or keyboard" Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-04-01 03:56 -0700
    Re: onMidiSuccess, "fake a midiMessage with mouse and charkeys", create a midiMessage object using mouse or keyboard" Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-04-01 04:13 -0700

csiph-web