Exemple #1
0
def dataset(data_dir):
    r"""
    Given a directory filled with data files, create a corresponding
    dataset.
    """
    data = SupervisedDataSet(NUMBER_INPUTS, SUPPORTED_FRETS)
    for piece in os.listdir(data_dir):
        LOG.info('Adding samples from piece: {p}'.format(p=piece))
        full_path = os.path.join(data_dir, piece)
        tracks = read_standard_tracks(full_path)
        for track in tracks:
            limiting_notes_generator = limiting_notes(track)
            try:
                next_limitation = limiting_notes_generator.next()
            except StopIteration:
                next_limitation = None
            for context in chord_contexts(track):
                context = (context[0],
                           context[1],
                           context[2],  # **physical** successors!
                           context[3],
                           context[4],
                           next_limitation)
                LOG.debug('Chord context: {c}'.format(c=context))
                chord_entry = context[1]
                # sample data yields once for each note in chord!
                for (inputs, outputs) in _sample_data(*context):
                    data.addSample(inputs, outputs)
                while next_limitation and next_limitation[1] <= chord_entry:
                    try:
                        next_limitation = limiting_notes_generator.next()
                    except StopIteration:
                        next_limitation = None
    return data
 def test_limiting_first_chord(self):
     block = ['E|-0-',
              'B|-0-',
              'G|-0-',
              'D|-0-',
              'A|-0-',
              'E|-0-']
     expected = (('E', 2), 0)
     generator = limiting_notes(block)
     self.assertEqual(generator.next(), expected)
 def test_limiting_third_chord(self):
     block = ['E|-3-3-12',
              'B|-3-3-12',
              'G|-2-2-11',
              'D|-------',
              'A|-------',
              'E|-------']
     expected1 = (('E', 5), 2)
     expected2 = (('B', 4), 2)
     generator = limiting_notes(block)
     self.assertEqual(generator.next(), expected1)
     self.assertEqual(generator.next(), expected2)
     self.assertRaises(StopIteration, generator.next)