Exemple #1
0
        /// <summary>
        /// 주어진 화음과 자연스럽게 이어지도록 새 화음을 초기화합니다.
        /// </summary>
        /// <param name="c"></param>
        public Chord(Form1.Theme theme, Chord c)
        {
            Random r = new Random();
            int    rand;
            int    oldP, p;

            switch (theme)
            {
            case Form1.Theme.Autumn:
                #region Autumn Chord
                maxOctave = 5;
                minOctave = 4;
                rand      = r.Next(17);
                switch (rand)
                {
                case 1:
                case 2:
                case 3:
                case 4:
                case 5:
                    type = Type.Major;
                    break;

                case 8:
                case 9:
                case 10:
                    type = Type.minor;
                    break;

                case 11:
                    type = Type.sus2;
                    break;

                case 12:
                case 13:
                    type = Type.sus4;
                    break;

                case 14:
                case 6:
                    type = Type.M7;
                    break;

                case 15:
                case 7:
                    type = Type.m7;
                    break;

                default:
                    type = c.type;
                    break;
                }

                //root = (Root)r.Next(12);
                rand = r.Next(10);
                switch (rand)
                {
                case 1:
                case 2:
                case 3:
                    root = c.root;
                    break;

                case 4:
                case 5:
                case 6:
                    root = (Root)(((int)c.root + 7) % 12);
                    break;

                case 7:
                case 8:
                case 9:
                    root = (Root)(((int)c.root + 5) % 12);
                    break;

                case 10:
                    if (c.type == Type.Major)
                    {
                        root = (Root)(((int)c.root - 3) % 12);
                        type = Type.minor;
                    }
                    else if (c.type == Type.minor)
                    {
                        root = (Root)(((int)c.root + 3) % 12);
                        type = Type.Major;
                    }
                    else if (c.type == Type.dim)
                    {
                        type = c.type;
                        rand = r.Next(2);
                        if (rand == 0)
                        {
                            root = (Root)(((int)c.root + 3) % 12);
                        }
                        else
                        {
                            root = (Root)(((int)c.root - 3) % 12);
                        }
                    }
                    else if (c.type == Type.aug)
                    {
                        type = c.type;
                        rand = r.Next(2);
                        if (rand == 0)
                        {
                            root = (Root)(((int)c.root + 4) % 12);
                        }
                        else
                        {
                            root = (Root)(((int)c.root - 4) % 12);
                        }
                    }
                    else
                    {
                        rand = r.Next(2);
                        if (rand == 0)
                        {
                            root = (Root)(((int)c.root + 3) % 12);
                            type = Type.Major;
                        }
                        else
                        {
                            root = (Root)(((int)c.root - 3) % 12);
                            type = Type.minor;
                        }
                    }
                    break;

                default:            // Unused
                    root = (Root)r.Next(12);
                    break;
                }

                rand   = r.Next(15);
                octave = c.octave;
                switch (rand)
                {
                case 0:
                    octave -= 1;
                    if (octave < minOctave)
                    {
                        octave = minOctave + 1;
                    }
                    break;

                case 1:
                case 2:
                case 3:
                    octave -= 1;
                    if (octave < minOctave)
                    {
                        octave = minOctave;
                    }
                    break;

                case 4:
                case 5:
                case 6:
                case 7:
                case 8:
                case 9:
                case 10:
                case 11:
                    break;

                case 12:
                case 13:
                case 14:
                    octave += 1;
                    if (octave > maxOctave)
                    {
                        octave = maxOctave;
                    }
                    break;

                default:
                    octave += 1;
                    if (octave > maxOctave)
                    {
                        octave = maxOctave - 1;
                    }
                    break;
                }
                if (octave > maxOctave)
                {
                    octave = maxOctave;
                }
                if (octave < minOctave)
                {
                    octave = minOctave;
                }

                oldP = (int)c.root + c.octave * 12;
                p    = (int)root + octave * 12;
                while (oldP + 12 < p)
                {
                    octave--;
                    p = (int)root + octave * 12;
                }
                while (oldP - 12 > p)
                {
                    octave++;
                    p = (int)root + octave * 12;
                }
                if (octave > maxOctave)
                {
                    octave = maxOctave;
                }
                if (octave < minOctave)
                {
                    octave = minOctave;
                }

                break;

                #endregion
            case Form1.Theme.Rain:
                #region Rain Chord
                maxOctave = 8;
                minOctave = 5;
                rand      = r.Next(17);
                switch (rand)
                {
                case 1:
                case 2:
                case 3:
                case 4:
                    type = Type.minor;
                    break;

                case 5:
                case 6:
                    type = Type.m7;
                    break;

                case 7:
                    type = Type.Major;
                    break;

                case 8:
                case 9:
                case 10:
                    type = Type.M7;
                    break;

                case 11:
                    type = Type.sus2;
                    break;

                case 12:
                case 13:
                    type = Type.sus4;
                    break;

                case 14:
                    type = Type.aug;
                    break;

                case 15:
                    type = Type.dim;
                    break;

                default:
                    type = c.type;
                    break;
                }

                //root = (Root)r.Next(12);
                rand = r.Next(10);
                switch (rand)
                {
                case 1:
                case 2:
                case 3:
                    root = c.root;
                    break;

                case 4:
                case 5:
                case 6:
                    root = (Root)(((int)c.root + 7) % 12);
                    break;

                case 7:
                case 8:
                case 9:
                    root = (Root)(((int)c.root + 5) % 12);
                    break;

                case 10:
                    if (c.type == Type.Major)
                    {
                        root = (Root)(((int)c.root - 3) % 12);
                        type = Type.minor;
                    }
                    else if (c.type == Type.minor)
                    {
                        root = (Root)(((int)c.root + 3) % 12);
                        type = Type.Major;
                    }
                    else if (c.type == Type.dim)
                    {
                        type = c.type;
                        rand = r.Next(2);
                        if (rand == 0)
                        {
                            root = (Root)(((int)c.root + 3) % 12);
                        }
                        else
                        {
                            root = (Root)(((int)c.root - 3) % 12);
                        }
                    }
                    else if (c.type == Type.aug)
                    {
                        type = c.type;
                        rand = r.Next(2);
                        if (rand == 0)
                        {
                            root = (Root)(((int)c.root + 4) % 12);
                        }
                        else
                        {
                            root = (Root)(((int)c.root - 4) % 12);
                        }
                    }
                    else
                    {
                        rand = r.Next(2);
                        if (rand == 0)
                        {
                            root = (Root)(((int)c.root + 3) % 12);
                            type = Type.Major;
                        }
                        else
                        {
                            root = (Root)(((int)c.root - 3) % 12);
                            type = Type.minor;
                        }
                    }
                    break;

                default:            // Unused
                    root = (Root)r.Next(12);
                    break;
                }

                rand   = r.Next(15);
                octave = c.octave;
                switch (rand)
                {
                case 0:
                    octave -= 1;
                    if (octave < minOctave)
                    {
                        octave = minOctave + 1;
                    }
                    break;

                case 1:
                case 2:
                case 3:
                    octave -= 1;
                    if (octave < minOctave)
                    {
                        octave = minOctave;
                    }
                    break;

                case 4:
                case 5:
                case 6:
                case 7:
                case 8:
                case 9:
                case 10:
                case 11:
                    break;

                case 12:
                case 13:
                case 14:
                    octave += 1;
                    if (octave > maxOctave)
                    {
                        octave = maxOctave;
                    }
                    break;

                default:
                    octave += 1;
                    if (octave > maxOctave)
                    {
                        octave = maxOctave - 1;
                    }
                    break;
                }
                if (octave > maxOctave)
                {
                    octave = maxOctave;
                }
                if (octave < minOctave)
                {
                    octave = minOctave;
                }

                oldP = (int)c.root + c.octave * 12;
                p    = (int)root + octave * 12;
                while (oldP + 12 < p)
                {
                    octave--;
                    p = (int)root + octave * 12;
                }
                while (oldP - 12 > p)
                {
                    octave++;
                    p = (int)root + octave * 12;
                }
                if (octave > maxOctave)
                {
                    octave = maxOctave;
                }
                if (octave < minOctave)
                {
                    octave = minOctave;
                }

                break;

                #endregion
            case Form1.Theme.Star:
                #region Star Chord
                maxOctave = 8;
                minOctave = 5;
                switch (c.type)
                {
                case Type.Major:
                case Type.M7:
                    rand = r.Next(8);
                    switch (rand)
                    {
                    case 0:
                        root = (Root)(((int)c.root - 3) % 12);
                        type = Type.minor;
                        break;

                    case 1:
                        root = c.root;
                        type = Type.aug;
                        break;

                    case 2:
                        root = (Root)(((int)c.root + 1) % 12);
                        type = Type.dim;
                        break;

                    case 3:
                        root = (Root)(((int)c.root + 4) % 12);
                        type = Type.dim;
                        break;

                    case 4:
                        root = (Root)(((int)c.root + 4) % 12);
                        type = Type.minor;
                        break;

                    case 5:
                        root = c.root;
                        type = Type.minor;
                        break;

                    case 6:
                        root = c.root;
                        type = Type.sus2;
                        break;

                    case 7:
                        root = c.root;
                        type = Type.sus4;
                        break;
                    }
                    break;

                case Type.minor:
                case Type.m7:
                    rand = r.Next(8);
                    switch (rand)
                    {
                    case 0:
                        root = c.root;
                        type = Type.dim;
                        break;

                    case 1:
                        root = (Root)(((int)c.root - 4) % 12);
                        type = Type.Major;
                        break;

                    case 2:
                        root = (Root)(((int)c.root - 3) % 12);
                        type = Type.dim;
                        break;

                    case 3:
                        root = (Root)(((int)c.root + 3) % 12);
                        type = Type.Major;
                        break;

                    case 4:
                        root = (Root)(((int)c.root + 3) % 12);
                        type = Type.aug;
                        break;

                    case 5:
                        root = c.root;
                        type = Type.Major;
                        break;

                    case 6:
                        root = c.root;
                        type = Type.sus2;
                        break;

                    case 7:
                        root = c.root;
                        type = Type.sus4;
                        break;
                    }
                    break;

                case Type.sus2:
                    rand = r.Next(6);
                    switch (rand)
                    {
                    case 0:
                        root = c.root;
                        type = Type.Major;
                        break;

                    case 1:
                        root = c.root;
                        type = Type.minor;
                        break;

                    case 2:
                        root = c.root;
                        type = Type.sus4;
                        break;

                    case 3:
                        root = (Root)(((int)c.root - 5) % 12);
                        type = Type.minor;
                        break;

                    case 4:
                        root = (Root)(((int)c.root - 5) % 12);
                        type = Type.Major;
                        break;

                    case 5:
                        root = (Root)(((int)c.root - 5) % 12);
                        type = Type.sus2;
                        break;
                    }
                    break;

                case Type.sus4:
                    rand = r.Next(6);
                    switch (rand)
                    {
                    case 0:
                        root = c.root;
                        type = Type.Major;
                        break;

                    case 1:
                        root = c.root;
                        type = Type.minor;
                        break;

                    case 2:
                        root = c.root;
                        type = Type.sus2;
                        break;

                    case 3:
                        root = (Root)(((int)c.root + 5) % 12);
                        type = Type.minor;
                        break;

                    case 4:
                        root = (Root)(((int)c.root + 5) % 12);
                        type = Type.Major;
                        break;

                    case 5:
                        root = (Root)(((int)c.root + 5) % 12);
                        type = Type.sus4;
                        break;
                    }
                    break;

                case Type.aug:
                    rand = r.Next(6);
                    switch (rand)
                    {
                    case 0:
                        root = c.root;
                        type = Type.Major;
                        break;

                    case 1:
                        root = (Root)(((int)c.root - 3) % 12);
                        type = Type.minor;
                        break;

                    case 2:
                        root = (Root)(((int)c.root + 1) % 12);
                        type = Type.minor;
                        break;

                    case 3:
                        root = (Root)(((int)c.root + 4) % 12);
                        type = Type.Major;
                        break;

                    case 4:
                        root = (Root)(((int)c.root - 4) % 12);
                        type = Type.Major;
                        break;

                    case 5:
                        root = (Root)(((int)c.root + 5) % 12);
                        type = Type.minor;
                        break;
                    }
                    break;

                case Type.dim:
                    rand = r.Next(11);
                    switch (rand)
                    {
                    case 0:
                    case 7:
                        root = c.root;
                        type = Type.minor;
                        break;

                    case 1:
                    case 8:
                        root = (Root)(((int)c.root - 4) % 12);
                        type = Type.Major;
                        break;

                    case 2:
                        root = (Root)(((int)c.root - 3) % 12);
                        type = Type.dim;
                        break;

                    case 3:
                        root = (Root)(((int)c.root + 3) % 12);
                        type = Type.dim;
                        break;

                    case 4:
                    case 9:
                        root = (Root)(((int)c.root + 3) % 12);
                        type = Type.minor;
                        break;

                    case 5:
                    case 10:
                        root = (Root)(((int)c.root - 1) % 12);
                        type = Type.Major;
                        break;

                    case 6:
                        root = (Root)(((int)c.root + 6) % 12);
                        type = Type.dim;
                        break;
                    }
                    break;
                }

                rand   = r.Next(15);
                octave = c.octave;
                switch (rand)
                {
                case 0:
                    octave -= 1;
                    if (octave < minOctave)
                    {
                        octave = minOctave + 1;
                    }
                    break;

                case 1:
                case 2:
                case 3:
                    octave -= 1;
                    if (octave < minOctave)
                    {
                        octave = minOctave;
                    }
                    break;

                case 4:
                case 5:
                case 6:
                case 7:
                case 8:
                case 9:
                case 10:
                case 11:
                    break;

                case 12:
                case 13:
                case 14:
                    octave += 1;
                    if (octave > maxOctave)
                    {
                        octave = maxOctave;
                    }
                    break;

                default:
                    octave += 1;
                    if (octave > maxOctave)
                    {
                        octave = maxOctave - 1;
                    }
                    break;
                }
                if (octave > maxOctave)
                {
                    octave = maxOctave;
                }
                if (octave < minOctave)
                {
                    octave = minOctave;
                }

                oldP = (int)c.root + c.octave * 12;
                p    = (int)root + octave * 12;
                while (oldP + 12 < p)
                {
                    octave--;
                    p = (int)root + octave * 12;
                }
                while (oldP - 12 > p)
                {
                    octave++;
                    p = (int)root + octave * 12;
                }
                if (octave > maxOctave)
                {
                    octave = maxOctave;
                }
                if (octave < minOctave)
                {
                    octave = minOctave;
                }

                break;
                #endregion
            }
        }
Exemple #2
0
        /// <summary>
        /// 랜덤으로 화음을 초기화합니다.
        /// </summary>
        public Chord(Form1.Theme theme)
        {
            Random r = new Random();
            int    rand;

            switch (theme)
            {
            case Form1.Theme.Autumn:
                #region Autumn Chord
                maxOctave = 5;
                minOctave = 4;
                root      = (Root)r.Next(12);

                rand = r.Next(15);
                switch (rand)
                {
                case 1:
                case 2:
                case 3:
                case 4:
                case 5:
                case 6:
                    type = Type.Major;
                    break;

                case 7:
                case 8:
                case 9:
                case 10:
                    type = Type.minor;
                    break;

                case 11:
                    type = Type.sus2;
                    break;

                case 12:
                case 13:
                    type = Type.sus4;
                    break;

                case 14:
                    type = Type.M7;
                    break;

                default:
                    type = Type.m7;
                    break;
                }

                rand   = r.Next(15);
                octave = 5;
                switch (rand)
                {
                case 0:
                    octave -= 2;
                    break;

                case 1:
                case 2:
                case 3:
                    octave -= 1;
                    break;

                case 4:
                case 5:
                case 6:
                case 7:
                case 8:
                case 9:
                case 10:
                case 11:
                    break;

                case 12:
                case 13:
                case 14:
                    octave += 1;
                    break;

                default:
                    octave += 2;
                    break;
                }
                if (octave > maxOctave)
                {
                    octave = maxOctave;
                }
                if (octave < minOctave)
                {
                    octave = minOctave;
                }

                break;

                #endregion
            case Form1.Theme.Rain:
                #region Rain Chord
                maxOctave = 8;
                minOctave = 5;
                root      = (Root)r.Next(12);

                rand = r.Next(15);
                switch (rand)
                {
                case 1:
                case 2:
                case 3:
                case 4:
                    type = Type.minor;
                    break;

                case 5:
                case 6:
                    type = Type.m7;
                    break;

                case 7:
                    type = Type.Major;
                    break;

                case 8:
                case 9:
                case 10:
                    type = Type.M7;
                    break;

                case 11:
                    type = Type.sus2;
                    break;

                case 12:
                case 13:
                    type = Type.sus4;
                    break;

                case 14:
                    type = Type.aug;
                    break;

                default:
                    type = Type.dim;
                    break;
                }

                rand   = r.Next(15);
                octave = 6;
                switch (rand)
                {
                case 0:
                    octave -= 2;
                    break;

                case 1:
                case 2:
                case 3:
                    octave -= 1;
                    break;

                case 4:
                case 5:
                case 6:
                case 7:
                case 8:
                case 9:
                case 10:
                case 11:
                    break;

                case 12:
                case 13:
                case 14:
                    octave += 1;
                    break;

                default:
                    octave += 2;
                    break;
                }
                if (octave > maxOctave)
                {
                    octave = maxOctave;
                }
                if (octave < minOctave)
                {
                    octave = minOctave;
                }

                break;

                #endregion
            case Form1.Theme.Star:
                #region Star Chord
                maxOctave = 8;
                minOctave = 5;
                root      = (Root)r.Next(12);

                rand = r.Next(15);
                switch (rand)
                {
                case 1:
                case 2:
                case 3:
                case 4:
                case 5:
                    type = Type.Major;
                    break;

                case 6:
                case 7:
                case 8:
                case 9:
                case 10:
                    type = Type.minor;
                    break;

                case 11:
                    type = Type.sus2;
                    break;

                case 12:
                case 13:
                    type = Type.sus4;
                    break;

                case 14:
                    type = Type.aug;
                    break;

                default:
                    type = Type.dim;
                    break;
                }

                rand   = r.Next(15);
                octave = 6;
                switch (rand)
                {
                case 0:
                    octave -= 2;
                    break;

                case 1:
                case 2:
                case 3:
                    octave -= 1;
                    break;

                case 4:
                case 5:
                case 6:
                case 7:
                case 8:
                case 9:
                case 10:
                case 11:
                    break;

                case 12:
                case 13:
                case 14:
                    octave += 1;
                    break;

                default:
                    octave += 2;
                    break;
                }
                if (octave > maxOctave)
                {
                    octave = maxOctave;
                }
                if (octave < minOctave)
                {
                    octave = minOctave;
                }

                break;
                #endregion
            }
        }