def different_sections():
    func_name = 'different_sections'
    print 'Running {}...'.format(func_name)

    marimba = Marimba()
    audio_duration_seconds = 120
    audio = Audio(audio_duration_seconds)

    sections = Sections(32, len(audio))

    scale_type = [0, 4, 7]
    root = 0
    for section in sections:
        section.root = root
        scale = [(pc + root) % 12 for pc in scale_type]
        section.scale = [p for p in range(60, 73) if p % 12 in scale]
        root = (root + 1) % 12

    max_start = len(audio) - 80000

    n_notes = audio_duration_seconds * 5
    for _ in range(n_notes):
        start = np.random.randint(0, max_start)

        scale = sections.get_by_sample_offset(start).scale

        midi_number = np.random.choice(scale)
        note = marimba.get_note(midi_number)
        audio.add(start, note)

    audio.write_wav(func_name)
    print 'Done running {}.'.format(func_name)
 def setup_harmony_sections(self):
     harmony_sections = [3, 1] * 16
     self.harmony_sections = Sections(harmony_sections, self.len_audio)
     for i, harmony in enumerate(self.harmony_sections):
         if i % 2:
             harmony.harmony = [0, 4, 7]
         else:
             harmony.harmony = [5, 9, 0]
 def setup_register_sections(self):
     n_register_sections = 96 - 65
     low = 58
     high = 65
     self.register_sections = Sections(n_register_sections, self.len_audio)
     for section in self.register_sections:
         section.low = low
         section.high = high
         section.register = range(low, high)
         low = max([36, low - 1])
         high = min([96, high + 1])
    def go(self):
        pitch_options = [p for p in range(64, 87) if p % 12 in [0, 2, 4, 7, 9]]
        melody = dissonant_counterpoint(pitch_options, multiplier=10, skip=20)
        beats = Sections(self.duration_seconds * 4, self.len_audio - 80000)
        for beat in beats:
            if beat.index % 4:
                pitch = melody.next()
                note = self.marimba.get_note(pitch)
                self.audio.add(beat.start, note)

        pitch_options = [p for p in range(48, 62) if p % 12 in [0, 2, 4, 7, 9]]
        melody = dissonant_counterpoint(pitch_options, multiplier=10, skip=20)
        beats = Sections(self.duration_seconds, self.len_audio - 80000)
        for beat in beats:
            pitch = melody.next()
            note = self.marimba.get_note(pitch)
            self.audio.add(beat.start, note)
def different_sections_multiple_2():
    func_name = 'different_sections_multiple_2'
    print 'Running {}...'.format(func_name)

    marimba = Marimba()
    audio_duration_seconds = 240
    audio = Audio(audio_duration_seconds)

    harmonies = Sections(32, len(audio))
    for i, harmony in enumerate(harmonies):
        if i % 2:
            harmony.harmony = [0, 4, 7]
        else:
            harmony.harmony = [5, 9, 0]

    n_density_sections = 121
    densities = Sections(n_density_sections, len(audio))
    density_values = np.linspace(4, 100, 121)
    for section, value in zip(densities, density_values):
        section.density = value

    n_register_sections = 96 - 65
    low = 58
    high = 65
    register_sections = Sections(n_register_sections, len(audio))
    for section in register_sections:
        section.low = low
        section.high = high
        section.register = range(low, high)
        low = max([36, low - 1])
        high = min([96, high + 1])

    max_start = len(audio) - 80000

    print 'max_start', max_start, 'densities[-1].start', densities[-1].start

    for density_section in densities:
        for i in range(int(density_section.density)):
            start = np.random.randint(
                density_section.start,
                min([density_section.next_start, max_start]))

            register_section = register_sections.get_by_sample_offset(start)
            harmony_section = harmonies.get_by_sample_offset(start)
            pitch_options = [
                p for p in register_section.register
                if p % 12 in harmony_section.harmony
            ]

            pitch = np.random.choice(pitch_options)

            note = marimba.get_note(pitch)

            audio.add(start, note)

    audio.write_wav(func_name)
    print 'Done running {}.'.format(func_name)
Example #6
0
 def __init__(self, props, parent=None):
     super(PackageInfoDialog, self).__init__('pkginfo', props, parent)
     self.addButton.clicked.connect(self.addDep)
     self.removeButton.clicked.connect(self.removeDep)
     from sections import Sections
     sortedSections = sorted(Sections.items(), key=lambda x: x[1])
     self.sortedSectionCodes = [x[0] for x in sortedSections]
     sortedSectionNames = [x[1] for x in sortedSections]
     self.sectionCB.addItems(sortedSectionNames)
     sel = self.query('section')
     try:
         index = self.sortedSectionCodes.index(sel)
         self.sectionCB.setCurrentIndex(index)
     except ValueError:
         pass
     index = self.priorityCB.findText(self.query('priority'))
     if index >= 0:
         self.priorityCB.setCurrentIndex(index)
     self.shortDescEdit.setText(self.query('shortDesc'))
     self.longDescEdit.setPlainText(self.query('longDesc'))
     deps = self.query('deps').split(',')
     deps = [d for d in deps if d]
     if len(deps) > 0:
         self.dependList.addItems(deps)
Example #7
0
 def __init__(self, puzzle):
     s = Sections(puzzle)
     self.row = s.make('row')
     self.col = s.make('col')
     self.sq = s.make('sq')
     self.Missing = namedtuple('MissingValues', 'values locations')
 def setup_density_sections(self):
     n_density_sections = 121
     self.density_sections = Sections(n_density_sections, self.len_audio)
     density_values = np.linspace(4, 100, 121)
     for section, value in zip(self.density_sections, density_values):
         section.density = value
class MusicWithSections(object):
    def __init__(self):
        self.duration_seconds = 240
        self.setup()
        self.setup_harmony_sections()
        self.setup_density_sections()
        self.setup_register_sections()
        self.go()
        self.closeout()

    def setup(self):
        self.name = 'MusicWithSections'
        print 'Running {}...'.format(self.name)
        self.marimba = Marimba()
        self.audio = Audio(self.duration_seconds)
        self.len_audio = len(self.audio)

    def closeout(self):
        self.audio.write_wav(self.name)
        print 'Done running {}.'.format(self.name)

    def setup_harmony_sections(self):
        harmony_sections = [3, 1] * 16
        self.harmony_sections = Sections(harmony_sections, self.len_audio)
        for i, harmony in enumerate(self.harmony_sections):
            if i % 2:
                harmony.harmony = [0, 4, 7]
            else:
                harmony.harmony = [5, 9, 0]

    def setup_density_sections(self):
        n_density_sections = 121
        self.density_sections = Sections(n_density_sections, self.len_audio)
        density_values = np.linspace(4, 100, 121)
        for section, value in zip(self.density_sections, density_values):
            section.density = value

    def setup_register_sections(self):
        n_register_sections = 96 - 65
        low = 58
        high = 65
        self.register_sections = Sections(n_register_sections, self.len_audio)
        for section in self.register_sections:
            section.low = low
            section.high = high
            section.register = range(low, high)
            low = max([36, low - 1])
            high = min([96, high + 1])

    def go(self):
        max_start = len(self.audio) - 80000

        for density_section in self.density_sections:
            for i in range(int(density_section.density)):
                start = np.random.randint(
                    density_section.start,
                    min([density_section.next_start, max_start]))

                register_section = self.register_sections.get_by_sample_offset(
                    start)
                harmony_section = self.harmony_sections.get_by_sample_offset(
                    start)
                pitch_options = [
                    p for p in register_section.register
                    if p % 12 in harmony_section.harmony
                ]

                pitch = np.random.choice(pitch_options)

                note = self.marimba.get_note(pitch)

                self.audio.add(start, note)