Inheritance: IFitnessFunction
Esempio n. 1
0
        public static NCD FromMelodies(CompositionCategory category)
        {
            NCD ncd = new NCD();

            string savepath = GetSavePath(category);
            if (File.Exists(savepath))
            {
                //ncd.Deserialize(savepath);
               // return ncd;
            }

            MelodySequence[] seqs = new MelodySequence[category.Compositions.Length];
            for (int i = 0; i < category.Compositions.Length; i++)
                seqs[i] = category.Compositions[i].GetLongestTrack().GetMainSequence() as MelodySequence;

            ncd.songs = new string[seqs.Count()];

            int j = 0;
            foreach (MelodySequence m in seqs)
            {
                ncd.songs[j++] = m.ToString();
            }

            string root = System.IO.Path.GetDirectoryName(savepath);
            if (!System.IO.Directory.Exists(root))
                System.IO.Directory.CreateDirectory(root);
            ncd.Serialize(savepath);

            return ncd;
        }
Esempio n. 2
0
        public static NCD FromCompositions(CompositionCategory category)
        {
            NCD ncd = new NCD();

            string savepath = GetSavePath(category);
            if (File.Exists(savepath))
            {
                ncd.Deserialize(savepath);
                return ncd;
            }

            Composition[] seqs = category.Compositions;

            ncd.songs = new string[seqs.Count()];

            int i = 0;
            int j = 0;
            foreach (var comp in seqs)
            {
                Console.WriteLine("NCD: {0}", j++ / seqs.Length);
                var c = comp;
                if (MaxTracks > 0)
                {
                    var newComp = new Composition();
                    for(int k = 0; k < MaxTracks && k < comp.Tracks.Count; k++)
                    {
                        newComp.Add(comp.Tracks[k]);
                    }
                    c = newComp;
                }

                ncd.songs[i++] = c.ToString();
            }

            string root = System.IO.Path.GetDirectoryName(savepath);
            if (!System.IO.Directory.Exists(root))
                System.IO.Directory.CreateDirectory(root);
            ncd.Serialize(savepath);

            return ncd;
        }