Beispiel #1
0
 internal void harmonizate(Tonality tonality)
 {
     int[] scale = tonality.getScale();
     for (int i = 0; i < this.musicItemList.Count; i++)
     {
         MusicItem mi = musicItemList[i];
         if (mi.isChord())
         {
             continue;
         }
         Note  high  = (Note)mi;
         Chord chord = new Chord();
         chord.add(high);
         int found = 0;
         int pitch = high.getPitch() - 2; // Substracting 2 to avoid 2-intervals
         while (found < 2 && pitch > 0)
         {
             pitch--;
             if (tonality.isinTriad(pitch))
             {
                 chord.add(new Note(pitch, high.getDuration()));
                 found++;
             }
         }
         musicItemList[i] = chord;
     }
 }
Beispiel #2
0
        public List <int> getNonSilentNotes()
        {
            List <int> nonSilentNotes = new List <int>();

            for (int i = 0; i < musicItemList.Count; i++)
            {
                MusicItem mi = musicItemList[i];
                if (!mi.isSilence())
                {
                    nonSilentNotes.Add(i);
                }
            }
            return(nonSilentNotes);
        }
Beispiel #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);
        }
Beispiel #4
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;
         }
     }
 }
Beispiel #5
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;
         }
     }
 }
Beispiel #6
0
        private int getDisonance(MusicItem mi1, MusicItem mi2)
        {
            if (mi1.isSilence() || mi2.isSilence())
            {
                return(0);
            }

            Chord a, b;

            if (mi1.isChord())
            {
                a = (Chord)mi1;
            }
            else
            {
                a = new Chord();
                a.add((Note)mi1);
            }

            if (mi2.isChord())
            {
                b = (Chord)mi2;
            }
            else
            {
                b = new Chord();
                b.add((Note)mi2);
            }

            int totalDisonance = 0;

            for (int i = 0; i < a.size(); i++)
            {
                for (int j = 0; j < b.size(); j++)
                {
                    totalDisonance += getDisonance(a.get(i), b.get(j));
                }
            }

            return(totalDisonance / (a.size() * b.size()));
        }
Beispiel #7
0
        internal void ornamentation(int pitch)
        {
            List <MusicItem> oldList = this.musicItemList;

            this.musicItemList = new List <MusicItem>();
            foreach (MusicItem mi in oldList)
            {
                if (mi.isSilence())
                {
                    musicItemList.Add(mi);
                    continue;
                }

                mi.changeDuration(new Duration(1, 3));
                musicItemList.Add(mi.Clone());
                MusicItem aux = mi.Clone();
                aux.transport(pitch);
                musicItemList.Add(aux);
                musicItemList.Add(mi.Clone());
            }
        }
Beispiel #8
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();
            }
        }
Beispiel #9
0
 public void add(MusicItem musicItem)
 {
     this.musicItemList.Add(musicItem);
 }