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

Danny Wyatt (formerly known as 3ple here on the forum)
Musician, Music Producer, Songwriter, DJ
Official Website: http://www.iamdannywyatt.com  - Join my Discord: https://dwyatt.me/discord

Logic Pro 10.6.3 • M-Audio Fast Track Pro 4x4 • MacBook Pro 13" Mid 2012 || 2.5 GHz Dual-Core Intel Core i5 || 8GB 1600 MHz DDR3 RAM • macOS Catalina 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;

OSX 12.x (Monterey) on OpenCore - Logic Pro 10.7.4, VePro7, Mainstage3 - 5,1 MacPro 3.46ghz x 12 96gb ram

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?

Danny Wyatt (formerly known as 3ple here on the forum)
Musician, Music Producer, Songwriter, DJ
Official Website: http://www.iamdannywyatt.com  - Join my Discord: https://dwyatt.me/discord

Logic Pro 10.6.3 • M-Audio Fast Track Pro 4x4 • MacBook Pro 13" Mid 2012 || 2.5 GHz Dual-Core Intel Core i5 || 8GB 1600 MHz DDR3 RAM • macOS Catalina 10.15.7

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?

Danny Wyatt (formerly known as 3ple here on the forum)
Musician, Music Producer, Songwriter, DJ
Official Website: http://www.iamdannywyatt.com  - Join my Discord: https://dwyatt.me/discord

Logic Pro 10.6.3 • M-Audio Fast Track Pro 4x4 • MacBook Pro 13" Mid 2012 || 2.5 GHz Dual-Core Intel Core i5 || 8GB 1600 MHz DDR3 RAM • macOS Catalina 10.15.7

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);
}

OSX 12.x (Monterey) on OpenCore - Logic Pro 10.7.4, VePro7, Mainstage3 - 5,1 MacPro 3.46ghz x 12 96gb ram

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();
}

Danny Wyatt (formerly known as 3ple here on the forum)
Musician, Music Producer, Songwriter, DJ
Official Website: http://www.iamdannywyatt.com  - Join my Discord: https://dwyatt.me/discord

Logic Pro 10.6.3 • M-Audio Fast Track Pro 4x4 • MacBook Pro 13" Mid 2012 || 2.5 GHz Dual-Core Intel Core i5 || 8GB 1600 MHz DDR3 RAM • macOS Catalina 10.15.7

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.

OSX 12.x (Monterey) on OpenCore - Logic Pro 10.7.4, VePro7, Mainstage3 - 5,1 MacPro 3.46ghz x 12 96gb ram

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!

Danny Wyatt (formerly known as 3ple here on the forum)
Musician, Music Producer, Songwriter, DJ
Official Website: http://www.iamdannywyatt.com  - Join my Discord: https://dwyatt.me/discord

Logic Pro 10.6.3 • M-Audio Fast Track Pro 4x4 • MacBook Pro 13" Mid 2012 || 2.5 GHz Dual-Core Intel Core i5 || 8GB 1600 MHz DDR3 RAM • macOS Catalina 10.15.7

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

Danny Wyatt (formerly known as 3ple here on the forum)
Musician, Music Producer, Songwriter, DJ
Official Website: http://www.iamdannywyatt.com  - Join my Discord: https://dwyatt.me/discord

Logic Pro 10.6.3 • M-Audio Fast Track Pro 4x4 • MacBook Pro 13" Mid 2012 || 2.5 GHz Dual-Core Intel Core i5 || 8GB 1600 MHz DDR3 RAM • macOS Catalina 10.15.7

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...