Example #1
0
 internal void removeFromEnd(Duration duration)
 {
     while (duration > 0)
     {
         MusicItem mi = musicItemList[musicItemList.Count - 1];
         if (mi.getDuration() <= duration)
         {
             musicItemList.RemoveAt(musicItemList.Count - 1);
             duration -= mi.getDuration();
         }
         else
         {
             mi.shortenDurationFromEnd(duration);
             duration = 0;
         }
     }
 }
Example #2
0
 internal void removeFromBeginning(Duration duration)
 {
     while (duration > 0)
     {
         MusicItem mi = musicItemList[0];
         if (mi.getDuration() <= duration)
         {
             musicItemList.RemoveAt(0);
             duration -= mi.getDuration();
         }
         else
         {
             mi.shortenDurationFromBeginning(duration);
             duration = 0;
         }
     }
 }
Example #3
0
        public List <Duration> getNotesStart(bool getSilences)
        {
            List <Duration> notes     = new List <Duration>();
            Duration        noteStart = 0;

            for (int i = 0; i < musicItemList.Count; i++)
            {
                MusicItem mi = musicItemList[i];
                if (getSilences || !mi.isSilence())
                {
                    notes.Add(noteStart);
                }
                noteStart += mi.getDuration();
            }
            return(notes);
        }
Example #4
0
        internal void interpolate(Tonality tonality)
        {
            int percentage = RNG.generate(10, 50);

            List <int> nonSilentNotes = getNonSilentNotes();

            int number = Math.Max(percentage * nonSilentNotes.Count / 100, 1);

            for (int i = 0; i < number; i++)
            {
                int       element = RNG.generate(0, nonSilentNotes.Count - 1);
                MusicItem mi      = musicItemList[nonSilentNotes[element]];

                int newNotePitch = Note.convertToClosestPitch(mi.pitchMean(), tonality.getRandomPitchFromScale(70));

                /*
                 * SplitNote = true: Divide note length by half and add a random note after it
                 * SplitNote = false: Substitute a silence with a random note.
                 */
                bool splitNote = true;
                if (element != musicItemList.Count - 1 && musicItemList[nonSilentNotes[element] + 1].isSilence() && RNG.generateBool())
                {
                    splitNote = false;
                }

                if (splitNote)
                {
                    mi.changeDuration(new Duration(1, 2));
                    musicItemList.Insert(nonSilentNotes[element] + 1, new Note(newNotePitch, mi.getDuration()));
                }
                else
                {
                    musicItemList[nonSilentNotes[element] + 1] = new Note(newNotePitch, musicItemList[nonSilentNotes[element] + 1].getDuration());
                }

                nonSilentNotes = getNonSilentNotes();
            }
        }