コード例 #1
0
        public TransitionMatrix(MidiTrack _track)
        {
            nodeMatrix  = new List <TransitionNode>();
            sortedTrack = new MarkovSortedTrack(_track);
            TransitionNode startNode = new TransitionNode(new MarkovNote(0x00, 0x00, 0x00));

            nodeMatrix.Add(startNode);
            previousReadNode = nodeMatrix[0];
            previousWritePos = 0; //pos 0 in array- ie start of phrase
            for (int i = 0; i < sortedTrack.notesWithLengths.Count; i++)
            {
                addNote(sortedTrack.notesWithLengths[i]);
            }
        }
コード例 #2
0
        //analyze transition matrix and generate notes
        //how to deal with note offs? - add to an array?
        public MarkovNote getNextNote()
        {
            TransitionNode _node;

            _node = previousReadNode.getNextNote();
            if (_node != null)
            {
                previousReadNode = _node;
                return(_node.message);
            }
            else
            {
                Debug.Log("<color=red>Error:</color> non next note");
                return(null);
            }
        }
コード例 #3
0
        public void addWeight(TransitionNode p_node)
        {
            //Debug.Log("Add weight num : " + transitionWeights.Count + " to node");
            for (int i = 0; i < transitionWeights.Count; i++)
            {
                if (p_node.message.getMessageAsBytes().SequenceEqual(transitionWeights[i].getMessageAsBytes()))
                {
                    transitionWeights[i].weight++; //add to probability if weight node already exists
                    allTransitionsWeight++;
                    return;
                }
            }
            //else create new weighting and attach to exiting node ref
            TransitionWeight connectorWeight = new TransitionWeight(p_node);

            connectorWeight.weight++;
            allTransitionsWeight++;
            transitionWeights.Add(connectorWeight);
        }
コード例 #4
0
        //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;
        }
コード例 #5
0
 public TransitionWeight(TransitionNode p_node)
 {
     node = p_node;
 }