All I am after realy is to change this
reline = re.line.split('instr', '/d$')
into something that grabs any line with instr in it take all the
numbers and then grab any comment that may or may not be at the end of
the line starting with ; until the end of the line including white
spaces.. this is a corrected version from http://python-forum.org/py/viewtopic.php?t=1703
thanks in advance the hole routine is down below.. -
def extractCsdInstrument (input_File_Name, output_File_Name,
-
instr_number):
-
-
"takes an .csd input file and grabs instr_number instrument and
-
creates output_File_Name"
-
f = open (input_File_Name , 'r') #opens file passed
-
in to read
-
f2 = open (output_File_Name, 'w') #opens file passed
-
in to write
-
instr_yes = 'false' #set flag to false
-
-
for line in f: #for through all
-
the lines
-
if "instr" in line: #look for instr in
-
the file
-
if instr_yes == 'true': #check to see if
-
this ends the instr block
-
break #exit the block
-
-
reline = re.line.split('instr', '/d$') #error probily
-
split instr and /d (decimal number into parts) $ for end of line
-
number = int(reline[1]) #convert to a
-
number maybe not important
-
if number == instr_number: #check to see if
-
it is the instr passed to function
-
instr_yes = "true": #change flag to
-
true because this is the instr we want
-
if instr_yes = "true": #start of code to
-
copy to another file
-
f2.write(f.line) #write line to
-
output file
-
-
f.close #close input file
-
f2.close
-
-
13 1700 Er*********@msn.com wrote:
All I am after realy is to change this
reline = re.line.split('instr', '/d$')
If you think this is the only problem in your code, think again; almost
every other line has an error or an unpythonic idiom. Have you read any
tutorial or sample code before typing this python-like pseudocode ?
George
George Sakkis wrote:
Er*********@msn.com wrote:
All I am after realy is to change this
reline = re.line.split('instr', '/d$')
If you think this is the only problem in your code, think again; almost
every other line has an error or an unpythonic idiom. Have you read any
tutorial or sample code before typing this python-like pseudocode ?
George
better to offend a python than a rattlesnake (you have to see the cwa
rattlesnake shirts shirts compared to the python shirts) :)
As long as it will run but I feel like I am just converting it to
something that feels like c somewhat but I am learning the commands
(hopefully).. hard to get a good chapters with questions at the end
without cash... I am happy even if the code isn't pythonic if it runs
with this.
import csoundroutines
extractCsdInstrument("bay-at-night.csd", "test.orc", 1) http://www.dexrow.com
Hi Eric,
Don't let people offput you from learning python. It's a great
language, and is fun to use. But really, George does have a point -- if
you want to learn python, then the best way is to swim with the tide
rather than against it. But still, don't worry too much about being
pythonic and whatnot (many people would disagree with me here), just
write the code that _you_ (and your team) feel the most comfortable
with, and helps you be the most productive. But again, many of the
conventional pythonic ways to do things are such because people have
tested various ways and found those to be the best. So don't just blow
off convention, either. Find a happy medium between your coding style
and the conventions, and then you'll really become as productive as you
can be. That's my opinion. And only my opinion. But if it helps you
too, that's good. :)
Ps. Do have a look at the tutorials and other guides available, they
should help you out alot (e.g., the regexp tutorial [1]).
[1] http://www.amk.ca/python/howto/regex/
Regards,
Jordan Er*********@msn.com wrote:
All I am after realy is to change this
reline = re.line.split('instr', '/d$')
into something that grabs any line with instr in it take all the
numbers and then grab any comment that may or may not be at the end of
the line starting with ; until the end of the line including white
spaces.
-
def extractCsdInstrument (input_File_Name, output_File_Name,
-
instr_number):
-
"takes an .csd input file and grabs instr_number instrument and
-
creates output_File_Name"
-
f = open (input_File_Name , 'r')
-
f2 = open (output_File_Name, 'w')
-
instr_yes = 'false' # Python has built-in booleans
-
# Also, use sane naming: isInstr or hasInstr
-
for line in f:
-
if "instr" in line:
-
if instr_yes == 'true': # Use the bool -- `if hasInstr:`
-
break
-
reline = re.line.split('instr', '/d$') # ???
-
number = int(reline[1])
-
if number == instr_number: # Doesn't need to be 2 lines
-
instr_yes = "true": # the `:` is a syntax error
-
if instr_yes = "true":
-
f2.write(f.line) # odd way of doing it...
-
f.close()
-
f2.close()
-
Did you read the HOWTO on regular expressions yet? It's included with
the standard documentation, but here's a link: http://www.amk.ca/python/howto/regex/
Now, onto the issues:
1) The escape character is \, not /. Use "\d" to match a number.
2) I'm not sure I understand what you're trying to extract with your
regex. As it is, the expression will return a list containing one item,
a string identical to the line being matched up to, but not including,
the first number. The rest of the line will be discarded. Try Kiki, a
tool for testing regular expressions, before burying the expression in
your code.
3) Python has built-in booleans: True and False, no quotes. Use them so
that you don't get flamed on forums.
4) I don't claim to be a Python guru, but here's a massaged version of
the function you gave: -
-
def extractCsdInstrument (inputPath, outputPath, instrId):
-
""" Takes a .csd file, grabs info for instrument ID and writes to
-
file. """
-
src = open(inputPath, 'r')
-
dst = open(outputPath, 'w')
-
for line in src:
-
if "instr" in line:
-
info_comment = line.split(";", 1) # [info, comment]
-
# Extract integers
-
instrInfo = re.split(r"[^0-9]*", info_comment[0])
-
# Check the second number in the line
-
if instrInfo[1] == str(instrId):
-
dst.write(instrInfo.append(info_comment[1]))
-
src.close()
-
dst.close()
-
-
I didn't check if this actually works, since I don't know what a .csd
file looks like. There are of course other, better ways to do it, but
hopefully this leads you in the right direction.
5) Please, read the documentation that came with your Python
installation. Reading up on string methods etc. ahead of time will save
you much more time than trying to slug through it. Also consider using
a text editor with syntax highlighting; that will help catch most
obvious syntax errors during coding. Er*********@msn.com wrote:
All I am after realy is to change this
reline = re.line.split('instr', '/d$')
into something that grabs any line with instr in it take all the
numbers and then grab any comment that may or may not be at the end of
the line starting with ; until the end of the line including white
spaces.. this is a corrected version from
http://python-forum.org/py/viewtopic.php?t=1703
thanks in advance the hole routine is down below.. -
def extractCsdInstrument (input_File_Name, output_File_Name,
-
instr_number):
-
"takes an .csd input file and grabs instr_number instrument and
-
creates output_File_Name"
-
f = open (input_File_Name , 'r') #opens file passed
-
in to read
-
f2 = open (output_File_Name, 'w') #opens file passed
-
in to write
-
instr_yes = 'false' #set flag to false
-
for line in f: #for through all
-
the lines
-
if "instr" in line: #look for instr in
-
the file
-
if instr_yes == 'true': #check to see if
-
this ends the instr block
-
break #exit the block
-
reline = re.line.split('instr', '/d$') #error probily
-
split instr and /d (decimal number into parts) $ for end of line
-
number = int(reline[1]) #convert to a
-
number maybe not important
-
if number == instr_number: #check to see if
-
it is the instr passed to function
-
instr_yes = "true": #change flag to
-
true because this is the instr we want
-
if instr_yes = "true": #start of code to
-
copy to another file
-
f2.write(f.line) #write line to
-
output file
-
f.close #close input file
-
f2.close
-
Eric,
From your problem description and your code it is unclear what
exactly it is you want. The task appears to be rather simple, though,
and if you don't get much useful help I'd say it is because you don't
explain it very well.
I believe we've been through this before and your input data is
like this
data = '''
<CsoundSynthesizer>;
; test.csd - a Csound structured data file
<CsOptions>
-W -d -o tone.wav
</CsOptions>
<CsVersion ;optional section
Before 4.10 ;these two statements check for
After 4.08 ; Csound version 4.09
</CsVersion>
<CsInstruments>
; originally tone.orc
sr = 44100
kr = 4410
ksmps = 10
nchnls = 1
instr 1
a1 oscil p4, p5, 1 ; simple oscillator
out a1
endin
</CsInstruments>
<CsScore>
; originally tone.sco
f1 0 8192 10 1
i1 0 1 20000 1000 ;play one second of one kHz tone
e
</CsScore>
</CsoundSynthesizer>
Question 1: Is this your input?
if yes:
Question 1.1: What do you want to extract from it? In what format?
if no:
Question 1.1: What is your input?
Question 1.2: What do you want to extract from it? In what format?
Question 2: Do you need to generate output file names from the data?
(One file per instrument?)
if yes:
Question 2.1: What do you want to make your file name from?
(Instrument number?)
Regards
Frederic
Frederic Rentsch wrote:
Er*********@msn.com wrote:
All I am after realy is to change this
reline = re.line.split('instr', '/d$')
into something that grabs any line with instr in it take all the
numbers and then grab any comment that may or may not be at the end of
the line starting with ; until the end of the line including white
spaces.. this is a corrected version from http://python-forum.org/py/viewtopic.php?t=1703
thanks in advance the hole routine is down below.. -
def extractCsdInstrument (input_File_Name, output_File_Name,
-
instr_number):
-
-
"takes an .csd input file and grabs instr_number instrument and
-
creates output_File_Name"
-
f = open (input_File_Name , 'r') #opens file passed
-
in to read
-
f2 = open (output_File_Name, 'w') #opens file passed
-
in to write
-
instr_yes = 'false' #set flag to false
-
-
for line in f: #for through all
-
the lines
-
if "instr" in line: #look for instr in
-
the file
-
if instr_yes == 'true': #check to see if
-
this ends the instr block
-
break #exit the block
-
-
reline = re.line.split('instr', '/d$') #error probily
-
split instr and /d (decimal number into parts) $ for end of line
-
number = int(reline[1]) #convert to a
-
number maybe not important
-
if number == instr_number: #check to see if
-
it is the instr passed to function
-
instr_yes = "true": #change flag to
-
true because this is the instr we want
-
if instr_yes = "true": #start of code to
-
copy to another file
-
f2.write(f.line) #write line to
-
output file
-
-
f.close #close input file
-
f2.close
-
-
Eric,
From your problem description and your code it is unclear what
exactly it is you want. The task appears to be rather simple, though,
and if you don't get much useful help I'd say it is because you don't
explain it very well.
I believe we've been through this before and your input data is
like this
data = '''
<CsoundSynthesizer>;
; test.csd - a Csound structured data file
<CsOptions>
-W -d -o tone.wav
</CsOptions>
<CsVersion ;optional section
Before 4.10 ;these two statements check for
After 4.08 ; Csound version 4.09
</CsVersion>
<CsInstruments>
; originally tone.orc
sr = 44100
kr = 4410
ksmps = 10
nchnls = 1
instr 1
a1 oscil p4, p5, 1 ; simple oscillator
out a1
endin
</CsInstruments>
<CsScore>
; originally tone.sco
f1 0 8192 10 1
i1 0 1 20000 1000 ;play one second of one kHz tone
e
</CsScore>
</CsoundSynthesizer>
Question 1: Is this your input?
if yes:
Question 1.1: What do you want to extract from it? In what format?
if no:
Question 1.1: What is your input?
Question 1.2: What do you want to extract from it? In what format?
Question 2: Do you need to generate output file names from the data?
(One file per instrument?)
if yes:
Question 2.1: What do you want to make your file name from?
(Instrument number?)
Regards
Frederic
I want to pass the file name to the subroutine and return a comment
string if it is there maybe it should be simplier. I probily should
have the option of grabbing the comment in other related routines. I
am pretty ambitious with the main program. I did notice some code in
tcl that would be usefull to the app If I compile it.. I am probily
not ready for that though.. http://www.dexrow.com Er*********@msn.com wrote:
Frederic Rentsch wrote:
>Er*********@msn.com wrote:
>>All I am after realy is to change this
reline = re.line.split('instr', '/d$')
into something that grabs any line with instr in it take all the numbers and then grab any comment that may or may not be at the end of the line starting with ; until the end of the line including white spaces.. this is a corrected version from
http://python-forum.org/py/viewtopic.php?t=1703
thanks in advance the hole routine is down below.. - def extractCsdInstrument (input_File_Name, output_File_Name,
- instr_number):
- "takes an .csd input file and grabs instr_number instrument and
- creates output_File_Name"
- f = open (input_File_Name , 'r') #opens file passed
- in to read
- f2 = open (output_File_Name, 'w') #opens file passed
- in to write
- instr_yes = 'false' #set flag to false
- for line in f: #for through all
- the lines
- if "instr" in line: #look for instr in
- the file
- if instr_yes == 'true': #check to see if
- this ends the instr block
- break #exit the block
- reline = re.line.split('instr', '/d$') #error probily
- split instr and /d (decimal number into parts) $ for end of line
- number = int(reline[1]) #convert to a
- number maybe not important
- if number == instr_number: #check to see if
- it is the instr passed to function
- instr_yes = "true": #change flag to
- true because this is the instr we want
- if instr_yes = "true": #start of code to
- copy to another file
- f2.write(f.line) #write line to
- output file
- f.close #close input file
- f2.close
Eric, From your problem description and your code it is unclear what exactly it is you want. The task appears to be rather simple, though, and if you don't get much useful help I'd say it is because you don't explain it very well. I believe we've been through this before and your input data is like this
data = ''' <CsoundSynthesizer>; ; test.csd - a Csound structured data file
<CsOptions> -W -d -o tone.wav </CsOptions>
<CsVersion ;optional section Before 4.10 ;these two statements check for After 4.08 ; Csound version 4.09 </CsVersion>
<CsInstruments> ; originally tone.orc sr = 44100 kr = 4410 ksmps = 10 nchnls = 1 instr 1 a1 oscil p4, p5, 1 ; simple oscillator out a1 endin </CsInstruments>
<CsScore> ; originally tone.sco f1 0 8192 10 1 i1 0 1 20000 1000 ;play one second of one kHz tone e </CsScore>
</CsoundSynthesizer>
Question 1: Is this your input? if yes: Question 1.1: What do you want to extract from it? In what format? if no: Question 1.1: What is your input? Question 1.2: What do you want to extract from it? In what format? Question 2: Do you need to generate output file names from the data? (One file per instrument?) if yes: Question 2.1: What do you want to make your file name from? (Instrument number?)
Regards
Frederic
I want to pass the file name to the subroutine and return a comment
string if it is there maybe it should be simplier. I probily should
have the option of grabbing the comment in other related routines. I
am pretty ambitious with the main program. I did notice some code in
tcl that would be usefull to the app If I compile it.. I am probily
not ready for that though..
http://www.dexrow.com
Eric,
I'm beginning to enjoy this. I'm sure we'll sort this out in no
time if we proceed methodically. Imagine you are a teacher and I am your
student. This is a quiz. I have to take it and you need to explain to me
the problem you want me to solve. If you don't explain it clearly, I
will not know what I have to do and cannot do the quiz. If you answer my
questions above, your description of the problem will be clear and I can
take the quiz. Okay?
Frederic
Frederic Rentsch wrote:
Er*********@msn.com wrote:
Frederic Rentsch wrote: Er*********@msn.com wrote:
All I am after realy is to change this
reline = re.line.split('instr', '/d$')
into something that grabs any line with instr in it take all the numbers and then grab any comment that may or may not be at the end of the line starting with ; until the end of the line including white spaces.. this is a corrected version from
http://python-forum.org/py/viewtopic.php?t=1703
thanks in advance the hole routine is down below.. - def extractCsdInstrument (input_File_Name, output_File_Name,
- instr_number):
- "takes an .csd input file and grabs instr_number instrument and
- creates output_File_Name"
- f = open (input_File_Name , 'r') #opens file passed
- in to read
- f2 = open (output_File_Name, 'w') #opens file passed
- in to write
- instr_yes = 'false' #set flag to false
- for line in f: #for through all
- the lines
- if "instr" in line: #look for instr in
- the file
- if instr_yes == 'true': #check to see if
- this ends the instr block
- break #exit the block
- reline = re.line.split('instr', '/d$') #error probily
- split instr and /d (decimal number into parts) $ for end of line
- number = int(reline[1]) #convert to a
- number maybe not important
- if number == instr_number: #check to see if
- it is the instr passed to function
- instr_yes = "true": #change flag to
- true because this is the instr we want
- if instr_yes = "true": #start of code to
- copy to another file
- f2.write(f.line) #write line to
- output file
- f.close #close input file
- f2.close
Eric,
From your problem description and your code it is unclear what
exactly it is you want. The task appears to be rather simple, though,
and if you don't get much useful help I'd say it is because you don't
explain it very well.
I believe we've been through this before and your input data is
like this
data = '''
<CsoundSynthesizer>;
; test.csd - a Csound structured data file
<CsOptions>
-W -d -o tone.wav
</CsOptions>
<CsVersion ;optional section
Before 4.10 ;these two statements check for
After 4.08 ; Csound version 4.09
</CsVersion>
<CsInstruments>
; originally tone.orc
sr = 44100
kr = 4410
ksmps = 10
nchnls = 1
instr 1
a1 oscil p4, p5, 1 ; simple oscillator
out a1
endin
</CsInstruments>
<CsScore>
; originally tone.sco
f1 0 8192 10 1
i1 0 1 20000 1000 ;play one second of one kHz tone
e
</CsScore>
</CsoundSynthesizer>
Question 1: Is this your input?
if yes:
Question 1.1: What do you want to extract from it? In what format?
if no:
Question 1.1: What is your input?
Question 1.2: What do you want to extract from it? In what format?
Question 2: Do you need to generate output file names from the data?
(One file per instrument?)
if yes:
Question 2.1: What do you want to make your file name from?
(Instrument number?)
Regards
Frederic
I want to pass the file name to the subroutine and return a comment
string if it is there maybe it should be simplier. I probily should
have the option of grabbing the comment in other related routines. I
am pretty ambitious with the main program. I did notice some code in
tcl that would be usefull to the app If I compile it.. I am probily
not ready for that though.. http://www.dexrow.com
Eric,
I'm beginning to enjoy this. I'm sure we'll sort this out in no
time if we proceed methodically. Imagine you are a teacher and I am your
student. This is a quiz. I have to take it and you need to explain to me
the problem you want me to solve. If you don't explain it clearly, I
will not know what I have to do and cannot do the quiz. If you answer my
questions above, your description of the problem will be clear and I can
take the quiz. Okay?
Frederic
instr 1
a1 oscil p4, p5, 1 ; simple oscillator ; comment is
sometimes here
out a1
endin
I need to know the file I wan't to grab this from I need to grab this
out of the larger file and put it into it's own file, I need to know
what instr the user wants. I need to know what file to put it into and
it would be usefull to have the comment line returned (if any).
I did just get python essential reference 3rd edition.. If there is a
better reference on just the subject I am after I would be glad to grab
it when I get cash again. Er*********@msn.com wrote:
Frederic Rentsch wrote:
>Er*********@msn.com wrote:
>>Frederic Rentsch wrote: Er*********@msn.com wrote:
All I am after realy is to change this > reline = re.line.split('instr', '/d$') > into something that grabs any line with instr in it take all the numbers and then grab any comment that may or may not be at the end of the line starting with ; until the end of the line including white spaces.. this is a corrected version from > http://python-forum.org/py/viewtopic.php?t=1703 > thanks in advance the hole routine is down below.. > > > > > > - def extractCsdInstrument (input_File_Name, output_File_Name,
- instr_number):
- >
- "takes an .csd input file and grabs instr_number instrument and
- creates output_File_Name"
- f = open (input_File_Name , 'r') #opens file passed
- in to read
- f2 = open (output_File_Name, 'w') #opens file passed
- in to write
- instr_yes = 'false' #set flag to false
- >
- for line in f: #for through all
- the lines
- if "instr" in line: #look for instr in
- the file
- if instr_yes == 'true': #check to see if
- this ends the instr block
- break #exit the block
- >
- reline = re.line.split('instr', '/d$') #error probily
- split instr and /d (decimal number into parts) $ for end of line
- number = int(reline[1]) #convert to a
- number maybe not important
- if number == instr_number: #check to see if
- it is the instr passed to function
- instr_yes = "true": #change flag to
- true because this is the instr we want
- if instr_yes = "true": #start of code to
- copy to another file
- f2.write(f.line) #write line to
- output file
- >
- f.close #close input file
- f2.close
- >
> > > > Eric, From your problem description and your code it is unclear what exactly it is you want. The task appears to be rather simple, though, and if you don't get much useful help I'd say it is because you don't explain it very well. I believe we've been through this before and your input data is like this
data = ''' <CsoundSynthesizer>; ; test.csd - a Csound structured data file
<CsOptions> -W -d -o tone.wav </CsOptions>
<CsVersion ;optional section Before 4.10 ;these two statements check for After 4.08 ; Csound version 4.09 </CsVersion>
<CsInstruments> ; originally tone.orc sr = 44100 kr = 4410 ksmps = 10 nchnls = 1 instr 1 a1 oscil p4, p5, 1 ; simple oscillator out a1 endin </CsInstruments>
<CsScore> ; originally tone.sco f1 0 8192 10 1 i1 0 1 20000 1000 ;play one second of one kHz tone e </CsScore>
</CsoundSynthesizer>
Question 1: Is this your input? if yes: Question 1.1: What do you want to extract from it? In what format? if no: Question 1.1: What is your input? Question 1.2: What do you want to extract from it? In what format? Question 2: Do you need to generate output file names from the data? (One file per instrument?) if yes: Question 2.1: What do you want to make your file name from? (Instrument number?)
Regards
Frederic
I want to pass the file name to the subroutine and return a comment string if it is there maybe it should be simplier. I probily should have the option of grabbing the comment in other related routines. I am pretty ambitious with the main program. I did notice some code in tcl that would be usefull to the app If I compile it.. I am probily not ready for that though..
http://www.dexrow.com
Eric, I'm beginning to enjoy this. I'm sure we'll sort this out in no time if we proceed methodically. Imagine you are a teacher and I am your student. This is a quiz. I have to take it and you need to explain to me the problem you want me to solve. If you don't explain it clearly, I will not know what I have to do and cannot do the quiz. If you answer my questions above, your description of the problem will be clear and I can take the quiz. Okay?
Frederic
instr 1
a1 oscil p4, p5, 1 ; simple oscillator ; comment is
sometimes here
out a1
endin
I need to know the file I wan't to grab this from I need to grab this
out of the larger file and put it into it's own file, I need to know
what instr the user wants. I need to know what file to put it into and
it would be usefull to have the comment line returned (if any).
I did just get python essential reference 3rd edition.. If there is a
better reference on just the subject I am after I would be glad to grab
it when I get cash again.
Eric,
Tell us the story. Are you a student? A musician? What are you doing
with these files? Where do you get them from? What for?
Frederic
These are csound files. Csound recently added python as a scripting
language and is allowing also allowing csound calls from outside of
csound. The nice thing about csound is that instead of worrying about
virus and large files it is an interpiter and all the files look
somewhat like html. 4,000 virus free instruments for $20 is available
at http://www.csounds.com and the csound programming book is also
available. The downside is that csound is can be realy ugly looking
(that is what I am trying to change) and it lets you write ugly looking
song code that is almost unreadable at times (would look nice in a
grid) http://www.msn.com
...
Frederic Rentsch wrote:
Er*********@msn.com wrote:
Frederic Rentsch wrote: Er*********@msn.com wrote:
Frederic Rentsch wrote: Er*********@msn.com wrote:
All I am after realy is to change this
reline = re.line.split('instr', '/d$')
into something that grabs any line with instr in it take all the numbers and then grab any comment that may or may not be at the end of the line starting with ; until the end of the line including white spaces.. this is a corrected version from
http://python-forum.org/py/viewtopic.php?t=1703
thanks in advance the hole routine is down below.. - def extractCsdInstrument (input_File_Name, output_File_Name,
- instr_number):
- "takes an .csd input file and grabs instr_number instrument and
- creates output_File_Name"
- f = open (input_File_Name , 'r') #opens file passed
- in to read
- f2 = open (output_File_Name, 'w') #opens file passed
- in to write
- instr_yes = 'false' #set flag to false
- for line in f: #for through all
- the lines
- if "instr" in line: #look for instr in
- the file
- if instr_yes == 'true': #check to see if
- this ends the instr block
- break #exit the block
- reline = re.line.split('instr', '/d$') #error probily
- split instr and /d (decimal number into parts) $ for end of line
- number = int(reline[1]) #convert to a
- number maybe not important
- if number == instr_number: #check to see if
- it is the instr passed to function
- instr_yes = "true": #change flag to
- true because this is the instr we want
- if instr_yes = "true": #start of code to
- copy to another file
- f2.write(f.line) #write line to
- output file
- f.close #close input file
- f2.close
Eric, From your problem description and your code it is unclear what exactly it is you want. The task appears to be rather simple, though, and if you don't get much useful help I'd say it is because you don't explain it very well. I believe we've been through this before and your input data is like this
data = ''' <CsoundSynthesizer>; ; test.csd - a Csound structured data file
<CsOptions> -W -d -o tone.wav </CsOptions>
<CsVersion ;optional section Before 4.10 ;these two statements check for After 4.08 ; Csound version 4.09 </CsVersion>
<CsInstruments> ; originally tone.orc sr = 44100 kr = 4410 ksmps = 10 nchnls = 1 instr 1 a1 oscil p4, p5, 1 ; simple oscillator out a1 endin </CsInstruments>
<CsScore> ; originally tone.sco f1 0 8192 10 1 i1 0 1 20000 1000 ;play one second of one kHz tone e </CsScore>
</CsoundSynthesizer>
Question 1: Is this your input? if yes: Question 1.1: What do you want to extract from it? In what format? if no: Question 1.1: What is your input? Question 1.2: What do you want to extract from it? In what format? Question 2: Do you need to generate output file names from the data? (One file per instrument?) if yes: Question 2.1: What do you want to make your file name from? (Instrument number?)
Regards
Frederic
I want to pass the file name to the subroutine and return a comment string if it is there maybe it should be simplier. I probily should have the option of grabbing the comment in other related routines. I am pretty ambitious with the main program. I did notice some code in tcl that would be usefull to the app If I compile it.. I am probily not ready for that though..
http://www.dexrow.com
Eric,
I'm beginning to enjoy this. I'm sure we'll sort this out in no
time if we proceed methodically. Imagine you are a teacher and I am your
student. This is a quiz. I have to take it and you need to explain to me
the problem you want me to solve. If you don't explain it clearly, I
will not know what I have to do and cannot do the quiz. If you answer my
questions above, your description of the problem will be clear and I can
take the quiz. Okay?
Frederic
instr 1
a1 oscil p4, p5, 1 ; simple oscillator ; comment is
sometimes here
out a1
endin
I need to know the file I wan't to grab this from I need to grab this
out of the larger file and put it into it's own file, I need to know
what instr the user wants. I need to know what file to put it into and
it would be usefull to have the comment line returned (if any).
I did just get python essential reference 3rd edition.. If there is a
better reference on just the subject I am after I would be glad to grab
it when I get cash again.
Eric,
Tell us the story. Are you a student? A musician? What are you doing
with these files? Where do you get them from? What for?
Frederic
Er*********@msn.com wrote:
These are csound files. Csound recently added python as a scripting
language and is allowing also allowing csound calls from outside of
csound. The nice thing about csound is that instead of worrying about
virus and large files it is an interpiter and all the files look
somewhat like html. 4,000 virus free instruments for $20 is available
at http://www.csounds.com and the csound programming book is also
available. The downside is that csound is can be realy ugly looking
(that is what I am trying to change) and it lets you write ugly looking
song code that is almost unreadable at times (would look nice in a
grid)
http://www.msn.com
..
Frederic Rentsch wrote:
>Er*********@msn.com wrote:
>>Frederic Rentsch wrote: Er*********@msn.com wrote:
Frederic Rentsch wrote: > > > >Er*********@msn.com wrote: >> >> >> >>All I am after realy is to change this >>> >> reline = re.line.split('instr', '/d$') >>> >>into something that grabs any line with instr in it take all the >>numbers and then grab any comment that may or may not be at the end of >>the line starting with ; until the end of the line including white >>spaces.. this is a corrected version from >>> >>http://python-forum.org/py/viewtopic.php?t=1703 >>> >>thanks in advance the hole routine is down below.. >>> >>> >>> >>> >>> >>> >> - >>def extractCsdInstrument (input_File_Name, output_File_Name,
- >>instr_number):
- >>>
- >> "takes an .csd input file and grabs instr_number instrument and
- >>creates output_File_Name"
- >> f = open (input_File_Name , 'r') #opens file passed
- >>in to read
- >> f2 = open (output_File_Name, 'w') #opens file passed
- >>in to write
- >> instr_yes = 'false' #set flag to false
- >>>
- >> for line in f: #for through all
- >>the lines
- >> if "instr" in line: #look for instr in
- >>the file
- >> if instr_yes == 'true': #check to see if
- >>this ends the instr block
- >> break #exit the block
- >>>
- >> reline = re.line.split('instr', '/d$') #error probily
- >>split instr and /d (decimal number into parts) $ for end of line
- >> number = int(reline[1]) #convert to a
- >>number maybe not important
- >> if number == instr_number: #check to see if
- >>it is the instr passed to function
- >> instr_yes = "true": #change flag to
- >>true because this is the instr we want
- >> if instr_yes = "true": #start of code to
- >>copy to another file
- >> f2.write(f.line) #write line to
- >>output file
- >>>
- >> f.close #close input file
- >> f2.close
- >>>
- >>
>>> >>> >>> >>> >>> >Eric, > From your problem description and your code it is unclear what >exactly it is you want. The task appears to be rather simple, though, >and if you don't get much useful help I'd say it is because you don't >explain it very well. > I believe we've been through this before and your input data is >like this >> > data = ''' > <CsoundSynthesizer>; > ; test.csd - a Csound structured data file >> > <CsOptions> > -W -d -o tone.wav > </CsOptions> >> > <CsVersion ;optional section > Before 4.10 ;these two statements check for > After 4.08 ; Csound version 4.09 > </CsVersion> >> > <CsInstruments> > ; originally tone.orc > sr = 44100 > kr = 4410 > ksmps = 10 > nchnls = 1 > instr 1 > a1 oscil p4, p5, 1 ; simple oscillator > out a1 > endin > </CsInstruments> >> > <CsScore> > ; originally tone.sco > f1 0 8192 10 1 > i1 0 1 20000 1000 ;play one second of one kHz tone > e > </CsScore> >> > </CsoundSynthesizer> >> >Question 1: Is this your input? >if yes: > Question 1.1: What do you want to extract from it? In what format? >if no: > Question 1.1: What is your input? > Question 1.2: What do you want to extract from it? In what format? >Question 2: Do you need to generate output file names from the data? >(One file per instrument?) >if yes: > Question 2.1: What do you want to make your file name from? >(Instrument number?) >> >> >Regards >> >Frederic >> >> >> I want to pass the file name to the subroutine and return a comment string if it is there maybe it should be simplier. I probily should have the option of grabbing the comment in other related routines. I am pretty ambitious with the main program. I did notice some code in tcl that would be usefull to the app If I compile it.. I am probily not ready for that though.. > http://www.dexrow.com > > > > Eric, I'm beginning to enjoy this. I'm sure we'll sort this out in no time if we proceed methodically. Imagine you are a teacher and I am your student. This is a quiz. I have to take it and you need to explain to me the problem you want me to solve. If you don't explain it clearly, I will not know what I have to do and cannot do the quiz. If you answer my questions above, your description of the problem will be clear and I can take the quiz. Okay?
Frederic
instr 1 a1 oscil p4, p5, 1 ; simple oscillator ; comment is sometimes here out a1 endin
I need to know the file I wan't to grab this from I need to grab this out of the larger file and put it into it's own file, I need to know what instr the user wants. I need to know what file to put it into and it would be usefull to have the comment line returned (if any).
I did just get python essential reference 3rd edition.. If there is a better reference on just the subject I am after I would be glad to grab it when I get cash again.
Eric,
Tell us the story. Are you a student? A musician? What are you doing with these files? Where do you get them from? What for?
Frederic
Eric,
I found an excellent CSound doc at:
ems.music.utexas.edu/program/mus329j/CSPrimer.pdf. I am myself
interested in music and will definitely look into this more closely.
For the time being I get the impression that you are dealing with
CSound instrument definition files which you can buy cheaply in great
quantity but unfortunately are illegibly formatted. If this is so, what
you would need is a formatter. I found references to CSound editors
(e.g. http://flavio.tordini.org/csound-editor/). Those should be capable
of formatting.
Writing your own formatter shouldn't be all that hard. Here's a
quick try:
def csound_formatter (in_file, out_file_file = sys.stdout):
INDENT = 10
CODE_LENGTH = 50
for l in in_file:
line = l.strip ()
if line == '':
out_file.write ('\n')
else:
if line [0] == ';': # Comment line
out_file.write ('%s\n' % line)
else:
code = comment = ''
if line [-1] == ':': # Label
out_file.write ('%s\n' % line)
else:
if ';' in line:
code, comment = line.split (';')
out_file.write ('%*s%-*s;%s\n' % (INDENT, '',
CODE_LENGTH, code, comment))
else:
out_file.write ('%*s%s\n' % (INDENT, '', line))
And here is a section of a csound file with white space squeezed out as
would make the file smaller:
>>csound = StringIO.StringIO ('''; Basic FM Instrument with Variable
Vibrato
; p4=amp p5=pch(fund) p6=vibdel p7=vibrate p8=vibwth
; p9=rise p10=decay p11=max index p12=car fac p13=modfac
; p14=index rise p15=index decay p16=left channel factor p17=original p3
instr 9,10,11,12
;--------------------------------------------------------------------------------
;initialization block:
kpitch init cpspch (p5)
itempo = p3/p17 ;ratio seconds/beats
idelay = p6 * itempo ;convert beats to secs
irise = p9 * itempo
idecay = p10 * itempo
indxris = (p14 == 0 ? irise : p14 * itempo)
indxdec = (p15 == 0 ? idecay : p15 * itempo)
if (p16 != 0) igoto panning ;if a panfac, use it, else
ilfac = .707 ;default is mono (sqrt(.5))
irfac = .707
igoto perform
panning:
ilfac = sqrt(p16)
irfac = sqrt(1-p16)
;--------------------------------------------------------------------------------
;performance block:
perform:
if (p7 == 0 || p8 == 0) goto continue
kontrol oscil1 idelay,1,.5,2 ;vib control
kvib oscili p8*kontrol,p7*kontrol,1 ;vibrato unit
kpitch = cpsoct(octpch(p5)+kvib) ;varying fund pitch in hz
continue:
kamp linen p4,irise,p3,idecay
kindex linen p11,indxris,p3,indxdec
asig foscili kamp,kpitch,p12,p13,kindex,1 ;p12,p13=carfac,mod fac
outs asig*ilfac,asig*irfac
endin
''')
Now we run this through the function defined above:
>>csound_formatter (s)
; Basic FM Instrument with Variable Vibrato
; p4=amp p5=pch(fund) p6=vibdel p7=vibrate p8=vibwth
; p9=rise p10=decay p11=max index p12=car fac p13=modfac
; p14=index rise p15=index decay p16=left channel factor p17=original p3
instr 9,10,11,12
;--------------------------------------------------------------------------------
;initialization block:
kpitch init cpspch (p5)
itempo = p3/p17 ;ratio
seconds/beats
idelay = p6 * itempo ;convert
beats to secs
irise = p9 * itempo
idecay = p10 * itempo
indxris = (p14 == 0 ? irise : p14 * itempo)
indxdec = (p15 == 0 ? idecay : p15 * itempo)
if (p16 != 0) igoto panning ;if a
panfac, use it, else
ilfac = .707 ;default is
mono (sqrt(.5))
irfac = .707
igoto perform
panning:
ilfac = sqrt(p16)
irfac = sqrt(1-p16)
;--------------------------------------------------------------------------------
;performance block:
perform:
if (p7 == 0 || p8 == 0) goto continue
kontrol oscil1 idelay,1,.5,2 ;vib control
kvib oscili p8*kontrol,p7*kontrol,1 ;vibrato unit
kpitch = cpsoct(octpch(p5)+kvib) ;varying
fund pitch in hz
continue:
kamp linen p4,irise,p3,idecay
kindex linen p11,indxris,p3,indxdec
asig foscili kamp,kpitch,p12,p13,kindex,1
;p12,p13=carfac,mod fac
outs asig*ilfac,asig*irfac
endin
It works on a couple of presumptions (e.g. no code following labels). So
it may not function perfectly but shouldn't be hard to tweak.
Hope this helps
Frederic
Frederic Rentsch wrote:
Er*********@msn.com wrote:
These are csound files. Csound recently added python as a scripting
language and is allowing also allowing csound calls from outside of
csound. The nice thing about csound is that instead of worrying about
virus and large files it is an interpiter and all the files look
somewhat like html. 4,000 virus free instruments for $20 is available
at http://www.csounds.com and the csound programming book is also
available. The downside is that csound is can be realy ugly looking
(that is what I am trying to change) and it lets you write ugly looking
song code that is almost unreadable at times (would look nice in a
grid) http://www.msn.com
..
Frederic Rentsch wrote: Er*********@msn.com wrote:
Frederic Rentsch wrote: Er*********@msn.com wrote:
Frederic Rentsch wrote: Er*********@msn.com wrote: > > > >All I am after realy is to change this >> > reline = re.line.split('instr', '/d$') >> >into something that grabs any line with instr in it take all the >numbers and then grab any comment that may or may not be at the end of >the line starting with ; until the end of the line including white >spaces.. this is a corrected version from >> >http://python-forum.org/py/viewtopic.php?t=1703 >> >thanks in advance the hole routine is down below.. >> >> >> >> >> >> > - >def extractCsdInstrument (input_File_Name, output_File_Name,
- >instr_number):
- >>
- > "takes an .csd input file and grabs instr_number instrument and
- >creates output_File_Name"
- > f = open (input_File_Name , 'r') #opens file passed
- >in to read
- > f2 = open (output_File_Name, 'w') #opens file passed
- >in to write
- > instr_yes = 'false' #set flag to false
- >>
- > for line in f: #for through all
- >the lines
- > if "instr" in line: #look for instr in
- >the file
- > if instr_yes == 'true': #check to see if
- >this ends the instr block
- > break #exit the block
- >>
- > reline = re.line.split('instr', '/d$') #error probily
- >split instr and /d (decimal number into parts) $ for end of line
- > number = int(reline[1]) #convert to a
- >number maybe not important
- > if number == instr_number: #check to see if
- >it is the instr passed to function
- > instr_yes = "true": #change flag to
- >true because this is the instr we want
- > if instr_yes = "true": #start of code to
- >copy to another file
- > f2.write(f.line) #write line to
- >output file
- >>
- > f.close #close input file
- > f2.close
- >>
- >
>> >> >> >> >> Eric, From your problem description and your code it is unclear what exactly it is you want. The task appears to be rather simple, though, and if you don't get much useful help I'd say it is because you don't explain it very well. I believe we've been through this before and your input data is like this > data = ''' <CsoundSynthesizer>; ; test.csd - a Csound structured data file > <CsOptions> -W -d -o tone.wav </CsOptions> > <CsVersion ;optional section Before 4.10 ;these two statements check for After 4.08 ; Csound version 4.09 </CsVersion> > <CsInstruments> ; originally tone.orc sr = 44100 kr = 4410 ksmps = 10 nchnls = 1 instr 1 a1 oscil p4, p5, 1 ; simple oscillator out a1 endin </CsInstruments> > <CsScore> ; originally tone.sco f1 0 8192 10 1 i1 0 1 20000 1000 ;play one second of one kHz tone e </CsScore> > </CsoundSynthesizer> > Question 1: Is this your input? if yes: Question 1.1: What do you want to extract from it? In what format? if no: Question 1.1: What is your input? Question 1.2: What do you want to extract from it? In what format? Question 2: Do you need to generate output file names from the data? (One file per instrument?) if yes: Question 2.1: What do you want to make your file name from? (Instrument number?) > > Regards > Frederic > > > I want to pass the file name to the subroutine and return a comment string if it is there maybe it should be simplier. I probily should have the option of grabbing the comment in other related routines. I am pretty ambitious with the main program. I did notice some code in tcl that would be usefull to the app If I compile it.. I am probily not ready for that though..
http://www.dexrow.com
Eric, I'm beginning to enjoy this. I'm sure we'll sort this out in no time if we proceed methodically. Imagine you are a teacher and I am your student. This is a quiz. I have to take it and you need to explain to me the problem you want me to solve. If you don't explain it clearly, I will not know what I have to do and cannot do the quiz. If you answer my questions above, your description of the problem will be clear and I can take the quiz. Okay?
Frederic
instr 1 a1 oscil p4, p5, 1 ; simple oscillator ; comment is sometimes here out a1 endin
I need to know the file I wan't to grab this from I need to grab this out of the larger file and put it into it's own file, I need to know what instr the user wants. I need to know what file to put it into and it would be usefull to have the comment line returned (if any).
I did just get python essential reference 3rd edition.. If there is a better reference on just the subject I am after I would be glad to grab it when I get cash again.
Eric,
Tell us the story. Are you a student? A musician? What are you doing
with these files? Where do you get them from? What for?
Frederic
Eric,
I found an excellent CSound doc at:
ems.music.utexas.edu/program/mus329j/CSPrimer.pdf. I am myself
interested in music and will definitely look into this more closely.
For the time being I get the impression that you are dealing with
CSound instrument definition files which you can buy cheaply in great
quantity but unfortunately are illegibly formatted. If this is so, what
you would need is a formatter. I found references to CSound editors
(e.g. http://flavio.tordini.org/csound-editor/). Those should be capable
of formatting.
Writing your own formatter shouldn't be all that hard. Here's a
quick try:
def csound_formatter (in_file, out_file_file = sys.stdout):
INDENT = 10
CODE_LENGTH = 50
for l in in_file:
line = l.strip ()
if line == '':
out_file.write ('\n')
else:
if line [0] == ';': # Comment line
out_file.write ('%s\n' % line)
else:
code = comment = ''
if line [-1] == ':': # Label
out_file.write ('%s\n' % line)
else:
if ';' in line:
code, comment = line.split (';')
out_file.write ('%*s%-*s;%s\n' % (INDENT, '',
CODE_LENGTH, code, comment))
else:
out_file.write ('%*s%s\n' % (INDENT, '', line))
And here is a section of a csound file with white space squeezed out as
would make the file smaller:
>>csound = StringIO.StringIO ('''; Basic FM Instrument with Variable
Vibrato
; p4=amp p5=pch(fund) p6=vibdel p7=vibrate p8=vibwth
; p9=rise p10=decay p11=max index p12=car fac p13=modfac
; p14=index rise p15=index decay p16=left channel factor p17=original p3
instr 9,10,11,12
;--------------------------------------------------------------------------------
;initialization block:
kpitch init cpspch (p5)
itempo = p3/p17 ;ratio seconds/beats
idelay = p6 * itempo ;convert beats to secs
irise = p9 * itempo
idecay = p10 * itempo
indxris = (p14 == 0 ? irise : p14 * itempo)
indxdec = (p15 == 0 ? idecay : p15 * itempo)
if (p16 != 0) igoto panning ;if a panfac, use it, else
ilfac = .707 ;default is mono (sqrt(.5))
irfac = .707
igoto perform
panning:
ilfac = sqrt(p16)
irfac = sqrt(1-p16)
;--------------------------------------------------------------------------------
;performance block:
perform:
if (p7 == 0 || p8 == 0) goto continue
kontrol oscil1 idelay,1,.5,2 ;vib control
kvib oscili p8*kontrol,p7*kontrol,1 ;vibrato unit
kpitch = cpsoct(octpch(p5)+kvib) ;varying fund pitch in hz
continue:
kamp linen p4,irise,p3,idecay
kindex linen p11,indxris,p3,indxdec
asig foscili kamp,kpitch,p12,p13,kindex,1 ;p12,p13=carfac,mod fac
outs asig*ilfac,asig*irfac
endin
''')
Now we run this through the function defined above:
>>csound_formatter (s)
; Basic FM Instrument with Variable Vibrato
; p4=amp p5=pch(fund) p6=vibdel p7=vibrate p8=vibwth
; p9=rise p10=decay p11=max index p12=car fac p13=modfac
; p14=index rise p15=index decay p16=left channel factor p17=original p3
instr 9,10,11,12
;--------------------------------------------------------------------------------
;initialization block:
kpitch init cpspch (p5)
itempo = p3/p17 ;ratio
seconds/beats
idelay = p6 * itempo ;convert
beats to secs
irise = p9 * itempo
idecay = p10 * itempo
indxris = (p14 == 0 ? irise : p14 * itempo)
indxdec = (p15 == 0 ? idecay : p15 * itempo)
if (p16 != 0) igoto panning ;if a
panfac, use it, else
ilfac = .707 ;default is
mono (sqrt(.5))
irfac = .707
igoto perform
panning:
ilfac = sqrt(p16)
irfac = sqrt(1-p16)
;--------------------------------------------------------------------------------
;performance block:
perform:
if (p7 == 0 || p8 == 0) goto continue
kontrol oscil1 idelay,1,.5,2 ;vib control
kvib oscili p8*kontrol,p7*kontrol,1 ;vibrato unit
kpitch = cpsoct(octpch(p5)+kvib) ;varying
fund pitch in hz
continue:
kamp linen p4,irise,p3,idecay
kindex linen p11,indxris,p3,indxdec
asig foscili kamp,kpitch,p12,p13,kindex,1
;p12,p13=carfac,mod fac
outs asig*ilfac,asig*irfac
endin
It works on a couple of presumptions (e.g. no code following labels). So
it may not function perfectly but shouldn't be hard to tweak.
Hope this helps
Frederic
I was hoping to add and remove instruments.. although the other should
go into my example file because it will come in handy at some point.
It would also be cool to get a list of instruments along with any
comment line if there is one into a grid but that is two different
functions. http://www.dexrow.com Er*********@msn.com wrote:
Frederic Rentsch wrote:
>Er*********@msn.com wrote:
>>These are csound files. Csound recently added python as a scripting language and is allowing also allowing csound calls from outside of csound. The nice thing about csound is that instead of worrying about virus and large files it is an interpiter and all the files look somewhat like html. 4,000 virus free instruments for $20 is available at http://www.csounds.com and the csound programming book is also available. The downside is that csound is can be realy ugly looking (that is what I am trying to change) and it lets you write ugly looking song code that is almost unreadable at times (would look nice in a grid)
snip snip snip snip snip .........
I was hoping to add and remove instruments.. although the other should
go into my example file because it will come in handy at some point.
It would also be cool to get a list of instruments along with any
comment line if there is one into a grid but that is two different
functions.
http://www.dexrow.com
Eric,
Below the dotted line there are two functions.
"csound_filter ()" extracts and formats instrument blocks from
csound files and writes the output to another file. (If called without
an output file name, the output displays on the screen).
The second function, "make_instrument_dictionaries ()", takes the
file generated by the first function and makes two dictionaries. One of
them lists instrument ids keyed on instrument description, the other one
does it the other way around, listing descriptions by instrument id.
Instrument ids are file name plus instrument number.
You cannot depend on this system to function reliably, because it
extracts information from comments. I took my data from
"ems.music.utexas.edu/program/mus329j/CSPrimer.pdf" the author of which
happens to lead his instrument blocks with a header made up of comment
lines, the first of which characterizes the block. That first line I use
to make the dictionaries. If your data doesn't follow this practice,
then you may not get meaningful dictionaries and are in for some
hacking. In any case, this doesn't look like a job that can be fully
automated. But if you can build your data base with a manageable amount
of manual work you should be okay.
The SE filter likewise works depending on formal consistency with
my sample. If it fails, you may have to either tweak it or move up to a
parser.
I'll be glad to provide further assistance to the best of my
knowledge. But you will have to make an effort to express yourself
intelligibly. As a matter of fact the hardest part of proposing
solutions to your problem is guessing what your problem is. I suggest
you do this: before you post, show the message to a good friend and edit
it until he understands it.
Regards
Frederic
..
------------------------------------------------------------------------------------------------------------------------
def csound_filter (csound_file_name,
name_of_formatted_instrument_blocks_file = sys.stdout):
"""
This function filters and formats instrument blocks out of a
csound file.
csound_formatter (csound_file_name,
name_of_formatted_instrument_blocks_file)
csound_formatter (csound_file_name) # Single argument: screen output
"""
import SE
Instruments_Filter = SE.SE ('<EAT"~;.*~==(10)"
"~instr(.|\n)*?endin~==(10)(10)"')
INDENT = 10
CODE_LENGTH = 50
def format ():
for l in instruments_file:
line = l.strip ()
if line == '':
out_file.write ('\n')
else:
if line [0] == ';': # Comment line
out_file.write ('%s\n' % line)
else:
code = comment = ''
if line [-1] == ':': # Label
out_file.write ('%s\n' % line)
else:
if ';' in line:
code, comment = line.split (';')
out_file.write ('%*s%-*s;%s\n' % (INDENT, '',
CODE_LENGTH, code, comment))
else:
out_file.write ('%*s%s\n' % (INDENT, '', line))
instruments_file_name = Instruments_Filter (csound_file_name)
instruments_file = file (instruments_file_name, 'w+a')
if name_of_formatted_instrument_blocks_file != sys.stdout:
out_file = file (name_of_formatted_instrument_blocks_file, 'wa')
owns_out_file = True
else:
out_file = name_of_formatted_instrument_blocks_file
owns_out_file = False
format ()
if owns_out_file: out_file.close ()
def make_instrument_dictionaries (name_of_formatted_instrument_blocks_file):
"""
This function takes a file made by the previous function and
generates two dictionaries.
One records instrument ids by description. The other one
instrument descriptions by id.
Instrument ids are made up of file name and instrument number.
If these two dictionaries are pickled they can be used like data
bases and added to
incrementally.
"""
import re
instrument_numbers_re = re.compile ('instr *([0-9,]+)')
in_file = file (name_of_formatted_instrument_blocks_file, 'ra')
instrument_descriptions_by_id = {}
instrument_ids_by_description = {}
inside = False
for line in in_file:
line = line.strip ()
if not inside:
if line:
instrument_description = line [1:].rstrip ()
inside = True
else:
if line == '':
inside = False
if inside:
if line.startswith ('instr'):
instrument_numbers = instrument_numbers_re.match
(line).group (1).split (',')
instrument_ids = ['%s: %s' %
(name_of_formatted_instrument_blocks_file, i_n) for i_n in
instrument_numbers]
instrument_ids_by_description [instrument_description] =
instrument_ids
for instrument_id in instrument_ids:
instrument_descriptions_by_id [instrument_id] =
instrument_description
in_file.close ()
return instrument_descriptions_by_id, instrument_ids_by_description
---------------------------------------------------------------------------------------------
>>for instrument_id in instrument_descriptions_by_id:
print '%s - %s' % (instrument_id,
instrument_descriptions_by_id [instrument_id])
T:\instruments: 5 - Simple Gating Instrument with Chorus
T:\instruments: 4 - Portamento/Panning Instrument
T:\instruments: 12 - Basic FM Instrument with Variable Vibrato
T:\instruments: 11 - Basic FM Instrument with Variable Vibrato
T:\instruments: 10 - Basic FM Instrument with Variable Vibrato
---------------------------------------------------------------------------------------------
>>for description in instrument_ids_by_description:
print description
for instrument in instrument_ids_by_description [description]:
print ' ', instrument
Basic FM Instrument with Variable Vibrato
T:\instruments: 9
T:\instruments: 10
T:\instruments: 11
T:\instruments: 12
Simple Gating Instrument with Chorus
T:\instruments: 5
T:\instruments: 6
T:\instruments: 7
T:\instruments: 8
Portamento/Panning Instrument
T:\instruments: 1
T:\instruments: 2
T:\instruments: 3
T:\instruments: 4
--------------------------------------------------------------------------------------------- This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: WindAndWaves |
last post by:
Hi Gurus
I hope I am going to make sense with this question:
I have an html page that I have turned into a php page with a bit of php code above the html (connect to database, massage data a...
|
by: Sebastien GIRAUD |
last post by:
Hello,
First let say that am french and that i'll try to write the best english i can...
I'm a python newbe and have the following problem : I try to create 2 threads in a server program and they...
|
by: Ron |
last post by:
Is this built into any of the python versions? Need it! Using 2.3.5 and
doesn't seem to have it.Newbe needs help!email ron@nac.net Thanks Ron
|
by: Jean Pierre Daviau |
last post by:
Hi,
<script language="javascript" type="text/javascript">
if(navigator.appName.indexOf("Netscape") != -1){
document.writeln('<link rel="stylesheet" href="~styles/aquarelle_ns.css"...
|
by: Yaro |
last post by:
Hello
DB2/NT 8.1.3
Sorry for stupid questions. I am newbe in DB2.
1. How can I read *.sql script (with table and function definitions) into a
database? Tool, command...
2. In Project Center...
| |
by: Jim |
last post by:
I have created a windows form that contains several tab
pages which contain a panels. On a tab page I am trying
to dynamically create a series of buttons in that pages
panel. I am failing because...
|
by: ken |
last post by:
Hi all,
I copied this code from the examples. "How to: Receive Strings From
Serial Ports in Visual Basic" When I call the function and using the
single step method it hangs at Dim Incoming As...
|
by: AMP |
last post by:
I have a simple question.
If i have a button on form1 that creates :
Form2 newform = new Form2();
newform.Show();
As I click the button a new form shows,but acording to my code each one
has...
|
by: Eric_Dexter |
last post by:
def simplecsdtoorc(filename):
file = open(filename,"r")
alllines = file.read_until("</CsInstruments>")
pattern1 = re.compile("</")
orcfilename = filename + "orc"
for line in alllines:
if not...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |