BlottoBeats.Client.Generator.generate_4Chord C# (CSharp) Method

generate_4Chord() public method

public generate_4Chord ( SongParameters paramets ) : double
paramets BlottoBeats.Library.SongData.SongParameters
return double
        public double generate_4Chord(SongParameters paramets)
        {
            Random randomizer = new Random(paramets.seed);
            int mode = 0; // 0 = Major 1 = Minor
            String key;
            String gen;
            Song.SongSegment[] thisSection = new Song.SongSegment[3];
            String timeSigPattern = ""; //Simple or Compound Meter
            int timeSigQuant = 0; // 2 = Duple, 3 = Triple, etc

            String[] notes = { "A", "A#", "B", "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#" };

            //Select Key
            key = notes[randomizer.Next(12)];

            //Now also sets the genre
            Song output = new Song(paramets.tempo, key, paramets.genre);
            Console.Out.WriteLine(paramets.genre);

            int randOutput = randomizer.Next(2);
            switch (randOutput)
            {
                case 0:
                    timeSigPattern = "Simple";
                    break;
                case 1:
                    timeSigPattern = "Compound";
                    break;
            }

            timeSigQuant = randomizer.Next(3) + 2;

            for (int i = 0; i < 3; i++)
            {
                if (i != 2)
                    thisSection[i] = new Song.SongSegment();
                else
                    thisSection[i] = new Song.SongSegment(thisSection[0].chordPattern, thisSection[0].melodies, thisSection[0].melodies[0]);

                String chordProg="";

                int subdiv=0;

                int measureLen = 0;
                if (timeSigPattern.Equals("Simple"))
                {
                    measureLen += 4;
                }
                else
                    measureLen += 6;
                measureLen *= timeSigQuant;

                if (timeSigQuant == 2)
                {
                    randOutput = randomizer.Next(2) + 1;
                    subdiv = measureLen / randOutput;
                }
                else if (timeSigQuant == 3)
                {
                    randOutput = randomizer.Next(2) + 1;
                    if (randOutput == 2)
                        randOutput = 3;
                    subdiv = measureLen / randOutput;
                }
                else
                {
                    randOutput = randomizer.Next(3) + 1;
                    if (randOutput == 3)
                        randOutput = 4;
                    subdiv = measureLen / randOutput;
                }
                int repPerMeasure = measureLen / subdiv;

                int randout = randomizer.Next(5);
                switch (randout)
                {
                    case 0:
                        chordProg = "6415";
                        break;
                    case 1:
                        chordProg = "1564";
                        break;
                    case 2:
                        chordProg = "1264";
                        break;
                    case 3:
                        chordProg = "1254";
                        break;
                    case 4:
                        chordProg = "4156";
                        break;

                }
                //Write chord progression
                if (i != 2)
                {

                    for (int j = 0; j < 4; j++)
                    {
                        for (int k = 0; k < 4; k++)
                        {
                            for (int l = 0; l < repPerMeasure; l++)
                            {
                                thisSection[i].chordPattern.Add(generateChord(mode, key, chordProg[k], subdiv));
                            }

                        }
                    }
                }
                //Write voice line
                composeMelody(thisSection[i], randomizer, key, mode, timeSigPattern, timeSigQuant);

                //Write bass line
                if (i != 2)
                {
                    Song.Melody thisMelody = new Song.Melody();
                    for (int j = 0; j < 4; j++)
                    {
                        for (int k = 0; k < 4; k++)
                        {
                            for (int l = 0; l < repPerMeasure; l++)
                            {
                               thisMelody.melodicLine.Add(thisSection[i].chordPattern[(j*4*repPerMeasure)+(k*repPerMeasure)+l].chordVoice.First());
                            }

                        }
                    }
                    thisSection[i].melodies.Add(thisMelody);

                }

                //Fix ordering of voice and bass line after insertion in bridge
                if (i == 2)
                {
                    Song.Melody tmp = thisSection[i].melodies[0];
                    thisSection[i].melodies[0] = thisSection[i].melodies[1];
                    thisSection[i].melodies[1] = tmp;
                }
            }

            output.addSegment(thisSection[0]);
            output.addSegment(thisSection[1]);
            output.addSegment(thisSection[0]);
            output.addSegment(thisSection[1]);
            output.addSegment(thisSection[2]);
            output.addSegment(thisSection[1]);

            BlottoBeats.MidiOut.MidiOut outgoing = new BlottoBeats.MidiOut.MidiOut();
            double songLen = outgoing.outputToMidi(output);

            return songLen;
        }