I'm trying to make a major scale converter for music. Is there anyone who knows how to do it?

So far, I've this

rootNote is a scale base note, such as cMajor or gMajor, that I want to convert to a major scale from 0-126. If I put rootNote 60 and note 60 together, the right return is 0, if I put rootNote 60 and note 61 together, the right return is 2, if I put rootNote 60 and note 62 together, the right return is 4, and if I put rootNote 60 and note 63 together, the right return is 5.

If I put rootNote 61 and note 60 together, the right return is 0, but if I put rootNote 61 and note 61 together, the right return is 1. If I put rootNote 61 and note 62 together, the right return is 3, and if I put rootNote 61 and note 63 together, the right return is 5.

Okay, I have this other one, and it appears to function. I'd like to lay out my sequence in major scale, but is there a formula I can use? This isn't working

```public int getINMajorScale(int note, int rootNote)
{

List<int> majorScale = new List<int>();
//int bNote = (int)_bNote.CurrentValue;

int bNoteMpl = bNote / 12;
bNote = 12 + (bNote - (12 * bNoteMpl)) - 7;
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.Sort();
int modNuller = 0;
if (nmr >= 7)
{
modNuller = nmr / 7;
nmr = nmr - 7 * modNuller;
}
return (majorScale[nmr] + (modNuller *12));
}```
Jun 11 in C# 13 views

## 1 answer to this question.

I believe I know what you're looking for based on your input-output data.

1. Identify the steps = rootNote
2. Determine the interval between the rootNote and the note steps up the scale (number of semitones).
3. find the phase of the rootNote - 60

This algorithm yields precise 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;
} ```

Giving:

```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

}```
• 2,340 points

## What is the best C# to VB.net converter

Telerik has a solid SharpDevelop-based converter that ...READ MORE

## Trying to upload files using Selenium(C#)

You can try using Javascript Executor to ...READ MORE

## Deploy my Windows 10 IOT core application locally!

Of course, you, can! That is, in ...READ MORE

## How do backend of these really cool games work?

Most of the games these days don't ...READ MORE

## SQLite.Net not being able to create text file in Win IoT Library!

That exception comes when access limited to ...READ MORE

## How secure is to implement blockchain at a smaller scale??

Blockchain relies on the number of nodes ...READ MORE

+1 vote