Python: Reading GuitarPro (.gp5) files












2















I'm new to writing questions here, so please feel free to point out how i can improve the quality of future questions!



Edit: More code included as was asked in the comments



I'm trying to read GuitarPro files into python. These files essentially contain the sheet music for songs, but contain more information than e.g. MIDI files.



I want to parse the notes and the duration of the notes into e.g. a list structure. Further, i hope other effects can be parsed from the GuitarPro files also, such as bends, slides, hammer-ons etc.



I have been trying to use the library PyGuitarPro, but get stuck:



import guitarpro
import os

# 'wet_sand.gp5' is the guitar pro file
parsed_song = guitarpro.parse('wet_sand.gp5')
song = guitarpro.gp5.GP5File(parsed_song,encoding='UTF-8')
song.readSong()


I get the following error from ReadSong() (documentation here):



Traceback (most recent call last):

File "<ipython-input-15-e1663229852d>", line 8, in <module>
song.readSong()

File "C:Python27libsite-packagesguitarprogp5.py", line 62, in readSong
song.version = self.readVersion()

File "C:Python27libsite-packagesguitarproiobase.py", line 114, in readVersion
self.version = self.readByteSizeString(30)

File "C:Python27libsite-packagesguitarproiobase.py", line 97, in readByteSizeString
return self.readString(size, self.readByte())

File "C:Python27libsite-packagesguitarproiobase.py", line 47, in readByte
return (self.read(*args, default=default) if count == 1 else

File "C:Python27libsite-packagesguitarproiobase.py", line 35, in read
data = self.data.read(count)

AttributeError: 'Song' object has no attribute 'read'









share|improve this question

























  • You can improve this question by posting the exact code that is causing the error, and the full text (copy and pate it in) of the error including the entire traceback. You should also provide enough data that someone could reproduce your problem as an MCVE

    – Craig
    Nov 23 '18 at 18:15











  • If you keep getting an error, the error message (and possibly trace back) will help debug it. It’s hard to help if you don’t post the message.

    – Dietrich Epp
    Nov 23 '18 at 18:16






  • 1





    I have updated the code now with the error, hope it's better now.

    – Malte Jensen
    Nov 24 '18 at 10:03
















2















I'm new to writing questions here, so please feel free to point out how i can improve the quality of future questions!



Edit: More code included as was asked in the comments



I'm trying to read GuitarPro files into python. These files essentially contain the sheet music for songs, but contain more information than e.g. MIDI files.



I want to parse the notes and the duration of the notes into e.g. a list structure. Further, i hope other effects can be parsed from the GuitarPro files also, such as bends, slides, hammer-ons etc.



I have been trying to use the library PyGuitarPro, but get stuck:



import guitarpro
import os

# 'wet_sand.gp5' is the guitar pro file
parsed_song = guitarpro.parse('wet_sand.gp5')
song = guitarpro.gp5.GP5File(parsed_song,encoding='UTF-8')
song.readSong()


I get the following error from ReadSong() (documentation here):



Traceback (most recent call last):

File "<ipython-input-15-e1663229852d>", line 8, in <module>
song.readSong()

File "C:Python27libsite-packagesguitarprogp5.py", line 62, in readSong
song.version = self.readVersion()

File "C:Python27libsite-packagesguitarproiobase.py", line 114, in readVersion
self.version = self.readByteSizeString(30)

File "C:Python27libsite-packagesguitarproiobase.py", line 97, in readByteSizeString
return self.readString(size, self.readByte())

File "C:Python27libsite-packagesguitarproiobase.py", line 47, in readByte
return (self.read(*args, default=default) if count == 1 else

File "C:Python27libsite-packagesguitarproiobase.py", line 35, in read
data = self.data.read(count)

AttributeError: 'Song' object has no attribute 'read'









share|improve this question

























  • You can improve this question by posting the exact code that is causing the error, and the full text (copy and pate it in) of the error including the entire traceback. You should also provide enough data that someone could reproduce your problem as an MCVE

    – Craig
    Nov 23 '18 at 18:15











  • If you keep getting an error, the error message (and possibly trace back) will help debug it. It’s hard to help if you don’t post the message.

    – Dietrich Epp
    Nov 23 '18 at 18:16






  • 1





    I have updated the code now with the error, hope it's better now.

    – Malte Jensen
    Nov 24 '18 at 10:03














2












2








2


1






I'm new to writing questions here, so please feel free to point out how i can improve the quality of future questions!



Edit: More code included as was asked in the comments



I'm trying to read GuitarPro files into python. These files essentially contain the sheet music for songs, but contain more information than e.g. MIDI files.



I want to parse the notes and the duration of the notes into e.g. a list structure. Further, i hope other effects can be parsed from the GuitarPro files also, such as bends, slides, hammer-ons etc.



I have been trying to use the library PyGuitarPro, but get stuck:



import guitarpro
import os

# 'wet_sand.gp5' is the guitar pro file
parsed_song = guitarpro.parse('wet_sand.gp5')
song = guitarpro.gp5.GP5File(parsed_song,encoding='UTF-8')
song.readSong()


I get the following error from ReadSong() (documentation here):



Traceback (most recent call last):

File "<ipython-input-15-e1663229852d>", line 8, in <module>
song.readSong()

File "C:Python27libsite-packagesguitarprogp5.py", line 62, in readSong
song.version = self.readVersion()

File "C:Python27libsite-packagesguitarproiobase.py", line 114, in readVersion
self.version = self.readByteSizeString(30)

File "C:Python27libsite-packagesguitarproiobase.py", line 97, in readByteSizeString
return self.readString(size, self.readByte())

File "C:Python27libsite-packagesguitarproiobase.py", line 47, in readByte
return (self.read(*args, default=default) if count == 1 else

File "C:Python27libsite-packagesguitarproiobase.py", line 35, in read
data = self.data.read(count)

AttributeError: 'Song' object has no attribute 'read'









share|improve this question
















I'm new to writing questions here, so please feel free to point out how i can improve the quality of future questions!



Edit: More code included as was asked in the comments



I'm trying to read GuitarPro files into python. These files essentially contain the sheet music for songs, but contain more information than e.g. MIDI files.



I want to parse the notes and the duration of the notes into e.g. a list structure. Further, i hope other effects can be parsed from the GuitarPro files also, such as bends, slides, hammer-ons etc.



I have been trying to use the library PyGuitarPro, but get stuck:



import guitarpro
import os

# 'wet_sand.gp5' is the guitar pro file
parsed_song = guitarpro.parse('wet_sand.gp5')
song = guitarpro.gp5.GP5File(parsed_song,encoding='UTF-8')
song.readSong()


I get the following error from ReadSong() (documentation here):



Traceback (most recent call last):

File "<ipython-input-15-e1663229852d>", line 8, in <module>
song.readSong()

File "C:Python27libsite-packagesguitarprogp5.py", line 62, in readSong
song.version = self.readVersion()

File "C:Python27libsite-packagesguitarproiobase.py", line 114, in readVersion
self.version = self.readByteSizeString(30)

File "C:Python27libsite-packagesguitarproiobase.py", line 97, in readByteSizeString
return self.readString(size, self.readByte())

File "C:Python27libsite-packagesguitarproiobase.py", line 47, in readByte
return (self.read(*args, default=default) if count == 1 else

File "C:Python27libsite-packagesguitarproiobase.py", line 35, in read
data = self.data.read(count)

AttributeError: 'Song' object has no attribute 'read'






python guitar






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 24 '18 at 10:02







Malte Jensen

















asked Nov 23 '18 at 18:10









Malte JensenMalte Jensen

183




183













  • You can improve this question by posting the exact code that is causing the error, and the full text (copy and pate it in) of the error including the entire traceback. You should also provide enough data that someone could reproduce your problem as an MCVE

    – Craig
    Nov 23 '18 at 18:15











  • If you keep getting an error, the error message (and possibly trace back) will help debug it. It’s hard to help if you don’t post the message.

    – Dietrich Epp
    Nov 23 '18 at 18:16






  • 1





    I have updated the code now with the error, hope it's better now.

    – Malte Jensen
    Nov 24 '18 at 10:03



















  • You can improve this question by posting the exact code that is causing the error, and the full text (copy and pate it in) of the error including the entire traceback. You should also provide enough data that someone could reproduce your problem as an MCVE

    – Craig
    Nov 23 '18 at 18:15











  • If you keep getting an error, the error message (and possibly trace back) will help debug it. It’s hard to help if you don’t post the message.

    – Dietrich Epp
    Nov 23 '18 at 18:16






  • 1





    I have updated the code now with the error, hope it's better now.

    – Malte Jensen
    Nov 24 '18 at 10:03

















You can improve this question by posting the exact code that is causing the error, and the full text (copy and pate it in) of the error including the entire traceback. You should also provide enough data that someone could reproduce your problem as an MCVE

– Craig
Nov 23 '18 at 18:15





You can improve this question by posting the exact code that is causing the error, and the full text (copy and pate it in) of the error including the entire traceback. You should also provide enough data that someone could reproduce your problem as an MCVE

– Craig
Nov 23 '18 at 18:15













If you keep getting an error, the error message (and possibly trace back) will help debug it. It’s hard to help if you don’t post the message.

– Dietrich Epp
Nov 23 '18 at 18:16





If you keep getting an error, the error message (and possibly trace back) will help debug it. It’s hard to help if you don’t post the message.

– Dietrich Epp
Nov 23 '18 at 18:16




1




1





I have updated the code now with the error, hope it's better now.

– Malte Jensen
Nov 24 '18 at 10:03





I have updated the code now with the error, hope it's better now.

– Malte Jensen
Nov 24 '18 at 10:03












1 Answer
1






active

oldest

votes


















0














Looking at the the examples provided, e.g. this one. I don't think you need this portion.




song = guitarpro.gp5.GP5File(parsed_song,encoding='UTF-8')




The following should be enough, as parse already calls readSong here.




song = guitarpro.parse('wet_sand.gp5')




Finally it looks like the file-format is automatically determined by parse here.



As an example you could do something like this.



import guitarpro
song = guitarpro.parse('test.gp5')

for track in song.tracks:
for measure in track.measures:
for voice in measure.voices:
for beat in voice.beats:
for note in beat.notes:
print(note.durationPercent)
print(note.effect)





share|improve this answer


























  • Maybe look at some of the examples? e.g. github.com/Perlence/PyGuitarPro/blob/develop/examples/…

    – eandersson
    Nov 24 '18 at 11:35











  • Thanks for the answer. However I cannot get the notes, durations, and effects out from this as far as i can see (I might be wrong here). The whole point is that I only want: the notes in order, the duration of each note and an optional effect (bends, slides, etc.). Hope this makes sense. If i parsed a midi-file, i cannot get effects such as bends and slides.

    – Malte Jensen
    Nov 24 '18 at 11:40











  • Do you have an example GP5 File I could check? but I would create a new question at Stackoverflow for this. Ideally each question should be focused on a very specific problem. The traceback should have been solved by the my answer, but your follow up question just seems like a new issue to me.

    – eandersson
    Nov 25 '18 at 0:54











  • @eanderson I will start a new thread then. The questions was meant from the beginning to be: "how do i extract only notes from a .gp5 file with the package i reference", but I see that this might not have been clear enough. Please bear in mind that I'm new and I'm trying to learn how to ask good questions. Thanks for the help so far!

    – Malte Jensen
    Nov 26 '18 at 11:14











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53451286%2fpython-reading-guitarpro-gp5-files%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Looking at the the examples provided, e.g. this one. I don't think you need this portion.




song = guitarpro.gp5.GP5File(parsed_song,encoding='UTF-8')




The following should be enough, as parse already calls readSong here.




song = guitarpro.parse('wet_sand.gp5')




Finally it looks like the file-format is automatically determined by parse here.



As an example you could do something like this.



import guitarpro
song = guitarpro.parse('test.gp5')

for track in song.tracks:
for measure in track.measures:
for voice in measure.voices:
for beat in voice.beats:
for note in beat.notes:
print(note.durationPercent)
print(note.effect)





share|improve this answer


























  • Maybe look at some of the examples? e.g. github.com/Perlence/PyGuitarPro/blob/develop/examples/…

    – eandersson
    Nov 24 '18 at 11:35











  • Thanks for the answer. However I cannot get the notes, durations, and effects out from this as far as i can see (I might be wrong here). The whole point is that I only want: the notes in order, the duration of each note and an optional effect (bends, slides, etc.). Hope this makes sense. If i parsed a midi-file, i cannot get effects such as bends and slides.

    – Malte Jensen
    Nov 24 '18 at 11:40











  • Do you have an example GP5 File I could check? but I would create a new question at Stackoverflow for this. Ideally each question should be focused on a very specific problem. The traceback should have been solved by the my answer, but your follow up question just seems like a new issue to me.

    – eandersson
    Nov 25 '18 at 0:54











  • @eanderson I will start a new thread then. The questions was meant from the beginning to be: "how do i extract only notes from a .gp5 file with the package i reference", but I see that this might not have been clear enough. Please bear in mind that I'm new and I'm trying to learn how to ask good questions. Thanks for the help so far!

    – Malte Jensen
    Nov 26 '18 at 11:14
















0














Looking at the the examples provided, e.g. this one. I don't think you need this portion.




song = guitarpro.gp5.GP5File(parsed_song,encoding='UTF-8')




The following should be enough, as parse already calls readSong here.




song = guitarpro.parse('wet_sand.gp5')




Finally it looks like the file-format is automatically determined by parse here.



As an example you could do something like this.



import guitarpro
song = guitarpro.parse('test.gp5')

for track in song.tracks:
for measure in track.measures:
for voice in measure.voices:
for beat in voice.beats:
for note in beat.notes:
print(note.durationPercent)
print(note.effect)





share|improve this answer


























  • Maybe look at some of the examples? e.g. github.com/Perlence/PyGuitarPro/blob/develop/examples/…

    – eandersson
    Nov 24 '18 at 11:35











  • Thanks for the answer. However I cannot get the notes, durations, and effects out from this as far as i can see (I might be wrong here). The whole point is that I only want: the notes in order, the duration of each note and an optional effect (bends, slides, etc.). Hope this makes sense. If i parsed a midi-file, i cannot get effects such as bends and slides.

    – Malte Jensen
    Nov 24 '18 at 11:40











  • Do you have an example GP5 File I could check? but I would create a new question at Stackoverflow for this. Ideally each question should be focused on a very specific problem. The traceback should have been solved by the my answer, but your follow up question just seems like a new issue to me.

    – eandersson
    Nov 25 '18 at 0:54











  • @eanderson I will start a new thread then. The questions was meant from the beginning to be: "how do i extract only notes from a .gp5 file with the package i reference", but I see that this might not have been clear enough. Please bear in mind that I'm new and I'm trying to learn how to ask good questions. Thanks for the help so far!

    – Malte Jensen
    Nov 26 '18 at 11:14














0












0








0







Looking at the the examples provided, e.g. this one. I don't think you need this portion.




song = guitarpro.gp5.GP5File(parsed_song,encoding='UTF-8')




The following should be enough, as parse already calls readSong here.




song = guitarpro.parse('wet_sand.gp5')




Finally it looks like the file-format is automatically determined by parse here.



As an example you could do something like this.



import guitarpro
song = guitarpro.parse('test.gp5')

for track in song.tracks:
for measure in track.measures:
for voice in measure.voices:
for beat in voice.beats:
for note in beat.notes:
print(note.durationPercent)
print(note.effect)





share|improve this answer















Looking at the the examples provided, e.g. this one. I don't think you need this portion.




song = guitarpro.gp5.GP5File(parsed_song,encoding='UTF-8')




The following should be enough, as parse already calls readSong here.




song = guitarpro.parse('wet_sand.gp5')




Finally it looks like the file-format is automatically determined by parse here.



As an example you could do something like this.



import guitarpro
song = guitarpro.parse('test.gp5')

for track in song.tracks:
for measure in track.measures:
for voice in measure.voices:
for beat in voice.beats:
for note in beat.notes:
print(note.durationPercent)
print(note.effect)






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 25 '18 at 2:06

























answered Nov 24 '18 at 10:11









eanderssoneandersson

18.8k67093




18.8k67093













  • Maybe look at some of the examples? e.g. github.com/Perlence/PyGuitarPro/blob/develop/examples/…

    – eandersson
    Nov 24 '18 at 11:35











  • Thanks for the answer. However I cannot get the notes, durations, and effects out from this as far as i can see (I might be wrong here). The whole point is that I only want: the notes in order, the duration of each note and an optional effect (bends, slides, etc.). Hope this makes sense. If i parsed a midi-file, i cannot get effects such as bends and slides.

    – Malte Jensen
    Nov 24 '18 at 11:40











  • Do you have an example GP5 File I could check? but I would create a new question at Stackoverflow for this. Ideally each question should be focused on a very specific problem. The traceback should have been solved by the my answer, but your follow up question just seems like a new issue to me.

    – eandersson
    Nov 25 '18 at 0:54











  • @eanderson I will start a new thread then. The questions was meant from the beginning to be: "how do i extract only notes from a .gp5 file with the package i reference", but I see that this might not have been clear enough. Please bear in mind that I'm new and I'm trying to learn how to ask good questions. Thanks for the help so far!

    – Malte Jensen
    Nov 26 '18 at 11:14



















  • Maybe look at some of the examples? e.g. github.com/Perlence/PyGuitarPro/blob/develop/examples/…

    – eandersson
    Nov 24 '18 at 11:35











  • Thanks for the answer. However I cannot get the notes, durations, and effects out from this as far as i can see (I might be wrong here). The whole point is that I only want: the notes in order, the duration of each note and an optional effect (bends, slides, etc.). Hope this makes sense. If i parsed a midi-file, i cannot get effects such as bends and slides.

    – Malte Jensen
    Nov 24 '18 at 11:40











  • Do you have an example GP5 File I could check? but I would create a new question at Stackoverflow for this. Ideally each question should be focused on a very specific problem. The traceback should have been solved by the my answer, but your follow up question just seems like a new issue to me.

    – eandersson
    Nov 25 '18 at 0:54











  • @eanderson I will start a new thread then. The questions was meant from the beginning to be: "how do i extract only notes from a .gp5 file with the package i reference", but I see that this might not have been clear enough. Please bear in mind that I'm new and I'm trying to learn how to ask good questions. Thanks for the help so far!

    – Malte Jensen
    Nov 26 '18 at 11:14

















Maybe look at some of the examples? e.g. github.com/Perlence/PyGuitarPro/blob/develop/examples/…

– eandersson
Nov 24 '18 at 11:35





Maybe look at some of the examples? e.g. github.com/Perlence/PyGuitarPro/blob/develop/examples/…

– eandersson
Nov 24 '18 at 11:35













Thanks for the answer. However I cannot get the notes, durations, and effects out from this as far as i can see (I might be wrong here). The whole point is that I only want: the notes in order, the duration of each note and an optional effect (bends, slides, etc.). Hope this makes sense. If i parsed a midi-file, i cannot get effects such as bends and slides.

– Malte Jensen
Nov 24 '18 at 11:40





Thanks for the answer. However I cannot get the notes, durations, and effects out from this as far as i can see (I might be wrong here). The whole point is that I only want: the notes in order, the duration of each note and an optional effect (bends, slides, etc.). Hope this makes sense. If i parsed a midi-file, i cannot get effects such as bends and slides.

– Malte Jensen
Nov 24 '18 at 11:40













Do you have an example GP5 File I could check? but I would create a new question at Stackoverflow for this. Ideally each question should be focused on a very specific problem. The traceback should have been solved by the my answer, but your follow up question just seems like a new issue to me.

– eandersson
Nov 25 '18 at 0:54





Do you have an example GP5 File I could check? but I would create a new question at Stackoverflow for this. Ideally each question should be focused on a very specific problem. The traceback should have been solved by the my answer, but your follow up question just seems like a new issue to me.

– eandersson
Nov 25 '18 at 0:54













@eanderson I will start a new thread then. The questions was meant from the beginning to be: "how do i extract only notes from a .gp5 file with the package i reference", but I see that this might not have been clear enough. Please bear in mind that I'm new and I'm trying to learn how to ask good questions. Thanks for the help so far!

– Malte Jensen
Nov 26 '18 at 11:14





@eanderson I will start a new thread then. The questions was meant from the beginning to be: "how do i extract only notes from a .gp5 file with the package i reference", but I see that this might not have been clear enough. Please bear in mind that I'm new and I'm trying to learn how to ask good questions. Thanks for the help so far!

– Malte Jensen
Nov 26 '18 at 11:14




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53451286%2fpython-reading-guitarpro-gp5-files%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Feedback on college project

Futebolista

Albești (Vaslui)