Jump to content

Another way to write this?


Recommended Posts

Can I write this a different way?

var pitch1 = MIDI.noteNumber("c1");
var pitch2 = MIDI.noteNumber("c2");

 

For example, if I want to use the pitch values, for example 36 and 48?

I tried

var pitch1 = MIDI.noteName(36);
var pitch2 = MIDI.noteName(48);

 

and

 

var pitch1 = MIDI.noteName("36");
var pitch2 = MIDI.noteName("48");

 

but no luck...

I was reading this for clues, but I can't seem to make it work:

https://support.apple.com/guide/logicpro/use-the-javascript-midi-object-lgcebee22a60/10.6.2/mac/10.15.7

Link to comment
Share on other sites

the MIDI.noteNumber() function returns the note number matching the indicated pitch name string. If you already know the number you can just assign it like this:

 

var pitch1 = 36;
var pitch2 = 48;

 

 

But of course... duh! That was obvious haha My bad!

Thanks!

 

So how would you use MIDI.noteName in a particular situation?

Link to comment
Share on other sites

some people prefer to use the string note names. just depends. there is also a function for converting the other direction.

 

What I mean is that the code that I was given was

var pitch1 = MIDI.noteNumber("c1");

 

Can you give me an example of how you would use MIDI.noteName?

It seems that noteNumber uses the name of the note...

So how is noteName used?

Link to comment
Share on other sites

var name = MIDI.noteName(36);

 

or more likely you would be trying to get a string name from the actual event.

 

function HandleMIDI(event) {
   var name = MIDI.noteName(event.pitch);
   Trace(name);
}

 

 

Thing is, when I use that, it doesn't work.

Here's the whole code:

 

var pitch1 = MIDI.noteName(36);
var pitch2 = MIDI.noteName(48);

function HandleMIDI(event) {
   if(event instanceof Note) {
       if(event.pitch == pitch1) event.pitch = pitch2;
       else if(event.pitch == pitch2) event.pitch = pitch1;
   }
   event.send();
}

Link to comment
Share on other sites

The pitch value stored in Event objects and passed around is the number version of it. The only reason for getting the string name is to display it somewhere on the GUI, log it or perhaps if you want a script that will be easier to define the variables at the top by name, etc.. But any operations on Event objects should be using the pitch number.
Link to comment
Share on other sites

The pitch value stored in Event objects and passed around is the number version of it. The only reason for getting the string name is to display it somewhere on the GUI, log it or perhaps if you want a script that will be easier to define the variables at the top by name, etc.. But any operations on Event objects should be using the pitch number.

 

Hmmm ok. Note taken ;)

Thank you!

Link to comment
Share on other sites

The pitch value stored in Event objects and passed around is the number version of it. The only reason for getting the string name is to display it somewhere on the GUI, log it or perhaps if you want a script that will be easier to define the variables at the top by name, etc.. But any operations on Event objects should be using the pitch number.

 

 

If you don't mind and have the time, can you please check this script I created. My first one...

It's working and I think I've done everything as it should, but let me know what you think:

viewtopic.php?f=45&t=162689&p=853671#p853671

 

Thanks

Link to comment
Share on other sites

 Share

×
×
  • Create New...