Exemple #1
0
 public MarkovSortedTrack(MidiTrack p_track)
 {
     notesWithLengths = new List <MarkovNote>();
     for (int i = 0; i < p_track.getNumNotes(); i++)
     {
         //if note on
         if (p_track.getNote(i).getStatusByte() == 0x90)
         {
             MarkovNote _note = new MarkovNote(p_track.getNote(i));
             //find coupled note off
             for (int j = i + 1; j < p_track.getNumNotes(); j++)
             {
                 if (p_track.getNote(j).getByteOne() == _note.getByteOne() /* is same note */ &&
                     (p_track.getNote(j).getByteTwo() == 0x00 || p_track.getNote(j).getStatusByte() == 0x80) /* is note off */)
                 {
                     _note.length = p_track.getNote(j).getAbsTimeStamp() - p_track.getNote(i).getAbsTimeStamp();
                     j            = p_track.getNumNotes(); //force break for loop
                 }
             }
             if (_note.length == -1)
             {
                 Debug.Log("<color=red>Error- no note off</color>");
             }
             notesWithLengths.Add(_note);
         }
     }
 }
        //each node- check it doesn't exist already
        public void addNote(MarkovNote p_mes)
        {
            if (Midi.debugLevel > 1)
            {
                Debug.Log("Add note : " + p_mes.getByteOne());
            }
            for (int i = 0; i < nodeMatrix.Count; i++)
            {
                if (p_mes.getMessageAsBytes().SequenceEqual(nodeMatrix[i].getMessageAsBytes()) && p_mes.length == nodeMatrix[i].getNoteLen())
                {
                    nodeMatrix[previousWritePos].addWeight(nodeMatrix[i]);
                    previousWritePos = i;
                    return;
                }
            }
            TransitionNode node = new TransitionNode(p_mes);

            nodeMatrix[previousWritePos].addWeight(node);
            nodeMatrix.Add(node);
            previousWritePos = nodeMatrix.Count - 1;
        }
 public TransitionNode(MarkovNote p_mes)
 {
     message           = p_mes;
     transitionWeights = new List <TransitionWeight>();
 }