예제 #1
0
def activateKey(key):
    if currentMode > 0 or key > 3:
        fluidsynth.play_Note(Note(notes[currentMode][key]), modeChannels[currentMode], 70)
        print notes[currentMode][key]
    #the 96tears mode is unlike other modes in that the first two switches are drums and the next two switches play chords
    elif key == 0:
        fluidsynth.play_Note(drumSnare, 3, 90)
        print "Snare"  
    elif key == 1:
        fluidsynth.play_Note(drumBass, 3, 127)   
        print "Bass"
    elif key == 2:
        fluidsynth.play_NoteContainer(chordC7, 2, 60)    
        print "Chord C7"  
    elif key == 3:
        fluidsynth.play_NoteContainer(chordG, 2, 60)
        print "Chord G"
    
    #calculate neopixel color, each key is a different shade of the rainbow
    positionProduct = key*255
    notesLength = len(notes[currentMode])
    wheelPosition = positionProduct/notesLength
    #print "Color:", wheelPosition
    for i in range(strip.numPixels()):
        if i >= lightSegments[key][0] and i <= lightSegments[key][1]:
            strip.setPixelColor(i, wheel(wheelPosition))
    strip.show()
예제 #2
0
def main():
	#take first channel of file    
	Fs, data = wavfile.read(INPUT_FILE)
	y = data[:,0]

	#load piano soundfont
	SF2 = 'audio/FazioliGrandPiano.sf2'
	if not fluidsynth.init(SF2):
		print ("Couldn't load soundfont", SF2)
	
	#initialize variables for windowing
	sampSize = (Fs * WINDOW_LEN)/2
	prevStart = 0
	end = int(sampSize)
	totalSamp = int(len(y)/(sampSize*2) *2)

	#get the chords of the smoothed input
	for j in range(0,totalSamp):
		getFrequencies(smooth(y[prevStart:end]),Fs)
		prevStart += sampSize
		end += sampSize

	#play the chord back out again
	for idx,chord in enumerate(BAR):
		fluidsynth.play_NoteContainer(chord)
		time.sleep(PLAYBACK)
	time.sleep(PLAYBACK+0.3)
예제 #3
0
    def play(self):
        eighth_time = 0.125
        beat_time = eighth_time * 2
        bar_time = beat_time * self.beat_count

        fluidsynth.set_instrument(1, 0)
        fluidsynth.play_NoteContainer(self.chord)

        next_notes = list(self.melody.notes)
        playing_notes = []

        for eighth in range(self.beat_count * 2):
            # bar boundary?
            if eighth % 8 == 0:
                self.play_chord()

            try:
                next_note = next_notes[0]
            except IndexError as e:
                # if this is the last note, the above will throw an IndexError
                pass

            if next_note.start_eighth == eighth:
                next_notes.remove(next_note)
                playing_notes.append(next_note)

                print('subbeat {}: PLAY FOR {}: {}'.format(
                    eighth, next_note.eighth_count, next_note.note))
                fluidsynth.set_instrument(1, 0)
                fluidsynth.play_Note(next_note.note)

            for mel_note in list(playing_notes):
                if eighth == mel_note.start_eighth + mel_note.eighth_count:
                    print('subbeat {}: STOP        {}'.format(
                        eighth, mel_note.note))

                    # don't stop the note if the same note is being played somewhere else!
                    note_played_elsewhere = False
                    for note in playing_notes:
                        # skip over this one, we're interested in other notes
                        if note == mel_note:
                            continue
                        if note.note == mel_note.note:
                            note_played_elsewhere = True

                    if not note_played_elsewhere:
                        fluidsynth.stop_Note(mel_note.note)

                    playing_notes.remove(mel_note)

            time.sleep(eighth_time)
        # we should have played the exact
        # if it isn't, something went wrong somewhere
        if len(playing_notes) != 0:
            #raise RuntimeError('playing_notes wasn\'t empty at the end of segment.play()!')
            print('EOS playing_notes: {}'.format(playing_notes))
            for mel_note in playing_notes:
                fluidsynth.stop_Note(mel_note.note)
                playing_notes.remove(mel_note)
예제 #4
0
 def step(self, ticks):
     self.time += ticks
     new = [n for n in self.score.sounding_at(self.time) if not n in self.played]
     container = NoteContainer([note.fluidsynthname() for note in new])
     fluidsynth.play_NoteContainer(container)
     remove = [n for n in self.played if self.time >= n.delay + n.duration]
     self.played.difference_update(remove)
     self.played.update(new)
예제 #5
0
 def play_note(self, discord=0):
     if discord:
         self._current_note = self.generate_discord_container(self._current_num)
     elif self._current_num == 0:
         self._current_note = self.generate_base_container("C")
     else:
         self._current_note = self.generate_triad_container(self._current_num, "C")
     fluidsynth.play_NoteContainer(self._current_note, 0, 100)
예제 #6
0
 def play(self, events):
     notes_on = [e.to_ming_note() for e in events if e.command_type == 'NOTE_ON']
     notes_off = [e.to_ming_note() for e in events if e.command_type == 'NOTE_OFF']
     for note in notes_off:
         self.validator.add_gamer_note(note, 'NOTE_OFF')
     fluidsynth.stop_NoteContainer(NoteContainer(notes_off))
     for note in notes_on:
         self.validator.add_gamer_note(note, 'NOTE_ON')
     fluidsynth.play_NoteContainer(NoteContainer(notes_on))
예제 #7
0
	def test_playnotecontainer(self):
		self.assert_(fluidsynth.play_NoteContainer(NoteContainer(["C", "E", "G"]), 0))
		time.sleep(0.25)
		fluidsynth.stop_NoteContainer(NoteContainer(["C", "E", "G"]), 0)


		self.assert_(fluidsynth.play_NoteContainer(NoteContainer(["E", "G", Note("C", 6)]), 0))
		time.sleep(0.25)
		fluidsynth.stop_NoteContainer(NoteContainer(["E", "G", Note("C", 6)]), 0)
예제 #8
0
 def play_note(self, discord=0):
     if discord:
         self._current_note = self.generate_discord_container(
             self._current_num)
     elif self._current_num == 0:
         self._current_note = self.generate_base_container("C")
     else:
         self._current_note = self.generate_triad_container(
             self._current_num, "C")
     fluidsynth.play_NoteContainer(self._current_note, 0, 100)
예제 #9
0
 def test_playnotecontainer(self):
     self.assert_(fluidsynth.play_NoteContainer(NoteContainer(['C', 'E', 'G'
                  ]), 0))
     time.sleep(0.25)
     fluidsynth.stop_NoteContainer(NoteContainer(['C', 'E', 'G']), 0)
     self.assert_(fluidsynth.play_NoteContainer(NoteContainer(['E', 'G',
                  Note('C', 6)]), 0))
     time.sleep(0.25)
     fluidsynth.stop_NoteContainer(NoteContainer(['E', 'G', Note('C', 6)]),
                                   0)
예제 #10
0
 def test_playnotecontainer(self):
     self.assert_(fluidsynth.play_NoteContainer(NoteContainer(['C', 'E', 'G'
                  ]), 0))
     time.sleep(0.25)
     fluidsynth.stop_NoteContainer(NoteContainer(['C', 'E', 'G']), 0)
     self.assert_(fluidsynth.play_NoteContainer(NoteContainer(['E', 'G',
                  Note('C', 6)]), 0))
     time.sleep(0.25)
     fluidsynth.stop_NoteContainer(NoteContainer(['E', 'G', Note('C', 6)]),
                                   0)
예제 #11
0
 def test_playnotecontainer(self):
     self.assertTrue(
         fluidsynth.play_NoteContainer(NoteContainer(["C", "E", "G"]), 0))
     time.sleep(0.25)
     fluidsynth.stop_NoteContainer(NoteContainer(["C", "E", "G"]), 0)
     self.assertTrue(
         fluidsynth.play_NoteContainer(
             NoteContainer(["E", "G", Note("C", 6)]), 0))
     time.sleep(0.25)
     fluidsynth.stop_NoteContainer(NoteContainer(["E", "G",
                                                  Note("C", 6)]), 0)
예제 #12
0
def play_basic_chord(chord):
    c = NoteContainer(chord)
    l = Note(c[0].name)
    l.octave_down()
    print ch.determine(chord)[0]

    # Play chord and lowered first note
    fluidsynth.play_NoteContainer(c)
    fluidsynth.play_Note(l)
    time.sleep(1.0)

    return c
예제 #13
0
def play_basic_chord(chord):
   c = NoteContainer(chord)
   l = Note(c[0].name)
   l.octave_down()
   print ch.determine(chord)[0]
	
   # Play chord and lowered first note
   fluidsynth.play_NoteContainer(c)
   fluidsynth.play_Note(l)
   time.sleep(1.0)
	
   return c
예제 #14
0
def play_offset(off, sleep_s=0.2, song=sonata, repeats=5, down_octaves=1, instrument=None):
        song = song * repeats
        if instrument is not None:
                for i in range(off):
                        fluidsynth.set_instrument(i+1, instrument)
        for i in range(len(song)+off):
                to_stop = i - off
                if to_stop >= 0:
                        fluidsynth.stop_NoteContainer(NoteContainer([a + "-" + str(int(b)-down_octaves) for (a, b) in song[to_stop].split()]), channel=(to_stop%off)+1)
                if i < len(song):
                        fluidsynth.play_NoteContainer(NoteContainer([a + "-" + str(int(b)-down_octaves) for (a, b) in song[i].split()]), channel=(i%off)+1, velocity=127)
                time.sleep(sleep_s)
예제 #15
0
def playProgression():
    progression = ["I", "vi", "ii", "iii7", "I7", "viidom7", "iii7", "V7"]
    key = "C"

    chords = progressions.to_chords(progression, key)

    if not fluidsynth.init(SF2):
        print "Couldn't load soundfont", SF2
        sys.exit(1)

    while 1:
        i = 0
        for chord in chords:
            c = NoteContainer(chords[i])
            l = Note(c[0].name)
            p = c[1]
            l.octave_down()
            print ch.determine(chords[i])[0]

            # Play chord and lowered first note
            fluidsynth.play_NoteContainer(c)
            fluidsynth.play_Note(l)
            time.sleep(1.0)

            # Play highest note in chord
            fluidsynth.play_Note(c[-1])

            # 50% chance on a bass note
            if random() > 0.5:
                p = Note(c[1].name)
                p.octave_down()
                fluidsynth.play_Note(p)
            time.sleep(0.50)

            # 50% chance on a ninth
            if random() > 0.5:
                l = Note(intervals.second(c[0].name, key))
                l.octave_up()
                fluidsynth.play_Note(l)
            time.sleep(0.25)

            # 50% chance on the second highest note
            if random() > 0.5:
                fluidsynth.play_Note(c[-2])
            time.sleep(0.25)

            fluidsynth.stop_NoteContainer(c)
            fluidsynth.stop_Note(l)
            fluidsynth.stop_Note(p)
            i += 1
        print "-" * 20
예제 #16
0
def resolve_chord_tone(chord, tone, Ioctave):
    # play_progression([numeral], st.KEY, Ioctave=Ioctave)

    if st.ALTERNATIVE_CHORD_TONE_RESOLUTION == 1:
        fluidsynth.play_NoteContainer(chord)
        play_wait()
        fluidsynth.play_Note(tone)
        play_wait()
        root = chord[0]
        interval = NoteContainer([root, tone])
        fluidsynth.play_NoteContainer(interval)
    elif st.ALTERNATIVE_CHORD_TONE_RESOLUTION == 2:
        fluidsynth.play_NoteContainer(chord)
        play_wait()
        tone_idx = [x for x in chord].index(tone)
        if tone_idx == 0:
            arpeggiate()
        elif tone_idx == 1:
            arpeggiate(invert=[1, 0, 2])
        elif tone_idx == 2:
            arpeggiate(descending=True)
        else:
            raise Exception("This chord tone resolutions mode is only "
                            "implemented for triads.")

        # fluidsynth.play_Note(Iup_note)
        # Iup_note = Note(st.KEY)
        # Iup_note.octave += 1
        # fluidsynth.play_Note(Iup_note)
    else:
        fluidsynth.play_NoteContainer(chord)
        play_wait()
        fluidsynth.play_Note(tone)
        play_wait()
        arpeggiate()  # sets NEWQUESTION = False
예제 #17
0
파일: play.py 프로젝트: jld73/deep-harmony
def play_notes(notes):
    currtime = 0
    for note in sorted(notes):
        #       print "Note:", note[0], note[1], note[2], "currtime:", currtime

        if currtime < note[0]:
            sleeptime = (note[0] - currtime) * secondsPerBeat
            time.sleep(sleeptime)
            currtime = note[0]

        if note[2] == 'E':
            fluidsynth.stop_NoteContainer(note[1], channel)
        if note[2] == 'S':
            fluidsynth.play_NoteContainer(note[1], channel, velocity=note[3])
예제 #18
0
    def play(self):
        intro = self.segments['intro']
        fluidsynth.play_NoteContainer(intro.chord)
        time.sleep(0.25 * 8)
        fluidsynth.stop_NoteContainer(intro.chord)
        # intro, verse, chorus, verse, chorus, bridge, chorus
        play_pattern = [0, 1, 2, 1, 2, 3, 2]
        for segment_index in play_pattern:
            print('Playing {} segment'.format(
                Song.SEGMENT_ORDER[segment_index]))
            self.segments[Song.SEGMENT_ORDER[segment_index]].play()

        outro = self.segments['chorus']
        for i in range(3):
            fluidsynth.play_NoteContainer(outro.chord)
            time.sleep(0.25 * 8)
            fluidsynth.stop_NoteContainer(outro.chord)
예제 #19
0
파일: improv.py 프로젝트: djfoote/atunal
def play_smart_solo_over_chords(chord_list):
	fluidsynth.set_instrument(13, 45)
	fluidsynth.set_instrument(10, 108)

	fluidsynth.main_volume(13, 75)
	fluidsynth.main_volume(10, 100)
	
	solo = Track()

	bars = generate_solo(chord_list)
	for i in range(len(bars)):
		chord = NoteContainer(chords.from_shorthand(chord_list[i]))
		bar = bars[i]
		fluidsynth.play_NoteContainer(chord, 13)
		fluidsynth.play_Bar(bar, 10)
		fluidsynth.stop_NoteContainer(chord, 13)
		solo.add_bar(bar)
	return solo
예제 #20
0
def play_file(file_path='samplefile.py'):
    with open(file_path) as file_descriptor:
        lengths = list(map(len, file_descriptor))

    timed_notes = []
    for index_len, length in enumerate(lengths, 1):
        timed_notes.append([
            TimedNote(sum(lengths[index_range:index_len]) - 1, Note(50 + index_range * 4))
            for index_range, note_cap in enumerate(lengths[0:min(index_len, NOTE_RANGE)])
        ])

    sorted_notes = sorted(chain.from_iterable(timed_notes), key=attrgetter('time'))
    timed_containers = [
        TimedNoteContainer(time, NoteContainer(map(attrgetter('note'), timed_notes)))
        for time, timed_notes in groupby(sorted_notes, key=attrgetter('time'))
    ]

    current_time = 0
    for timed_container in timed_containers:
        sleep((timed_container.time - current_time) * SPEED)
        current_time = timed_container.time
        fluidsynth.play_NoteContainer(timed_container.container)
예제 #21
0
	def test_control_change(self):
		for x in range(0, 128, 20):
			fluidsynth.midi.control_change(1, 13,x)
			fluidsynth.play_NoteContainer(NoteContainer(["C", "E", "G"]), 0)
			time.sleep(0.25)
예제 #22
0
chords = progressions.to_chords(progression, key)
if not fluidsynth.init(SF2):
    print("Couldn't load soundfont", SF2)
    sys.exit(1)
while 1:
    i = 0
    for chord in chords:
        c = NoteContainer(chords[i])
        l = Note(c[0].name)
        p = c[1]
        l.octave_down()
        print(ch.determine(chords[i])[0])

        # Play chord and lowered first note

        fluidsynth.play_NoteContainer(c)
        fluidsynth.play_Note(l)
        time.sleep(1.0)

        # Play highest note in chord

        fluidsynth.play_Note(c[-1])

        # 50% chance on a bass note

        if random() > 0.50:
            p = Note(c[1].name)
            p.octave_down()
            fluidsynth.play_Note(p)
        time.sleep(0.50)
예제 #23
0
def play_stop_NoteContainer(noteContainer, duration):
    fluidsynth.play_NoteContainer(noteContainer)
    sleep(duration)
    fluidsynth.stop_NoteContainer(noteContainer)
예제 #24
0
 def test_main_volume(self):
     for x in range(0, 128, 20):
         fluidsynth.midi.main_volume(1, x)
         fluidsynth.midi.main_volume(2, x)
         fluidsynth.play_NoteContainer(NoteContainer(["C", "E", "G"]), 0)
         time.sleep(0.25)
예제 #25
0
 def test_control_change(self):
     for x in range(0, 128, 20):
         fluidsynth.midi.control_change(1, 13, x)
         fluidsynth.play_NoteContainer(NoteContainer(["C", "E", "G"]), 0)
         time.sleep(0.25)
예제 #26
0
 def play_chord(self):
     fluidsynth.stop_NoteContainer(self.chord)
     fluidsynth.set_instrument(1, 0)
     fluidsynth.play_NoteContainer(self.chord)
예제 #27
0
 def processSteps(self, steps, oldSteps=None, chord=False):
     if oldSteps is not None:
         steps = getNewSteps(steps, oldSteps)
     for step, sound in zip(steps, self.soundArr):
         if step and not chord:
             fluidsynth.play_NoteContainer(sound)
예제 #28
0
	def test_main_volume(self):
		for x in range(0, 128, 20):
			fluidsynth.midi.main_volume(1, x)
			fluidsynth.midi.main_volume(2, x)
			fluidsynth.play_NoteContainer(NoteContainer(["C", "E", "G"]), 0)
			time.sleep(0.25)
예제 #29
0
if not fluidsynth.init(SF2):
	print "Couldn't load soundfont", SF2
	sys.exit(1)

while 1:
	i = 0 
	for chord in chords:
		c = NoteContainer(chords[i])
		l = Note(c[0].name)
		p = c[1]
		l.octave_down()
		print ch.determine(chords[i])[0]

		# Play chord and lowered first note
		fluidsynth.play_NoteContainer(c)
		fluidsynth.play_Note(l)
		time.sleep(1.0)

		# Play highest note in chord
		fluidsynth.play_Note(c[-1])

		# 50% chance on a bass note
		if random() > 0.5:
			p = Note(c[1].name)
			p.octave_down()
			fluidsynth.play_Note(p)
		time.sleep(0.50)
		
		# 50% chance on a ninth
		if random() > 0.5:
예제 #30
0
 def play_column(self):
     notes = self.column_to_notes(self.active_col)
     fluidsynth.play_NoteContainer(notes)
예제 #31
0
            # ADQUISICIÓN DE IMAGENES
            video = k.getVideo()
            depthFrame = k.getDepth()

            if not (video is None) and not (depthFrame is None):
                videoFrame = procesovideo.add_image(video,
                                                    PATH_TECLADO_VIRTUAL)

                # PROCESAMIENTO
                posx, posy, notes = procesovideo.procesa_video(
                    depthFrame, videoFrame)

                # NOTAS
                NotasPres = notes

                fluidsynth.play_NoteContainer(NotasPres)
                ventana.notes = NotasPres
                ventana.mano_state = procesovideo.estado_list
                ventana.mano_posx = posx
                ventana.mano_posy = posy

                # RENDERIZACIÓN DE RESULTADOS
                if ventana.is_show_pasos:
                    # La imagen procesada se guarda en la pantalla sin escalar, por lo que el
                    # segundo atributo es False y el tamaño es []
                    ventana.image_kinect = ventana.cvimage_a_pygame(
                        videoFrame, False, [])
                    # se ingresan en forma de arreglo los pasos a mostrar en la interfaz.
                    Pasos_proceso = [
                        depthFrame,
                        procesovideo.medianDepth.astype(np.uint8),
예제 #32
0
            frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

            detected = eyes.detectMultiScale(frame, 1.3, 5)  # 1.3, 5

            if not len(detected):
                has_user_counter = 0
                has_user_timeout += 1

                if has_user_timeout > HAS_USER_WAIT:
                    has_user = False
                elif has_user and detect_timer > DETECT_WAIT:
                    detect_timer = 0

                    print('========= BLINK =========')

                    fluidsynth.play_NoteContainer(notes)

                    for note in notes:
                        print(note, int(note), note.next_octave,
                              (BASE_OCTAVE + note.next_octave) * 12)
                        new_note = (int(note) + 1) % 12
                        if new_note == 0:
                            note.next_octave = not note.next_octave
                        note = note.from_int((BASE_OCTAVE + note.next_octave) *
                                             12 + new_note)

            else:
                has_user_counter += 1
                has_user_timeout = 0
                if not has_user and has_user_counter > HAS_USER_WAIT:
                    has_user = True
예제 #33
0
def generate_accompaniment(net_output_chords):
    generated_chords = []
    chords = []
    for chord in net_output_chords:
        root, key = (chord.split(":"))
        print(root, key)
        if key == 'maj':
            chords.append(ch.major_triad(root))
        if key == 'min':
            chords.append(ch.minor_triad(root))      

    print(chords)  

    key = chords[0][0]
    print('key', key)
    if not fluidsynth.init(SF2):
        print("Couldn't load soundfont", SF2)
        sys.exit(1)

    print(dir(fluidsynth.midi))
    # fluidsynth.midi.start_audio_output()
    fluidsynth.midi.start_recording()
    phrase = 0
    while phrase == 0:
        i = 0
        for chord in chords:
            print("chord", chord)
            c = NoteContainer(chords[i])
            generated_chords.append([{'note':cc.name.replace("B#","B").replace("E#","E").replace("##","#"), 'octave':cc.octave} for cc in c])
            l = Note(c[0].name)
            p = c[1]
            l.octave_down()
            print(ch.determine(chords[i])[0])

            # Play chord and lowered first note
            # fluidsynth.midi.MidiFileOut.write_NoteContainer("test.mid", c)
            print("NEW CHORD = ", c)

            if PLAY_ENABLED:

                fluidsynth.play_NoteContainer(c)
                fluidsynth.play_Note(l)
                time.sleep(1.0)

                # Play highest note in chord
                fluidsynth.play_Note(c[-1])

                # 50% chance on a bass note

                if random() > 0.50:
                    p = Note(c[1].name)
                    p.octave_down()
                    fluidsynth.play_Note(p)
                time.sleep(0.50)

                # 50% chance on a ninth

                if random() > 0.50:
                    l = Note(intervals.second(c[0].name, key))
                    l.octave_up()
                    fluidsynth.play_Note(l)
                time.sleep(0.25)

                # 50% chance on the second highest note

                if random() > 0.50:
                    fluidsynth.play_Note(c[-2])
                time.sleep(0.25)
                fluidsynth.stop_NoteContainer(c)
                fluidsynth.stop_Note(l)
                fluidsynth.stop_Note(p)
            i += 1
        print("-" * 20)
        phrase = 1
        return generated_chords
예제 #34
0
파일: improv.py 프로젝트: djfoote/atunal
def play_solo_bar_with_chord(chord_name):
	chord = NoteContainer(chords.from_shorthand(chord_name))
	solo = solo_bar(chord_name)
	fluidsynth.play_NoteContainer(chord, 13)
	fluidsynth.play_Bar(solo, 10)
	fluidsynth.stop_NoteContainer(chord, 13)
예제 #35
0
파일: try1.py 프로젝트: dpkay/voicings
c = ChordTemplate()
c.SetNotes('D-3', 'G-3', 'C-4', 'F-4', 'A-4')
c.AddCharacter(ChordCharacter('D', 'm7', 'SoWhat'))
templates.append(c)

c = ChordTemplate()
c.SetNotes('F-3', 'B-3', 'E-4', 'A-4', 'D-5')
c.AddCharacter(ChordCharacter('D', '69', 'Fourths'))
c.AddCharacter(ChordCharacter('D', '69', 'Fourths'))
templates.append(c)

#print(notes.is_valid_note("D#"))

#nc = NoteContainer(['C', 'E', 'G'])
# middle Aminor is A3, C4, E4
#a = Note('A-3')
#n.from_int(44)
#nc = NoteContainer()
#nc += a
nc1 = templates[0].GetContainer()
nc2 = templates[1].GetContainer()

#fluidsynth.init("AJH_Piano.sf2","coreaudio","foo.wav")
fluidsynth.init("SalC5Light2.sf2", "coreaudio", "foo.wav")
fluidsynth.play_NoteContainer(nc1)
fluidsynth.midi.sleep(.2)
fluidsynth.stop_NoteContainer(nc1)
fluidsynth.play_NoteContainer(nc2)
fluidsynth.midi.sleep(1)
fluidsynth.stop_NoteContainer(nc2)
예제 #36
0
	def play_chord(self,note_length,chord,velocity):
		synth.play_NoteContainer(NoteContainer().from_chord(chord),velocity=velocity) #if it is not create chord from string
		time.sleep(self.me_time*note_length)
예제 #37
0
loop = 1
while loop < song_end:
    i = 0
    if random_solo_channel:
        solo_channel = choice(range(5, 8) + [11])
    for chord in chords:
        c = NoteContainer(chords[i])
        l = Note(c[0].name)
        n = Note('C')
        l.octave_down()
        l.octave_down()
        print ch.determine(chords[i])[0]

        if not swing and play_chords and loop > chord_start and loop\
             < chord_end:
            fluidsynth.play_NoteContainer(c, chord_channel, randrange(50, 75))
        if play_chords and loop > chord_start and loop < chord_end:
            if orchestrate_second:
                if loop % 2 == 0:
                    fluidsynth.play_NoteContainer(c, chord_channel2,
                            randrange(50, 75))
            else:
                fluidsynth.play_NoteContainer(c, chord_channel2, randrange(50,
                        75))

        if double_time:
            beats = [random() > 0.5 for x in range((loop % 2 + 1) * 8)]
        else:
            beats = [random() > 0.5 for x in range(8)]
        t = 0
        for beat in beats:
예제 #38
0
	def play(self, state):


		if not(self.midi_set):
			self.set_instrument()

		if state["tick"] == 0:
			self.record_new_bar(state)

		self.stop_playing_notes()

		note_length = self.get_note_length(state)
		max_notes = self.get_max_simultaneous_notes(state)
		range_min, range_max = self.get_range(state)

				

		dur = state["resolution"]
		if state["swing"]:
			if state["tick"] % 2 == 0:
				dur = 1.0 / (1.0 / dur * (2.0 / 3.0))
			else:
				dur = 1.0 / (1.0 / dur * (4.0 / 3.0))

		n = self.generate_note(state)
		if n is None:
			n = []
		v = int(self.generate_velocity(state))
		c = self.params["channel"]


		if max_notes != -1 and n != []:
			curn = self.len_current_notes_playing()
			if curn >= max_notes:
				n = []
			elif curn + len(n) > max_notes:
				n = n[:max_notes - curn]

		newn = []
		for note in n:
			if int(note) >= range_min and int(note) <= range_max:
				note.velocity = v
				note.channel = c
				newn.append(note)

		n = newn

		if n != [] and max_notes != 0:
					
			
			#if self.last_bpm != state["bpm"]:
			#	self.last_bpm = state["bpm"]
			#	n = NoteContainer(n)
			#	n.bpm = state["bpm"]

			self.record_notes(state, n, dur)

			if not self.no_fluidsynth:
				fluidsynth.play_NoteContainer(n, c, v)

			self.playing.append([n, note_length])
			self.last_chan = c
			self.last_played = n
			if state["paint_function"] != None:
				state["paint_function"](n, c)
		else:
			self.record_rest(dur)

		self.last_tick = (state["iterations"], state["tick"])