Old 06-06-2019, 05:02 AM   #1
MusoBob
Human being with feelings
 
MusoBob's Avatar
 
Join Date: Sep 2014
Posts: 840
Default Midi Note Name & Octave to Note Number

In Reaper I can find mute midi note but not lock midi note from transpose (but still move left/right).

I just have user input for start note and end note


end note F0
start note C0

and need to convert to note numbers in Lua.

This will exempt the keyswitch notes from being snapped to chord or scale.
__________________
ReaTrakStudio Chord Track for Reaper forum
www.reatrak.com
MusoBob is offline   Reply With Quote
Old 06-06-2019, 12:08 PM   #2
MusoBob
Human being with feelings
 
MusoBob's Avatar
 
Join Date: Sep 2014
Posts: 840
Default

I found this in Java note number to note name, I will try and work it out to Lua note name to note number, but if anyone already has the answer that would help.


Code:
octave = int (notenum / 12) - 1; 
note = substring("C C#D D#E F F#G G#A A#B ",(notenum % 12) * 2, 2);
EDIT: more
Code:
public static String getNoteName(int noteNumber){
    noteNumber -= 21; // see the explanation below.
    String[] notes = new String[] {"A", "A#", "B", "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#"};
    int octave = noteNumber / 12 + 1;
    String name = notes[noteNumber % 12];
    return name + octave;
}
Explanation:
  • A0 in midi is the first note and its number is 21. We adjust the index to start from 0 (hence noteNumber -= 21; at the beginning). If your note numbers are 0 based, for example in piano from 0 to 88, then you can comment this line out.
  • Note that in this solution, the note names in the array start from A to G.
  • Octave is noteNumber / 12 + 1 (Or ceiling of num / 12).
  • Note name index is noteNumber % 12.
__________________
ReaTrakStudio Chord Track for Reaper forum
www.reatrak.com

Last edited by MusoBob; 06-06-2019 at 01:00 PM.
MusoBob is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 03:53 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.