i am trying to create music major scale converter. Dose anyone have info how do to it
so far i have
rootNote is scale base note like cMajor or gMajor note is note that i want to convert into major scale 0-126 if i insert rootNote 60 and note 60 the right return would be 0, if i insert rootNote 60 and note 61 the right return would be 2, if i insert rootNote 60 and note 62 the right return would be 4, if i insert rootNote 60 and note 63 the right return would be 5,
if i insert rootNote 61 and note 60 the right return would be 0, if i insert rootNote 61 and note 61 the right return would be 1, if i insert rootNote 61 and note 62 the right return would be 3, if i insert rootNote 61 and note 63 the right return would be 5,
ok i have this other one and it seems to work i want to map my sequence out put in major scale but is there some kind of formula what can i use?
.
public int getINMajorScale(int note, int rootNote)
{
List<int> majorScale = new List<int>();
//int bNo开发者_C百科te = (int)_bNote.CurrentValue;
int bNoteMpl = bNote / 12;
bNote = 12 + (bNote - (12 * bNoteMpl)) - 7;
majorScale.Add(bNote + (12 * bNoteMpl));
int tBnote = bNote;
int res = 0;
for (int i = bNote; i < bNote + 6; i++)
{
//algorytm
res = tBnote + 7;
int mod = 0;
if (res >= 12)
{
mod = res / 12;
res = res - 12 * mod;
}
tBnote = res;
majorScale.Add(res + (bNoteMpl * 12));
}
majorScale.Sort();
int modNuller = 0;
if (nmr >= 7)
{
modNuller = nmr / 7;
nmr = nmr - 7 * modNuller;
}
return (majorScale[nmr] + (modNuller *12));
}
but it's obviously faulty.
Problems with the code as it stands:
modScaling
does nothing more thanrootNote % 12
as you always pass in 0 and 11- You define
mNote
but never use it i
is never used in thefor
loop and so each of the 5 iterations prints the same thing.
OK, lets translate your examples into actual notes to make it easier to understand (numbers presumably correspond to MIDI notes):
rootNote = 60
(C),note = 60
(C) - output 0rootNote = 60
(C),note = 61
(C#) - output 2rootNote = 60
(C),note = 62
(D) - output 4rootNote = 60
(C),note = 63
(D#) - output 5rootNote = 61
(C#),note = 60
(C) - output 0rootNote = 61
(C#),note = 61
(C#) - output 1rootNote = 61
(C#),note = 62
(D) - output 3rootNote = 61
(C#),note = 63
(D#) - output 5
I might be being really dense but I'm afraid I can't see the pattern there.
A Major scale is of course made up of the sequence Tone, Tone, Semi-tone, Tone, Tone, Tone, Semi-tone, but how does that map to your outputs?
Given your input-outputs, I think I know what you are looking for.
- determine
steps
=note - rootNote
- determine
interval
= number of semi-tones betweenrootNote
and the notesteps
up the scale - determine
phase
=rootNote - 60
This algorithm provides accurate results:
static int getINMajorScale(int note, int rootNote)
{
if (note < rootNote) return 0;
var scale = new[] { 2, 2, 1, 2, 2, 2, 1 };
var phase = rootNote - 60;
var steps = note - rootNote;
var interval = steps == 0
? 0 : Enumerable.Range(0, steps).Sum(step => scale[step % scale.Length]);
var number = phase + interval;
return number;
}
yielding:
static void Main(string[] args)
{
//rootNote = 60(C), note = 60(C) - output 0
//rootNote = 60(C), note = 61(C#) - output 2
//rootNote = 60(C), note = 62(D) - output 4
//rootNote = 60(C), note = 63(D#) - output 5
//rootNote = 61(C#), note = 60 (C) - output 0
//rootNote = 61(C#), note = 61 (C#) - output 1
//rootNote = 61(C#), note = 62 (D) - output 3
//rootNote = 61(C#), note = 63 (D#) - output 5
Console.WriteLine(getINMajorScale(60, 60)); // 0
Console.WriteLine(getINMajorScale(61, 60)); // 2
Console.WriteLine(getINMajorScale(62, 60)); // 4
Console.WriteLine(getINMajorScale(63, 60)); // 5
Console.WriteLine(getINMajorScale(60, 61)); // 0
Console.WriteLine(getINMajorScale(61, 61)); // 1
Console.WriteLine(getINMajorScale(62, 61)); // 3
Console.WriteLine(getINMajorScale(63, 61)); // 5
Console.ReadKey();
}
精彩评论