experchange > javascript

Jonas Thörnvall (09-22-18, 11:16 AM)
I have a track array and try to do an elementary eventeditor, and i managed to remove elements using

track[recTrack].midiMess.splice(trackEvent,1);

But when i try to insert a new element "objects" into array i fail.
Is there something i miss, because it tells me undefined?

track[recTrack].midiMess.data0.splice(trackEvent,0,"144"); //Well how?
track[recTrack].midiMess.data1.splice(trackEvent,0,insnote);
track[recTrack].midiMess.data2.splice(trackEvent,0,insvel);
Julio Di Egidio (09-22-18, 11:45 AM)
On Saturday, 22 September 2018 11:17:06 UTC+2, Jonas Thörnvall wrote:

> track[recTrack].midiMess.splice(trackEvent,1);
> track[recTrack].midiMess.data0.splice(trackEvent,0,"144"); //Well how?


> Is there something i miss, because it tells me undefined?


What tells you undefined?? You should get a JS error saying reference undefined or null or something, and where. Note that your sloppiness is
our extra effort...

That said, I just note that above you are splicing midiMess, below you are
splicing midiMess.dataN. Does that make sense?

Julio
Jonas Thörnvall (09-22-18, 12:07 PM)
Den lördag 22 september 2018 kl. 11:45:11 UTC+2 skrev Julio Di Egidio:
> On Saturday, 22 September 2018 11:17:06 UTC+2, Jonas Thörnvall wrote:
> What tells you undefined?? You should get a JS error saying reference undefined or null or something, and where. Note that your sloppiness is
> our extra effort...
> That said, I just note that above you are splicing midiMess, below you are
> splicing midiMess.dataN. Does that make sense?
> Julio


I think so? This is my track object.

function newTrack(m) {
track[m] ={
outport:[],
portname : [],
midichannel:[],
program:[],
midiMess:[],
//CONFIGURATION OF midiMess:[{time:0,data0:0,data1:0,data2:0}]
};
return track;
}

Here is how i update the track.
track[tracknr].midiMess.push({time:clock,data0:message.data[0],data1:message.data[1],data2:message.data[2]});
}

I mean it make sense to remove the full object "Event element" midiMess.
But thought i could splice objects of midiMess one at a time, but maybe i must update them all like when doing push new object?
Jonas Thörnvall (09-22-18, 12:09 PM)
Den lördag 22 september 2018 kl. 12:07:09 UTC+2 skrev Jonas Thörnvall:
[..]
> }
> I mean it make sense to remove the full object "Event element" midiMess.
> But thought i could splice objects of midiMess one at a time, but maybe imust update them all like when doing push new object?


track[tracknr].midiMess.splice({time:clock,data0:message.data[0],data1:message.data[1],data2:message.data[2]});

?
Jonas Thörnvall (09-22-18, 12:15 PM)
Den lördag 22 september 2018 kl. 12:09:57 UTC+2 skrev Jonas Thörnvall:
> Den lördag 22 september 2018 kl. 12:07:09 UTC+2 skrev Jonas Thörnvall:
> track[tracknr].midiMess.splice({time:clock,data0:message.data[0],data1:message.data[1],data2:message.data[2]});
> ?

Uncaught TypeError: Cannot read property 'splice' of undefined
at noteInsert (listtrack.js:12)
at HTMLButtonElement.onclick (midi.html:133)
Jonas Thörnvall (09-22-18, 12:24 PM)
Den lördag 22 september 2018 kl. 12:07:09 UTC+2 skrev Jonas Thörnvall:
[..]
> }
> I mean it make sense to remove the full object "Event element" midiMess.
> But thought i could splice objects of midiMess one at a time, but maybe imust update them all like when doing push new object?


Well this is what i mean it is all so fucking confusing?
Why isn't the syntax straightforward?
In a sain uninverse the syntax would be.
track[recTrack].midiMess[trackEvent].data0.splice(0,144);

Shouldn't it??????
Jonas Thörnvall (09-22-18, 12:28 PM)
Den lördag 22 september 2018 kl. 12:24:46 UTC+2 skrev Jonas Thörnvall:
> Den lördag 22 september 2018 kl. 12:07:09 UTC+2 skrev Jonas Thörnvall:
> Well this is what i mean it is all so fucking confusing?
> Why isn't the syntax straightforward?
> In a sain uninverse the syntax would be.
> track[recTrack].midiMess[trackEvent].data0.splice(0,144);
> Shouldn't it??????


So what is the syntax?
Julio Di Egidio (09-22-18, 12:40 PM)
On Saturday, 22 September 2018 12:24:46 UTC+2, Jonas Thörnvall wrote:
> Den lördag 22 september 2018 kl. 12:07:09 UTC+2 skrev Jonas Thörnvall:


> > I mean it make sense to remove the full object "Event element" midiMess..
> > But thought i could splice objects of midiMess one at a time, but maybeI
> > must update them all like when doing push new object?


Splice is defined for arrays, not for objects. To "update" objects, you just
assign values to their properties, e.g.:

rack[recTrack].midiMess[trackEvent].data0 = "144";

(or, 144: you keep mixing them by they are not the same...)

> Well this is what i mean it is all so fucking confusing?


No programmer has ever said programming is easy: in fact, by simple trial
and error, it's rather guaranteed you'll be forever a crank...

HTH,

Julio
Jonas Thörnvall (09-22-18, 12:43 PM)
Den lördag 22 september 2018 kl. 12:28:46 UTC+2 skrev Jonas Thörnvall:
> Den lördag 22 september 2018 kl. 12:24:46 UTC+2 skrev Jonas Thörnvall:
> So what is the syntax?


It all become guess work to me, i can guess?

track[tracknr].midiMess.push(trackEvent,0,{time:clock,data0:mess age.data[0],data1:message.data[1],data2:message.data[2]})
;

Well i will try.
Jonas Thörnvall (09-22-18, 12:47 PM)
Den lördag 22 september 2018 kl. 12:40:47 UTC+2 skrev Julio Di Egidio:
> On Saturday, 22 September 2018 12:24:46 UTC+2, Jonas Thörnvall wrote:
> Splice is defined for arrays, not for objects. To "update" objects, you just
> assign values to their properties, e.g.:
> rack[recTrack].midiMess[trackEvent].data0 = "144";
> (or, 144: you keep mixing them by they are not the same...)
> No programmer has ever said programming is easy: in fact, by simple trial
> and error, it's rather guaranteed you'll be forever a crank...
> HTH,
> Julio


Well that is not an insert Julio....
So you say one can't do it, using splice?
Not even something like
track[tracknr].midiMess.splice(trackEvent,0,{time:clock,data0:me ssage.data[0],data1:message.data[1],data2:message.data[2]})

Or?
;
Jonas Thörnvall (09-22-18, 01:00 PM)
Den lördag 22 september 2018 kl. 12:40:47 UTC+2 skrev Julio Di Egidio:
> On Saturday, 22 September 2018 12:24:46 UTC+2, Jonas Thörnvall wrote:
> Splice is defined for arrays, not for objects. To "update" objects, you just
> assign values to their properties, e.g.:
> rack[recTrack].midiMess[trackEvent].data0 = "144";
> (or, 144: you keep mixing them by they are not the same...)
> No programmer has ever said programming is easy: in fact, by simple trial
> and error, it's rather guaranteed you'll be forever a crank...
> HTH,
> Julio


Well anyhow apparently my guess was close enough, it worked.
track[tracknr].midiMess.splice(trackEvent,0,{time:instime,data0: 144,data1:insnote,data2:insvel});
What does the curled brackets denote here that it is an object or?
Julio Di Egidio (09-22-18, 01:00 PM)
On Saturday, 22 September 2018 12:47:10 UTC+2, Jonas Thörnvall wrote:

> Well that is not an insert Julio....


Well, sorry for not guessing what you meant, idiot.

> track[tracknr].midiMess.splice(trackEvent, 0, { time: clock, data0:
> message.data[0], data1 :message.data[1], data2: message.data[2] })


(Use spacing appropriately, all the more so when you are a fucking rookie.)

And now what's wrong with that, you bloody spammer?? A rethorical question,
this is simply the last time I waste my time on you, promised...

*Plonk*

Julio
Jonas Thörnvall (09-22-18, 01:02 PM)
Den lördag 22 september 2018 kl. 13:00:40 UTC+2 skrev Julio Di Egidio:
> On Saturday, 22 September 2018 12:47:10 UTC+2, Jonas Thörnvall wrote:
> Well, sorry for not guessing what you meant, idiot.
> (Use spacing appropriately, all the more so when you are a fucking rookie..)
> And now what's wrong with that, you bloody spammer?? A rethorical question,
> this is simply the last time I waste my time on you, promised...
> *Plonk*
> Julio


"But when i try to insert a new element "objects" into array i fail.
Is there something i miss, because it tells me undefined? "
Jonas Thörnvall (09-22-18, 01:03 PM)
Den lördag 22 september 2018 kl. 13:00:40 UTC+2 skrev Julio Di Egidio:
> On Saturday, 22 September 2018 12:47:10 UTC+2, Jonas Thörnvall wrote:
> Well, sorry for not guessing what you meant, idiot.
> (Use spacing appropriately, all the more so when you are a fucking rookie..)
> And now what's wrong with that, you bloody spammer?? A rethorical question,
> this is simply the last time I waste my time on you, promised...
> *Plonk*
> Julio


I am far to stupid to get offended, by foul words Julio LoL, nah i just keep going...

You know the little train that could LoL
Julio Di Egidio (09-22-18, 01:09 PM)
On Saturday, 22 September 2018 13:03:46 UTC+2, Jonas Thörnvall wrote:

> I am far to stupid to get offended, by foul words Julio


Idiot, rookie and spammer are not foul words, Jonas.

But I do wish I knew better English: I am going to learn some legalese...

*Plonk*

Julio