Beispiel #1
0
def main():
    songs_path = './songs/'
    os.makedirs(songs_path, exist_ok=True)

    songs = [{
        'name': 'sevennationarmy',
        'notes': utility.iterate('G3', scales.SCALE_STEPS['major']),
        'tempo': 360,
        'text': '515272524231322122515272524232423222'
    }, {
        'name':
        'boomer',
        'notes':
        utility.iterate('D3', scales.SCALE_STEPS['harmonic_minor']),
        'tempo':
        360,
        'text':
        '223242625242322212223262524232'
    }]

    tick_size = 2

    for song in songs:
        logger.debug('Current song: {name}'.format(name=song['name']))
        logger.debug('Notes: {notes}'.format(notes=song['notes']))
        m = Melopy(songs_path + song['name'], tempo=song['tempo'])
        ticks = get_ticks(song['text'], tick_size)
        for tick in ticks:
            note = song['notes'][int(tick[0])]
            fraction = 1.0 / int(tick[1])
            logger.debug('{note} {fraction}'.format(note=note,
                                                    fraction=fraction))
            m.add_fractional_note(note=note, fraction=fraction)
        m.render()
Beispiel #2
0
    def __init__(self, root, scaleIntervals):
        """
        Constructor.

        @param root: root note of scale
        @param scaleIntervals: list contains intervals to build scale from given root note.
        """
        #: List representation of scale
        self.scale = iterate(root, scaleIntervals, "list")
        #: Octave of root ==> octave of scale
        self.octave = int(self.scale[0][-1])
Beispiel #3
0
def generateScale(scale,
                  note,
                  mode=1,
                  rType="list",
                  octaves=True):  #scale, start, type
    """
    Generate a scale
    scale (string): major,  melodic_minor, harmonic_minor, chromatic, major_pentatonic
    note: start note
    """
    if scale in SCALE_STEPS:
        steps = _get_mode(SCALE_STEPS[scale], mode)
        return iterate(note, steps, rType, octaves)
    else:
        raise MelopyGenericError("Unknown scale type:" + str(scale))
Beispiel #4
0
 def test_iterate(self):
     start = 'D4'
     pattern = [2, 2, 1, 2, 2, 2]
     should_be = ['D4', 'E4', 'F#4', 'G4', 'A4', 'B4', 'C#5']
     self.assertEqual(should_be, utility.iterate(start, pattern))
Beispiel #5
0
 def test_iterate(self):
     start = 'D4'
     pattern = [2, 2, 1, 2, 2, 2]
     should_be = ['D4', 'E4', 'F#4', 'G4', 'A4', 'B4', 'C#5']
     self.assertEqual(should_be, utility.iterate(start, pattern))
Beispiel #6
0
def generateChord(name, tonic, inversion=0, rType='list', octaves=True):
    if name in CHORD_INTERVALS:
        steps = CHORD_INTERVALS[name]
        return _get_inversion(iterate(tonic, steps, rType, octaves), inversion)
    else:
        raise MelopyGenericError("Unknown Chord:" + str(name))