示例#1
0
        /// <summary>
        /// Updates the parts[] vector based on the current rhythm gene being a rest.
        /// </summary>
        /// <param name="i"></param>
        /// <param name="rhythmGene"></param>
        /// <param name="rhythmSoloPart0"></param>
        private void ProcessRestGene(ref int i, char rhythmGene)
        {
            byte   addDur = 0;
            string temps;
            byte   maxIterate        = Parameters.maxIterate;
            byte   genotypeIterate_0 = Parameters.genotypeIterate[0];

            string[] rhythmSoloPart0 = currentRhythmChromosome[0];

            parts[0] += "R";
            parts[1] += "R";
            parts[2] += "R|";
            parts[3] += "R|";

            do
            {
                addDur++;
                i++;

                if (i == maxIterate || i % genotypeIterate_0 == 0)
                {
                    break;
                }
                else
                {
                    rhythmGene = RhythmDecode(rhythmSoloPart0[i]);
                }
            }while ((rhythmGene == 'r' || rhythmGene == 'c'));

            temps     = Durations.FinalDuration(Parameters.durationIndex, addDur);
            parts[0] += temps + " ";
            parts[1] += temps + " ";
            parts[2] += addDur + " ";
            parts[3] += addDur + " ";
        }
示例#2
0
        /// <summary>
        /// Updates the parts[] vector based on the current rhythm gene being a note.
        /// </summary>
        /// <param name="i"></param>
        /// <param name="rhythmGene"></param>
        /// <param name="pitchSoloPart0"></param>
        /// <param name="pitchSoloPart1"></param>
        /// <param name="velocitySoloPart0"></param>
        /// <param name="velocitySoloPart1"></param>
        /// <param name="rhythmSoloPart0"></param>
        private void ProcessPitchGene(ref int i, char rhythmGene)
        {
            byte note1, note2;
            byte velocity1, velocity2;
            byte addDur = 1, fP;
            int  j;
            byte genotypeIterate_0 = Parameters.genotypeIterate[0];
            byte maxIterate        = Parameters.maxIterate;
            byte keySignatureIndex = Parameters.keySignatureIndex;

            byte[] octaves  = Parameters.octavesByteValues;
            string duration = Durations.FinalDuration(Parameters.durationIndex, addDur);

            int[]    pitchSoloPart0    = currentPitchChromosome[0];
            int[]    pitchSoloPart1    = currentPitchChromosome[1];
            byte[]   velocitySoloPart0 = currentVelocityChromosome[0];
            byte[]   velocitySoloPart1 = currentVelocityChromosome[1];
            string[] rhythmSoloPart0   = currentRhythmChromosome[0];

            do
            {
                fP        = Scales.FirstPitch(octaves[0], keySignatureIndex);
                note1     = PitchSolo1Decode(pitchSoloPart0[i], fP);
                velocity1 = VelocityDecode(velocitySoloPart0[i]);
                parts[0] += "[" + note1.ToString() + "]" + duration + "V" + velocity1.ToString() + " ";
                j         = note1 - fP;
                parts[2] += ActualOctave(j, 0).ToString() +  //(byte)Parameters.octaves[0] +
                            "|" + Scales.scales[keySignatureIndex][j] + "|" + addDur + " ";

                fP        = Scales.FirstPitch(octaves[1], keySignatureIndex);
                note2     = PitchSolo2Decode(pitchSoloPart1[i], note1, fP);
                velocity2 = VelocityDecode(velocitySoloPart1[i]);
                parts[1] += "[" + note2.ToString() + "]" + duration + "V" + velocity2.ToString() + " ";
                j         = note2 - fP;
                parts[3] += ActualOctave(j, 1).ToString() +  //(byte)Parameters.octaves[0] +
                            "|" + Scales.scales[keySignatureIndex][j] + "|" + addDur + " ";

                i++;

                if (i == maxIterate || i % genotypeIterate_0 == 0)
                {
                    break;
                }
                else
                {
                    rhythmGene = RhythmDecode(rhythmSoloPart0[i]);
                }
            }while (rhythmGene == 'p');
        }
示例#3
0
        /// <summary>
        /// Updates the parts[] vector based on the current rhythm gene being a continuation.
        /// </summary>
        /// <param name="i"></param>
        /// <param name="rhythmGene"></param>
        /// <param name="velocitySoloPart0"></param>
        /// <param name="velocitySoloPart1"></param>
        /// <param name="rhythmSoloPart0"></param>
        private void ProcessContinuationGene(ref int i, char rhythmGene)
        {
            byte   velocity1, velocity2;
            byte   addDur = 1;
            string duration;
            byte   maxIterate        = Parameters.maxIterate;
            byte   genotypeIterate_0 = Parameters.genotypeIterate[0];

            string[] rhythmSoloPart0 = currentRhythmChromosome[0];

            parts[0] = parts[0].Remove(parts[0].LastIndexOf(']') + 1);
            parts[1] = parts[1].Remove(parts[1].LastIndexOf(']') + 1);
            parts[2] = parts[2].Remove(parts[2].LastIndexOf('|') + 1);
            parts[3] = parts[3].Remove(parts[3].LastIndexOf('|') + 1);

            velocity1 = VelocityDecode(currentVelocityChromosome[0][i]);
            velocity2 = VelocityDecode(currentVelocityChromosome[1][i]);

            do
            {
                addDur++;
                i++;

                if (i == maxIterate || i % genotypeIterate_0 == 0)
                {
                    break;
                }
                else
                {
                    rhythmGene = RhythmDecode(rhythmSoloPart0[i]);
                }
            }while (rhythmGene == 'c');

            duration  = Durations.FinalDuration(Parameters.durationIndex, addDur);
            parts[0] += duration + "V" + velocity1.ToString() + " ";
            parts[1] += duration + "V" + velocity2.ToString() + " ";
            parts[2] += addDur + " ";
            parts[3] += addDur + " ";
        }
示例#4
0
        /// <summary>
        /// Fills the score staff template of THIS individual with the corresponding genome information.
        /// </summary>
        /// <param name="genome"></param>
        public void setContent(Genome genome)
        {
            try
            {
                // The final duration (e.g. q. is 1/4+(1/4)/2 or 6*1/16):
                // wrt unitBeat (e.g. unitBeat=16: q. is 6);
                byte unitBeatFinalDur;
                // in CFugue notation (e.g. q.).
                string cFugueFinalDur;
                byte   durLastNoteInTieIndex;
                double diff;
                layoutInterval = 0;
                string currentWordPart0, currentWordPart1;

                string[] wordsPart0 = genome.Parts[2].Split(' ');
                string[] wordsPart1 = genome.Parts[3].Split(' ');

                for (int j = 0; j < wordsPart0.Length - 1; j++)
                {
                    currentWordPart0 = wordsPart0[j];
                    currentWordPart1 = wordsPart1[j];
                    unitBeatFinalDur = Convert.ToByte(currentWordPart0.Substring(currentWordPart0.LastIndexOf('|') + 1));
                    cFugueFinalDur   = Durations.FinalDuration(Parameters.durationIndex, unitBeatFinalDur);

                    // If there is one element to place on the score.
                    if (cFugueFinalDur.Length == 1 || (cFugueFinalDur.Length == 2 && cFugueFinalDur.Contains('.')))
                    {
                        diff        = ((unitBeatFinalDur - 1) * unitElementWidth) / 2;
                        leftMargin += diff;

                        bool dot = GetDot(ref cFugueFinalDur);

                        // If it's a rest.
                        if (currentWordPart0[0] == 'R')
                        {
                            DrawRestForEachPart(cFugueFinalDur, dot);
                        }
                        // If it's a note.
                        else
                        {
                            DrawNoteForEachPart(currentWordPart0, currentWordPart1, dot, cFugueFinalDur);
                        }

                        leftMargin += unitElementWidth + diff + 1;
                    }

                    // If there are two elements (they're gonna be connected by a tie) to place on the score.
                    else
                    {
                        double[] interval = GetLayoutIntervals(unitBeatFinalDur);
                        diff           = interval[0];
                        layoutInterval = interval[1];
                        leftMargin    += diff;

                        bool[]           dot = GetDotsInTie(cFugueFinalDur, out durLastNoteInTieIndex);
                        DurationCFugue[] cFugueFinalDuration = GetCFugueDurationsInTie(cFugueFinalDur[0].ToString(), cFugueFinalDur[durLastNoteInTieIndex].ToString());

                        // If the two elements are rests.
                        if (currentWordPart0[0] == 'R')
                        {
                            DrawTiedRestsForEachPart(cFugueFinalDuration, dot);
                        }
                        // If the two elements are notes.
                        else
                        {
                            DrawTiedNotesForEachPart(currentWordPart0, currentWordPart1, dot, cFugueFinalDuration);
                        }

                        leftMargin += unitElementWidth + diff + 1;
                    }
                }

                // Reset leftMargin to default value when done.
                leftMargin = 2;
            }
            catch (Exception)
            {
            }
        }