What is the most efficient way to populate an array based on other information in Javascript? -
I have a note of size 16 in javascript. I have a static 2D array called Tip 11x12 NotoAnmelmapping. Now, in the form of input, I select the user to select any combination of 12 standard notes (C-C # -D-D # -EFF -G-G # -a-A-B-B) I do not, nor at all. Such as "CGG #", or "DD #GAB", or blank etc. PS: For example, I would like to refer to the 2D array and see if Oct. The corresponding numbers for C, G and G # are 0, 7 and 8. Similarly, for October 1, the numbers are 12, 19 and 20. In this fashion continuously, the first 16 numbers are: 0, 7, 8, 12, 19, 20, 24, 31, 32, 36, 43, 44 , 48, 55, 56, 60. >
I would like to specify these 16 numbers in my initial note array.
My approach
I have implemented the 2D array as a 1D array 128 items, where the letter contains the item was 0C All items from item 1 to C # 0 until item 127 (G10) I wanted to use the fact that in the 2D table there was a linear progress from the value 1-127. But I ended up with a nested 3 for the loop and still could not get it to work. What would be an effective way to achieve this in javascript?
You can create a lookup table with the first note Name of the relative note number:
< , 'F': 5, 'F': 5, 'F': 5, 'F': 5, 'F': 5, 'F # ': 6,' G ': 7,' G # ': 8,' A ': 9,' A # ': 10,' B ': 11};Then you can get note numbers relative to the selected notes relatively easily:
var selectedNotes = 'C G G #'; Var relativeNoteNumbers = selectedNotes.split ('') .filter (function (note) {return note}) // Remove spaces .map (function (note) {note note the relative note note number [note]}); Console.log (relativeNoteNumbers); // [0, 7, 8]
Observe that for every octave, the MIDI note increases by 12. If you want those notes for every Oct for up to 16 notes, you can do something like this:
var notes = []; While (notes length & lt; 16) {notes.push (Math.flur (Notes .length / relative not notes length) * 12+ relative notes [notes.lang% relative notes].);; }
Comments
Post a Comment