Music major scale converter

0 votes

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;
            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));
        }
Jun 11 in C# by pranav
• 2,320 points
8 views

1 answer to this question.

0 votes

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

    Console.ReadKey();
}
answered Jun 14 by krishna
• 1,340 points

Related Questions In C#

0 votes
1 answer

What is the best C# to VB.net converter

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

answered May 30 in C# by rajiv
• 1,620 points
20 views
0 votes
1 answer

What are major differences between C# and Java

Instead of listing out mutiple points, I ...READ MORE

answered Jun 9 in C# by rajiv
• 1,620 points
10 views
0 votes
3 answers

Trying to upload files using Selenium(C#)

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

answered Aug 23, 2019 in Selenium by Abha
• 28,100 points
4,468 views
0 votes
1 answer

Deploy my Windows 10 IOT core application locally!

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

answered Jul 17, 2018 in IoT (Internet of Things) by nirvana
• 3,130 points
499 views
+6 votes
16 answers

How do backend of these really cool games work?

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

answered Jul 19, 2018 in Career Counselling by Kalgi
• 52,350 points
7,253 views
0 votes
1 answer
0 votes
1 answer

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

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

answered Apr 18, 2018 in Blockchain by Perry
• 17,100 points
281 views
0 votes
1 answer

Can we scale Lambda functions for SNS trigger?

This doc should answer your first concern: ...READ MORE

answered Apr 20, 2018 in Cloud Computing by hemant
• 5,790 points
1,178 views
+1 vote
1 answer

How to fix java.lang.UnsupportedClassVersionError: Unsupported major.minor version

This error means you're trying to load ...READ MORE

answered Jun 8, 2018 in Java by Rishabh
• 3,620 points
2,025 views
0 votes
1 answer

How do I scale in Docker Swarm Mode W/Terraform Digital Ocean Load Balancing

The solution you could build for Digital ...READ MORE

answered Jun 19, 2018 in Docker by shubham
• 7,320 points
734 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP