Exemple #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;
     }
 }
Exemple #2
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()));
        }