def page_parse(url = None, text = None): 'Parses all song data from text taken from a result page.' 'Each entry corresponds to Song initialization data.' 'It will have to be formatted correctly to go to output.' 'The required format for Song class is:' '[artist, title, album, BPM, genre, label, year, key]' 'Type: String -> [Song]' # Condition for testing # For testing, set text = [[String]] type if url: text = AudioKC.raw_table_grab(url) songs = [] for raw_song_data in text: concatted_song = ''.join(raw_song_data) song_data = re.findall('<span class="[takb][^"]*?">(.*?)<', concatted_song) #song_data is in the form [title, artist, key, bpm] so must #convert to a valid form for Song class. formatted_song_data = [song_data[1], song_data[0], 'NULL', song_data[3], 'Null' , 'Null', 'Null' , song_data[2]] songs.append(music.Song(formatted_song_data)) return songs
def __init__(self, name, TEST=False): self.name = name if TEST: self.image_name = os.path.join('static', f'{name}.png') else: self.image_name = f'{name}.png' self.main = StaffDetector(self.image_name) # Calculate overlay sizing info self.radius = int(np.mean([s.note_size for s in self.main.staffs])) self.boldness = max(1, int(self.radius / 4)) # Draw overlays and display image self.copy = np.copy(self.main.image) # self.show_lines(self.copy) self.show_boxes(self.copy) self.show_notes(self.copy) self.plot(self.copy) # Construct Song and transcribe into tablature self.song = music.Song() for staff in self.main.staffs: for chord in staff.chords: self.song.add(chord) self.arr = player.Guitarist(self.song).arr print(f'{self.name}:\n{self.arr}')
def test_song_add(self): songs = [music.Song() for i in range(3)] songs[0].add(music.Note('E3')) songs[1].add(music.Chord(['E3'])) songs[2].add('E3') for song in songs: self.assertIn('E3', str(song.notes)) # This is sloppy
def read(self, song, DELTA=3): ''' This gradually pieces a song together via play(), to mitigate exponential complexity.''' path = [] # Play first three notes, and select best starting shape passage = music.Song(song.notes[:DELTA]) shape = self.play(passage) path.append(shape[0]) # Repeat in three-note sections, building off previous results for i in range(1, len(song) - DELTA): passage = music.Song([path[-1], *song.notes[i:i + DELTA + 1]]) shape = self.play(passage) try: path.append(shape[0]) except TypeError: continue # Ignore notes out of range # Add final notes for i in shape[1:]: path.append(i) return path
def test_mixed_notes(self): song = music.Song() bb_chords = [(['G3', 'B4'], 1 / 6), (['G4'], 1 / 6), (['A3', 'C5'], 1 / 6), (['G4'], 1 / 6), (['B3', 'D5'], 1 / 6), (['G4'], 1 / 6), (['G4', 'B5'], 1 / 4), (['G4'], 1 / 8), (['B5'], 1 / 8), (['G4'], 1 / 8), (['B5'], 1 / 8), (['G4'], 1 / 4)] for chord in bb_chords: song.add(music.Chord(*chord)) g = player.Guitarist(song) try: self.assertEqual(g.arr, blackbird) except AssertionError as AE: print(f'Blackbird, two bars, auto:\n{g.arr}') raise AE
def test_E_major(self): song = music.Song() for note in ('E3', 'F#3', 'G#3', 'A3', 'B3', 'C#4', 'D#4', 'E4'): song.add(music.Note(note, 1 / 8)) g = player.Guitarist(song) expected = ('|--------------------------------|\n' '|--------------------------------|\n' '|--------------------------------|\n' '|------------------------1---2---|\n' '|------------0---2---4-----------|\n' '|0---2---4-----------------------|\n\n') try: self.assertEqual(g.arr, expected) except AssertionError as AE: print(f'E major, one bar:\n{g.arr}') raise AE
def test_chords(self): song = music.Song() sotw_chords = [(['E3', 'B3', 'E4'], 1 / 4), (['G3', 'D4', 'G4'], 1 / 4), (['A3', 'E4', 'A4'], 3 / 8), (['E3', 'B3', 'E4'], 1 / 4), (['G3', 'D4', 'G4'], 1 / 4), (['B3', 'F#4', 'B4'], 1 / 8), (['A3', 'E4', 'A4'], 1 / 2)] for chord in sotw_chords: song.add(music.Chord(*chord)) g = player.Guitarist(song) try: self.assertEqual(g.arr, smoke_on_the_water) except AssertionError as AE: print(f'Smoke on the Water, two bars, auto:\n{g.arr}') raise AE
def __init__(self, song_title, difficulty='easy', debug=False): self.debug = debug self.song = music.Song(song_title, difficulty=difficulty) self.points = Points() # self.mp3 = Mp3() # beats self.beat_buffer = {k: [] for k in range(8)} # time self.time = time.ticks_ms self.ts_start = self.time() self.time_window_max = 200 # Beats buffer self.beat_last_ts = 0 self.beat_buffer_padding_ms = 500
def artist_grab(artist): 'Grabs and parses all songs by the artist in question' 'Relies on url_helper and song_parser to work' 'In this function the bool in url_helper is set to True' 'As we are searching for artists.' 'Type: String -> [Song]' artist = artist.rstrip().replace(' ','+') songs = [] begin = 0 url = BPMDB.url_helper(begin, True, artist) scraped_data = BPMDB.song_parse(url) while scraped_data: songs += [music.Song(song) for song in scraped_data] begin += 10 next_url = BPMDB.url_helper(begin, True, artist) scraped_data = BPMDB.song_parse(next_url) return songs
def main(): """Main method creates a TJ bot and starts it along with the console_input. main method """ F = open("convo_commands.txt", "w") thick_line = "================================================================================\n" thin_line = "--------------------------------------------------------------------------------\n" dash_line = "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \n" F.write(thick_line) F.write("Commands for MusicManager\n") F.write(thick_line) mm = music.MusicManager() for m in dir(mm): details = eval("pydoc.render_doc(mm." + m + ")") details = fix_line(details) out = "music." + details F.write(out) ss = music.Song("./resources/output.wav") for s in dir(ss): details = eval("pydoc.render_doc(ss." + s + ")") details = fix_line(details) out = "music." + details F.write(out) F.write(thick_line) F.write("Commands for LedManager\n") F.write(thick_line) lm = led.LedManager() for m in dir(lm): details = eval("pydoc.render_doc(lm." + m + ")") details = fix_line(details) out = "led." + details F.write(out) lm = led.NeoPixel() for m in dir(lm): details = eval("pydoc.render_doc(lm." + m + ")") details = fix_line(details) out = "led." + details F.write(out) F.write(thick_line) F.write("Commands for ServoManager\n") F.write(thick_line) lm = servo.ServoManager() for m in dir(lm): details = eval("pydoc.render_doc(lm." + m + ")") details = fix_line(details) out = "servo." + details F.write(out) se = servo.Servo() for m in dir(se): details = eval("pydoc.render_doc(se." + m + ")") details = fix_line(details) out = "servo." + details F.write(out)
def test_low_E(self): song = music.Song() song.add('E3') g = player.Guitarist(song) expected = tab.Bar(notes=[(tab.Shape((0, 0)), 1 / 4)]) self.assertEqual(g.arr, str(expected) + '\n')
def test_null_song(self): song = music.Song() g = player.Guitarist(song) self.assertEqual(g.arr, str(tab.Bar()) + '\n')