Esempio n. 1
0
 def __create_empty_dict(self):
     d = dict()
     for transition in make_chord_transitions():
         if self.__size is None:
             d.update({transition: NoteTransitionDictionary()})
         else:
             d.update({transition: NoteTransitionDictionary(self.__size)})
     return d
Esempio n. 2
0
 def test_init_no_filename(self):
     self.td = None
     self.td = ChordTransitionDictionary(size=self.size)
     chords = make_chord_transitions()
     chord_dict = {}
     for chord in chords:
         from datastructures.base_structures import NoteTransitionDictionary
         chord_dict.update({chord: NoteTransitionDictionary(self.size)})
     self.assertTrue(chord_dict, self.td.get_dict())
Esempio n. 3
0
 def test_init_no_filename(self):
     self.nd = None
     self.nd = NoteTransitionDictionary(self.size)
     empty_dict = {
         x: {y: 0
             for y in range(self.size)}
         for x in range(self.size)
     }
     self.assertEqual(self.nd.get_dict(), empty_dict)
Esempio n. 4
0
 def test_update_not_empty(self):
     from datastructures.base_structures import NoteTransitionDictionary
     import random as rand
     nd = NoteTransitionDictionary(self.size)
     transitions = []
     for x in range(self.size**2):
         start = rand.randint(0, self.size-1)
         end = rand.randint(0, self.size-1)
         transitions.append(NoteTransition(start,end))
     nd.add_note_transitions(transitions)
     self.pm.update(nd)
     for i in range(self.size):
         for j in range(self.size):
             total = sum(nd.get_dict()[i].values())
             if total > 0:
                 self.assertEqual(self.pm.get_matrix()[i][j], nd.get_dict()[i][j]/total)
Esempio n. 5
0
 def test_update_empty(self):
     from datastructures.base_structures import NoteTransitionDictionary
     empty = NoteTransitionDictionary(self.size)
     before = self.pm.get_matrix()[:]
     self.pm.update(empty)
     self.assertEqual(before, self.pm.get_matrix())
Esempio n. 6
0
for song in midi_songs_channel_other:
    notes = []
    for message in song:
        if message.type == "note_on" and message.channel == 1 and message.velocity != 0:
            notes.append(message.note)
    all_notes.append(notes)

#store each note transition as a tuple into a list
transitions = []
for notes in all_notes:
    for i in range(len(notes)-1):
        transition = NoteTransition(notes[i],notes[i+1])
        transitions.append(transition)

#create markov model data structures
nd = NoteTransitionDictionary()
pm = ProbabilityMatrix()
ntm = NoteTransitionMatrix()

#feed the data from the note transitions into the model
nd.add_note_transitions(transitions)
pm.update(nd)

#print the models
#print(nd.__repr__())
#print(pm.__repr__())
#print(ntm.__repr__())

#check which rows have non-zero rows
x = 0
while x < pm.get_size():
Esempio n. 7
0
 def setUp(self):
     self.size = 10
     self.nd = NoteTransitionDictionary(self.size)
Esempio n. 8
0
 def test_init_with_filename(self):
     self.nd = None
     self.nd = NoteTransitionDictionary(
         self.size, filename="TestNoteTransitionDictionary.txt")
     self.assertEqual(self.nd.read("TestNoteTransitionDictionary.txt"),
                      self.nd.get_dict())