def test_note2midi_known_values_with_unicode_issues(self, note, midi): " known values are correctly converted, unless decoding is expected to fail" try: self.assertEqual ( note2midi(note), midi ) except UnicodeEncodeError as e: import sys strfmt = "len(u'\\U0001D12A') != 1, excpected decoding failure | {:s} | {:s} {:s}" strres = strfmt.format(e, sys.platform, sys.version) # happens with: darwin 2.7.10, windows 2.7.12 if len('\U0001D12A') != 1 and sys.version[0] == '2': self.skipTest(strres + " | upgrade to Python 3 to fix") else: raise
def test_note2midi_known_values_with_unicode_issues(self, note, midi): " difficult values are correctly converted unless expected failure " try: assert note2midi(note) == midi except UnicodeEncodeError as e: # platforms with decoding failures include: # - osx: python <= 2.7.10 # - win: python <= 2.7.12 import sys strmsg = "len(u'\\U0001D12A') != 1, expected decoding failure" strmsg += " | upgrade to Python 3 to fix" strmsg += " | {:s} | {:s} {:s}" if len('\U0001D12A') != 1 and sys.version[0] == '2': skipTest(strmsg.format(repr(e), sys.platform, sys.version)) else: raise
def GuessNominalFreqFromFileName(self): '''tries to guess note frequency from the file name ''' import aubio import re tokens = re.findall('([A-Ga-g][sS#bB+-]*\d+)', self.name) try: notename = re.sub('s', '#', tokens[0]) f = aubio.miditofreq(aubio.note2midi(notename)) except (ValueError, IndexError): f = np.NaN return f
def test_note2midi_known_values(self, note, midi): " known values are correctly converted " assert note2midi(note) == midi
def test_note2midi_known_values(self, note, midi): " known values are correctly converted " self.assertEqual ( note2midi(note), midi )
def test_note2midi_known_values(self): " known values are correctly converted " for note, midi in list_of_known_notes: self.assertEqual ( note2midi(note), midi )
def test_note2midi_known_values(self): " known values are correctly converted " for note, midi in list_of_known_notes: self.assertEqual(note2midi(note), midi)
# main loop while True: try: # read data from audio input _, data = recorder.read() # convert data to aubio float samples samples = np.fromstring(data, dtype=aubio.float_type) #plt.plot(samples) #plt.show() if len(samples): # pitch of current frame freq = pitcher(samples)[0] try: note = aubio.freq2note(freq) midi = aubio.note2midi(note) volume = np.sum(samples**2) / len(samples) vel = (volume - VOL_OFFSET) / (1 - VOL_OFFSET) * 112 if volume > VOL_OFFSET: print("{:3} {}".format(note, volume)) if last_midi != midi: midiout.send_message([0x90, midi, vel]) # note on print("midi: " + str(midi)) last_midi = midi elif volume < .6: midiout.send_message([CONTROL_CHANGE, ALL_SOUND_OFF, 0]) last_midi = 0 except ValueError: print("warn: ValueError") except KeyboardInterrupt: print("Ctrl+C pressed, exiting")