def fill_list(self): self.index = 0 self.list_data = [] status = self.get_status() if status == "REC" or status == "PLAY+REC": self.list_data.append(("STOP_RECORDING", 0, "Stop Recording")) else: self.list_data.append(("START_RECORDING", 0, "Start Recording")) if status == "PLAY" or status == "PLAY+REC": self.list_data.append(("STOP_PLAYING", 0, "Stop Playing")) self.show_playing_bpm() if zynthian_gui_config.midi_play_loop: self.list_data.append(("LOOP", 0, "[x] Loop Play")) else: self.list_data.append(("LOOP", 0, "[ ] Loop Play")) self.list_data.append((None, 0, "-----------------------------")) i = 1 # Files in SD-Card for f in sorted(os.listdir(self.capture_dir_sdc)): fpath = join(self.capture_dir_sdc, f) if isfile(fpath) and f[-4:].lower() == '.mid': try: length = SMF(fpath).info.length title = "SDC: {} [{}:{:02d}]".format( f[:-4], int(length / 60), int(length % 60)) self.list_data.append((fpath, i, title)) i += 1 except Exception as e: logging.warning(e) # Files on USB-Pendrive for f in sorted(os.listdir(self.capture_dir_usb)): fpath = join(self.capture_dir_usb, f) if isfile(fpath) and f[-4:].lower() == '.mid': try: length = SMF(fpath).info.length title = "USB: {} [{}:{:02d}]".format( f[:-4], int(length / 60), int(length % 60)) self.list_data.append((fpath, i, title)) i += 1 except Exception as e: logging.warning(e) super().fill_list()
class TSMF(TestCase): def setUp(self): self.audio = SMF(os.path.join(DATA_DIR, "sample.mid")) def test_length(self): self.failUnlessAlmostEqual(self.audio.info.length, 127.997, 2) def test_not_my_file(self): self.failUnlessRaises( SMFError, SMF, os.path.join(DATA_DIR, "empty.ogg")) def test_pprint(self): self.audio.pprint() self.audio.info.pprint() def test_mime(self): self.assertTrue("audio/x-midi" in self.audio.mime) self.assertTrue("audio/midi" in self.audio.mime)
def load(self, midi_file_path): """ Song loader.""" # Save the file path. self._midi_file_path = midi_file_path # Load the song. self._mixer.music.load(self._midi_file_path) # Get the song duration. self.song_duration = SMF(midi_file_path).info.length # Indicate that a new song was loaded. self._new_song = True # Set the flag that indicates that the song can be played. self._play = False
def audioFile(audio): aud_str = str(audio) if aud_str.endswith(".mp3"): aud1 = MP3(audio) len1 = aud1.info.length return int(len1) elif aud_str.endswith('.wav'): aud2 = WAVE(audio) len2 = aud2.info.length return int(len2) elif aud_str.endswith('.flac'): aud3 = FLAC(audio) len3 = aud3.info.length return int(len3) elif aud_str.endswith('.aac'): aud4 = AAC(audio) len4 = aud4.info.length return int(len4) elif aud_str.endswith('.ac3'): aud5 = AC3(audio) len5 = aud5.info.length return int(len5) elif aud_str.endswith('.aiff'): aud6 = AIFF(audio) len6 = aud6.info.length return int(len6) elif aud_str.endswith('.asf'): aud7 = ASF(audio) len7 = aud7.info.length return int(len7) elif aud_str.endswith('.dsf'): aud8 = DSF(audio) len8 = aud8.info.length return int(len8) elif aud_str.endswith('.mp4'): aud9 = MP4(audio) len9 = aud9.info.length return int(len9) elif aud_str.endswith('.smf'): aud10 = SMF(audio) len10 = aud10.info.length return int(len10) elif aud_str.endswith('.ogg'): aud12 = OggFileType(audio) len12 = aud12.info.length return int(len12) else: return str("File type not supported.")
def __init__(self, filename): with translate_errors(): audio = SMF(filename) self["~#length"] = audio.info.length self.sanitize(filename)
def setUp(self): self.audio = SMF(os.path.join(DATA_DIR, "sample.mid"))