while True: if not startflag: ser.readline() #入力信号を待ってループを開始する startflag = True k = np.random.randint(0,100) if k < 90: modulation = np.random.randint(0,7) notes = chord.note_modulate(modulation) d_chords = chord.d_chord_modulate(notes) nd_chords = chord.nd_chord_modulate(notes) melody_pitches = chord.melody_pitches_modulate(notes) pat_id = chord.next_chord(pat_id) var = chord.create_chord_prog(pat_id) backing = chord.translate_chord_freq(var, d_chords, nd_chords) melody = chord.create_melody(var, melody_pitches, notes) for bar_m, bar_b in zip(melody, backing): for note_m, note_b in zip(bar_m, bar_b): ser.write(formatfreq(note_m)) ser.write(formatfreq(note_b)) #print(formatfreq(note_m)) #print(formatfreq(note_b)) if ser.inWaiting(): lx = int(ser.readline()) time.sleep(delaytimeFromLx(lx)) #time.sleep(2) ser.close()