Friday, January 19, 2007

 

changing the time in a .sco file (or csd) for that matter

This is a question I saw on the csound message system... realy it is an easy question usualy. there may be a glitch because there are several types of computer systems and programs saving text files..

The first thing would be to get rid of \n if they are being saved as part of the word..

for line in infile:
#just in case \n is causing trouble
for word in line:
if len(word) > 2:
if '\n' in word:
word = word[:-2]

Time is the second variable (usually unless the instrument has been done as i 1 instead of i1 and that can probity be checked for). The way I did it requires i to be the first character of the line. It is a little extra requirement that makes it easier to deal with the file. I split the line into its parts next. We have to check to see if it is a number in addition to typo's and possibly strange white space characters, you also have . and - as possible time characters. It is possible I have the count in the wrong place or partially messed up (cut and paste doesn't work so well for the blog. That is pretty much it we are just doing writing and simple tasks after that.

def orc_altertime(from_file, to_file, seconds):

fromfile = open(from_file, 'r')
tofile = open(to_file, 'w')
for line in fromfile:
if line.startswith('i')
w = line.split(' ')
if w[1].isdigit():
s = int(w[1])
s = s + seconds
#count = 0
for key in w:
print w
if count == 1:
if w[1].isdigit():
tofile.write(str(s) + ' ')
else:
tofile.write(w[1])
else:
tofile.write(key + ' ')
count = count + 1
tofile.write('\n')

Labels: ,


Comments: Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?