def testReadWriteEquals(tmpdir, filename): filepath = path.join(LOCATION, filename) songA = gp.parse(filepath) destpath = str(tmpdir.join(filename)) gp.write(songA, destpath) songB = gp.parse(destpath) assert songA == songB
def testClipboard(tmpdir): filepath = path.join(LOCATION, '2 whole bars.tmp') songA = gp.parse(filepath) songA.clipboard = None destpath = str(tmpdir.join('2 whole bars.tmp.gp5')) gp.write(songA, destpath) songB = gp.parse(destpath) assert songA == songB
def testConversion(tmpdir, source, targetExt): sourcepath = path.join(LOCATION, source) songA = gp.parse(sourcepath) songA.versionTuple = None # Remove the version so it's determined by the extension destpath = str(tmpdir.join(f'{source}.{targetExt}')) gp.write(songA, destpath) songB = gp.parse(destpath) assert songA == songB
def convert_and_compare(filename): __, ext = path.splitext(filename) filepath = path.join(LOCATION, filename) song_a = guitarpro.parse(filepath) destpath = path.join(OUTPUT, filename + ext) guitarpro.write(song_a, destpath) song_b = guitarpro.parse(destpath) assert song_a == song_b
def test_clipboard(output_folder): filepath = path.join(LOCATION, '2 whole bars.tmp') song_a = guitarpro.parse(filepath) song_a.clipboard = None destpath = path.join(output_folder, '2 whole bars.tmp.gp5') guitarpro.write(song_a, destpath) song_b = guitarpro.parse(destpath) assert song_a == song_b
def test_clipboard(tmpdir): filepath = path.join(LOCATION, '2 whole bars.tmp') song_a = guitarpro.parse(filepath) song_a.clipboard = None destpath = str(tmpdir.join('2 whole bars.tmp.gp5')) guitarpro.write(song_a, destpath) song_b = guitarpro.parse(destpath) assert song_a == song_b
def test_conversion(output_folder, filename): __, ext = path.splitext(filename) filepath = path.join(LOCATION, filename) song_a = guitarpro.parse(filepath) destpath = path.join(output_folder, filename + ext) guitarpro.write(song_a, destpath) song_b = guitarpro.parse(destpath) assert song_a == song_b
def test_chord(tmpdir, filename): filepath = path.join(LOCATION, filename) song = guitarpro.parse(filepath) assert song.tracks[0].measures[0].voices[0].beats[ 0].effect.chord is not None destpath = str(tmpdir.join('no_chord_strings.gp5')) guitarpro.write(song, destpath) song2 = guitarpro.parse(destpath) assert song == song2
def testGuessVersion(tmpdir): filename = 'Effects.gp5' filepath = path.join(LOCATION, filename) songA = gp.parse(filepath) songA.version = songA.versionTuple = None for ext, versionTuple in gp.io._EXT_VERSIONS.items(): if ext == 'tmp': continue destpath = str(tmpdir.join(filename + '.' + ext)) gp.write(songA, destpath) songB = gp.parse(destpath) assert songB.versionTuple == versionTuple
def test_guess_version(output_folder): filename = 'Effects.gp5' filepath = path.join(LOCATION, filename) song_a = guitarpro.parse(filepath) song_a.version = song_a.versionTuple = None for ext, versionTuple in guitarpro.io._EXT_VERSIONS.items(): if ext == 'tmp': continue destpath = path.join(output_folder, filename + '.' + ext) guitarpro.write(song_a, destpath) song_b = guitarpro.parse(destpath) assert song_b.versionTuple == versionTuple
def readFile(): # Finds songs in newSongs directory mydir = './validate/newSongs' files = listdir(mydir) noteList = [] # For each note e.g. C, E ,G # Converts each gp file into a list for gpfile in files: try: print('Found key for ', gpfile) curl = guitarpro.parse(mydir + '/' + gpfile) songKey = curl.key.name # Not C Major default files if str(songKey) == "CMajor": os.remove(mydir + '/' + gpfile) print('Removed -', gpfile, '- Key not found') else: # Convert to List convertToList(noteList, curl) except: # Error handling pass myFile = 'New Songs' processSong(noteList, myFile)
def testChord(tmpdir, caplog, filename): filepath = path.join(LOCATION, filename) song = gp.parse(filepath) assert song.tracks[0].measures[0].voices[0].beats[ 0].effect.chord is not None destpath = str(tmpdir.join('no_chord_strings.gp5')) gp.write(song, destpath) if filename == 'Unknown Chord Extension.gp5': iobase_logs = [ log for log in caplog.records if log.name == 'guitarpro.iobase' ] [record] = iobase_logs assert 'is an unknown ChordExtension' in record.msg song2 = gp.parse(destpath) assert song == song2
def save_file(self): fname = QtWidgets.QFileDialog.getSaveFileName( self, 'Open file', 'c:\\', "GuitarPro files (*.gp3 *.gp4 *.gp5)") if fname[0] != '': guitars = [] tab1 = guitarpro.parse(self.path) for i in self.guitarTracksList: for j in tab1.tracks: if i.name == j.name: guitars.append(j) tab = guitarpro.models.Song() tab.tempo = guitars[0].song.tempo tab.version = 'FICHIER GUITAR PRO v3.00' tab.tracks = guitars nnd = Neural_network_drums.NeuralNetwork('weights/rock_drums.h5') nnb = Neural_network_bass.NeuralNetwork('weights/rock_bass.h5') for i in self.drumTracksList: predict = nnd.Predict(self.Tab.guitarTracks[i.baseTrack]) drum_data.addTrack(guitars[0], predict, i.name, tab) for i in self.bassTracksList: predict, first_string, key, mm = nnb.Predict( self.Tab.guitarTracks[i.baseTrack], self.path) bass_data.addTrack(guitars[0], predict, i.name, tab, first_string, key, mm) guitarpro.write(tab, fname[0])
def test_empty(output_folder): empty_a = guitarpro.Song() destpath = path.join(output_folder, 'Empty.gp5') guitarpro.write(empty_a, destpath, version=(5, 2, 0)) empty_b = guitarpro.parse(destpath) assert empty_a == empty_b
def test_empty(tmpdir): empty_a = guitarpro.Song() destpath = str(tmpdir.join('Empty.gp5')) guitarpro.write(empty_a, destpath, version=(5, 2, 0)) empty_b = guitarpro.parse(destpath) assert empty_a == empty_b
def parse(self): if self.input_file is None: self.input_file = self.find_clipboard() if self.output_file is None: self.output_file = self.input_file self.song = guitarpro.parse(self.input_file) if self.selected_track_numbers is None: if self.song.clipboard is not None: self.selected_track_numbers = list( range(self.song.clipboard.startTrack, self.song.clipboard.stopTrack + 1)) else: self.selected_track_numbers = ALL if self.selected_measure_numbers is None: if self.song.clipboard is not None: self.selected_measure_numbers = list( range(self.song.clipboard.startMeasure, self.song.clipboard.stopMeasure + 1)) else: self.selected_measure_numbers = ALL if self.selected_beat_numbers is None: if self.song.clipboard is not None and self.song.clipboard.subBarCopy: self.selected_beat_numbers = list( range(self.song.clipboard.startBeat, self.song.clipboard.stopBeat + 1)) else: self.selected_beat_numbers = ALL
def main_tg(args): """ """ import guitarpro with open(args.songfile, "r") as fin: res = guitarpro.parse(fin) pprint(res.__attr__) #for s in res: # pprint (s) t = res.tracks[0] pprint(t.__attr__) #for s in t: # pprint (s) ms = t.measures measure = ms[1] pprint(measure.__attr__) v = measure.voices[0] pprint(v.__attr__) beat = v.beats[0] pprint(beat.__attr__)
def test_module(): song = guitarpro.parse('./data/Deacon Blues.gp5') for track in song.tracks: for measure in track.measures: for voice in measure.voices: print(voice)
def parse_song(filename, tracks=None): try: song = gp.parse(filename) except struct.error: raise BadTabException("Cannot open tab file.") data = { "album": song.album, "artist": song.artist, "tempo": song.tempo, "title": song.title, "year": song.copyright if song.copyright else None, "extension": filename[-3:] } with open(filename, mode='rb') as f: data['hash'] = str(hashlib.sha256(f.read()).digest()[:16]) s = Song.query.filter_by(hash=data['hash']).first() if s: logger.debug(f"Song with the same hash already found.") return s s = Song(**data) logger.info(f"Parsing song {s}") for i, track in enumerate(song.tracks): if not tracks or i in tracks: t = parse_track(s, track, song.tempo) s.tracks.append(t) db.session.add(s) db.session.commit() return s
def readInput(noteList): # Load input file myFile = './input/input.gp5' # Parse file curl = guitarpro.parse(myFile) convertToList(noteList, curl)
def main(): # Load model model = keras.models.load_model('./models/modelDuration.hdf5') mydir = './validate/newSongs' files = listdir(mydir) noteList = [] # For each note e.g. C, E ,G # Converts each gp file into a list for gpfile in files: try: print('Found key for ', gpfile) curl = guitarpro.parse(mydir + '/'+ gpfile) songKey = curl.key.name if str(songKey) == "CMajor": os.remove(mydir + '/' +gpfile) print('Removed -', gpfile,'- Key not found') else: durationToList(noteList, curl) except: print('FILE ERROR WITH ', gpfile) pass # Load original durations with open('models/durations', 'rb') as filepath: originalNotes = pickle.load(filepath) i = 'New Notes' inputNotes = noteList x_input, y_output, durationKeys, output_size = processOriginal(originalNotes, inputNotes) actualList, predictionList = validate(x_input, y_output, model, durationKeys, output_size) display(actualList, predictionList, i)
def testEmpty(tmpdir): emptyA = gp.Song() destpath = str(tmpdir.join('Empty.gp5')) gp.write(emptyA, destpath, version=(5, 2, 0)) emptyB = gp.parse(destpath) assert emptyA == emptyB
def main(): # Finds guitar pro files located in tabs mydir = './tabs' files = listdir(mydir) n_epochs = 60 noteList = [] # For each note e.g. C, E ,G noteLengthList = [] # Length of each note e.g. 0.5 , 1.0 # Converts each gp file into a list for gpfile in files: try: # If C major then skip curl = guitarpro.parse(mydir + '/' + gpfile) songKey = curl.key.name if str(songKey) == "CMajor": os.remove(mydir + '/' + gpfile) print('Removed -', gpfile, '- Key not found') else: convertToList(noteList, curl) except: # Error handling print('FILE ERROR WITH ', gpfile) pass # Build Model model = rnntwo.build_model(noteList, n_epochs)
def readFile(song): # Read the file of test noteList = [] myFile = './validate/' + song curl = guitarpro.parse(myFile) convertToList(noteList, curl) return noteList
def remove_rests(input_filename, output_filename): """Read a gp file 'input_filename', write to 'output_filename'.""" song = guitarpro.parse(input_filename) song.tracks = [ remove_rests_from_track(track) if track.isPercussionTrack else track for track in song.tracks ] guitarpro.write(song, output_filename)
def readInput(): noteList = [] myFile = './input/input.gp5' curl = guitarpro.parse(myFile) convertToList(noteList, curl) # Get last note lastNote = noteList[-1] return noteList, lastNote
def readInput(): noteList = [] # File used as input myFile = './input/input.gp5' # Parse the GP5 file curl = guitarpro.parse(myFile) # Convert the file to noteList convertToList(noteList, curl) return noteList
def standardize(input_filename, output_filename): """Read a gp file 'input_filename', write to 'output_filename'.""" song = guitarpro.parse(input_filename) song.tracks = [ standardize_track(track) if track.isPercussionTrack else track for track in song.tracks ] guitarpro.write(song, output_filename)
def get_tab_info(file, temp_dest): try: song = gp.parse(temp_dest) except struct.error: abort(400) return jsonify({ i: track.name for i, track in enumerate(song.tracks) if len(track.strings) == 6 })
def readFile(): # Validation files testList = ['sameNotes.gp5', 'CScale.gp5', 'outOfScaleSameNotes.gp5', 'AB.gp5', 'ABC.gp5', 'ABCD.gp5', 'pentatonic.gp5', 'inputtedSong.gp4', 'newSong.gp5'] for myFile in testList: noteList = [] myFile = './validate/'+myFile # Parse the validation file curl = guitarpro.parse(myFile) convertToList(noteList, curl) processSong(noteList,myFile)
def extract_from_song(path, base_duration): """ Extract data from song :param path: filepath to the song (Windows format) :param base_duration: the smallest temporal step :return: data of track's notes with encoded START and END stored in ndarray """ song = guitarpro.parse(path) track = song.tracks[0] return extract_data(track, base_duration)
def main(source, dest, tracks, semitones, stringmaps): if tracks is None: tracks = ['*'] if stringmaps is None: stringmaps = [0x7f] * len(tracks) song = guitarpro.parse(source) for number, semitone, stringmap in zip(tracks, semitones, stringmaps): for number in unfold_tracknumber(number, song.tracks): track = song.tracks[number - 1] transpose(track, semitone, stringmap) if dest is None: dest = '%s-transposed%s' % os.path.splitext(source) guitarpro.write(song, dest)
def test_gp(): """ testna funkcija, za delovanje z branjem guitar pro file-ov nakaj tukaj ne dela popolnoma """ songs=[] for name in ("ACDC - Back In Black.gp5","Guns N Roses - Patience.gp5","Guns N Roses - Knockin on Heavens door.gp5","Deep Purple - Smoke On The Water.gp5"): gpfile=guitarpro.parse(name) flat=flatten(gpfile) songs+=filterGP(flat) print "opened",name hist=2 mat=makeMat2(songs,hist)# print mat res=generate(mat,hist,50) gp2music21(res).show("midi")
def parse_gp(file_path): # Parse gp and extract a list of notes. parsed_file = gp.parse(file_path) #ToDo: Extract notes. # First test on extracting notes. (FAIL) gp_reader = gp.GPFileBase(open(file_path, 'r')) while 1: try: print gp_reader.read('s', 1) except: print "End of file." break
def main(): # curs_set(0) filepath = path.join(song_file) song = guitarpro.parse(filepath) tab = Tab(midiSynth) for track in song.tracks: events = [] for measure in track.measures: for voice in measure.voices: for beat in voice.beats: # print "Beat start: " + str(beat.start) + ", duration: " + str(beat.duration.time) if beat.effect.chord is not None: print "Chord: " + str(beat.effect.chord.name) + str(beat.effect.chord.strings) + str(beat.effect.chord.fingerings) for note in beat.notes: # printTabNotes() # print str(note.type) + ", " + str(note.effect) + ", " + str(note.string) + ": " + str(note.value) + ", real: " + str(note.realValue) event = NoteOnEvent(track, note, beat) events.append(event) tab.appendTabTick(beat.start, note.string, note.value, note.realValue, beat.duration.time) event = NoteOffEvent(track, note, beat) events.append(event) # for event in sorted(events, key = eventStartTime) : # while(not(event.timeToPlay())): # time.sleep(0.001) # print event.name + " (" + str(event.realStartTime) + ") : " + str(event.note.string) + ", " + str(event.note.value) + " (" + str(event.note.realValue) + ")" tab.play() midiSynth.close()
def main(args): '''Command line interface ''' files = [args.OLDFILE, args.MYFILE, args.YOURFILE] # Parse files songs = [guitarpro.parse(f) for f in files if f is not None] differ = GPDiffer(files, songs) if len(files) == 3: # If output is specified, try to merge if args.output is not None: result = differ.merge() guitarpro.write(result, args.output, format=args.format) if not len(differ.conflicts): return 0 for line in differ.show(): print line if len(files) == 2 or not differ.conflicts: return 0 else: return 1
def main(): for test in tests.TESTS: filepath = path.join(tests.LOCATION, test) song = guitarpro.parse(filepath) tests.product(test, song)
import sys import copy import guitarpro import utils if __name__ == "__main__": if len(sys.argv) <= 3: print("This script will combine several tracks into one, " "after which an attempt to detect and collapse repeats is made. " "Pass the (0-based) index of the tracks to combine, " "in order of priority.") print("Usage: {} <infile> <outfile> <track index>+". format(sys.argv[0]), file=sys.stderr) if len(sys.argv) >= 2: song = guitarpro.parse(sys.argv[1]) for idx, track in enumerate(song.tracks): print("* track {}: {}".format(idx, track.name)) sys.exit(1) src = sys.argv[1] dst = sys.argv[2] print("Parsing", src) song = guitarpro.parse(src) print("Processing", song.title) indices = [] for s in sys.argv[3:]: indices.append(int(s))
__author__ = 'Tadej' import guitarpro print "start" a=guitarpro.parse(r"Guns N Roses - Patience.gp5") for track in a.tracks[0:1]: print track,track.name for measure in track.measures: #print "\t",measure for voice in measure.voices: #print "\t\t",voice for beat in voice.beats: d=beat.duration #print "\t\t",beat.start,beat.index,beat.octave,d.value for note in beat.notes: print "\t\t\t",note.value,note.velocity,note.string,note.durationPercent,note.realValue print note.beat #start cetrtinka=960 #1/duration je trajanje v celinkah #note.realvalue - 49 = C1 1=pol tona =MIDI zapis
def set_tab(self, source): self.string_step = 1 / 5. self.curl = guitarpro.parse(source) self.count_ver = 2 self.count_hor = 3 self.measure_count = len(self.curl.tracks[0].measures)
import sys import guitarpro if __name__ == "__main__": if len(sys.argv) != 3: print("This script will re-tune 3rd string from E4 to F4 on 7-string " "tracks as needed. Notes on empty 3rd string will be marked as " "fretted on 35th fret.") print("Usage:", sys.argv[0], "<infile> <outfile>", file=sys.stderr) sys.exit(1) src = sys.argv[1] dst = sys.argv[2] print("Parsing", src) song = guitarpro.parse(src) print("Processing", song.title) for track in song.tracks: if track.isPercussionTrack: continue if len(track.strings) != 7 or track.strings[2].value != 52: continue # re-tune 3rd string from E4 to F4 print("* Re-tuning string 3 of track", track.name) track.strings[2].value = track.strings[2].value + 1 for measure in track.measures: for voice in measure.voices: for beat in voice.beats: for note in beat.notes: