Re: Is there a limit to os.popen()?
> kr = string.strip(os.popen('make kernelrelease').read()) If make is being executed, I presume that the python script has rw access to the location. How about x=os.system("make kernelrelease > my_report 2>&1 ") kr=open("my_report").read() Just a blind throw. Good luck sree -- http://mail.python.org/mailman/listinfo/python-list
Re: threading troubles
Piet van Oostrum wrote: >>>>>> sreekant <[EMAIL PROTECTED]> (S) wrote: > >> S> I decided in the end to use fork and all is well. > > But how are you doing the callback then? From your code it looks like the > callback is called after the external command finishes. The callback would > then be called in the child process, not in the parent process, I think. Or > do you have a solution for that? I am not calling the callback now. It is a pygtk interface to octavia music description language I wrote. I have a button "Play" which reads the text in the gtk.TextView , converts it to midi and calls fluidsynth with the resulting midi file. I want the ui to be accessible during the midi play because, the midi play can some times be a long piece of music. I also have a log window which is another textview. I was loading the result of res=os.popen3(my_command) report=res[1].read()+'\n'+res[2].read() logwindow gets the report added to it. However now I just put a message saying "playing midi" I don't know any way out at the moment. What I need is when I click on the play button, the fileplay(widget) function that gets called should be able to start a new thread or a fork which executes the commands and updates the ui.logwindow which is a textview with the output of os.popen3. During the execution the ui should be usable. Please see the scala program in this package http://sourceforge.net/projects/octavia . Checkout fileplay() function in the most latest version 0.22 . I don't want to attach the whole program to this message and annoy everyone. Below is the function causing probs. Ta sree ### def fileplay(x): global conf,bdir,bgplay lbuf.delete(lbuf.get_start_iter(),lbuf.get_end_iter()) dat=buf.get_text(buf.get_start_iter(),buf.get_end_iter()) if not len(dat)>0: return #see if the temporary dir to save temp gmc and midi exists #if not create it tempf=bdir+os.sep+'temp'+os.sep try: if not os.path.exists(tempf): os.mkdir(tempf) except: addlog(traceback.format_exc()) return #save octavia in to a count+1 text file if os.path.exists(tempf): try: fbase=tempf+getcnt() fmidi=fbase+'.midi' f=open(fbase,'w') f.write(dat) f.close() except: addlog(traceback.format_exc()) #run octavia addlog("Compiling to midi") if conf.has_key('octavia'): text2midi=conf['octavia'] else: addlog("Config doesn't exist. Trying default octavia") text2midi='octavia' try: res=os.popen3(text2midi+' '+fbase+' '+fmidi) addlog(res[1].read()+res[2].read()) except: addlog(traceback.format_exc()) return # if midi exists, we succeded. play midi if os.path.exists(fmidi): addlog("Trying to play midi") if conf.has_key('midiplayer'): midiplay=conf['midiplayer'] else: addlog("Config doesn't exist. Trying default timidity") midiplay='timidity' # start playing in a fork pid=os.fork() if pid: pass else: os.popen3(midiplay+' '+fmidi) sys.exit(0) -- http://mail.python.org/mailman/listinfo/python-list
Re: How to use images at the bachground?
pipehappy wrote: >> hi all, >> how to get out of the python shell which is executing a command? >> how to use images in the background of a page in Tkinter? > > on Unix, ctrl-c or ctrl-d may do the job. > on Windows, ctrl-z will do > Hi I presume you meant putting a image as a background for a Tkinter app. If so , try Tkinter.Canvas. Best of luck sree -- http://mail.python.org/mailman/listinfo/python-list
Re: threading troubles
Oh dear. For the time being I will leave it with fork and leave it at that. Ta sree > You may be missing nothing. If I recall correctly a similar problem was > once reported on the pygtk-list. Some investigation showed that some > programs couldn't be reliably run from a thread, using os.system. > -- http://mail.python.org/mailman/listinfo/python-list
problems with midi programming in python
Hi folks I hope someone here might be able to help. I scavenged some info and even code from the net and am trying to write a module that reads a text file and spits out a midi file. So far I managed to make it work to the level of reading a text file with appropriate notes, octaves, transposing, volume, aftertouch, polyphony, channeltouch etc. However I am stuck at writing notes longer than 127 decimal number. The code I am using is below. I didn't post the whole code to keep it brief. If it is ok I will post the whole. ### def note_on(self, time, channel, note, velocity): return varLen(time) + [0x90 + channel, note, velocity] def varLen(value): # Big endian variable byte word # as defined by the midi standard result = [] while value: result.append((value & 0x7F) | 0x80) value = value >> 7 if len(result) == 0: return [0] else: result[len(result)-1] -= 128 result.reverse() return result # note_on should accept time,channel,note and velocity as decimals. Note and velocity are not a problem as their numbers are small. If I want to put a note that lasts say longer than 127, fluidsynth moans saying unexpected eof or unexpected byte 0xfe. What I would like to do is, to be able to note_on(1500,1,60,120) 1500 being the problem. Midi file standard says that time is written as a variable length entity. so if 1500 does not fit in a byte it should then use as many bytes as needed, but all bytes except last one have their msb set to 1 to show there is more to come. Below is the output of mftext for a working and nonworking midi files respectively. ## playing a single 'a' note working fine ### Header format=1 ntrks=2 division=24 Track start Time=0 Tempo, microseconds-per-MIDI-quarter-note=50 Time=0 Time signature=4/4 MIDI-clocks/click=24 32nd-notes/24-MIDI-clocks=8 Time=0 Meta event, end of track Track end Track start Time=0 Program, chan=1 program=1 Time=0 Note on, chan=1 pitch=57 vol=127 Time=127 Note off, chan=1 pitch=57 vol=0 Time=127 Meta event, end of track Track end ## # playing a single a note, with double the 127 duration## not working Header format=1 ntrks=2 division=24 Track start Time=0 Tempo, microseconds-per-MIDI-quarter-note=50 Time=0 Time signature=4/4 MIDI-clocks/click=24 32nd-notes/24-MIDI-clocks=8 Time=0 Meta event, end of track Track end Track start Time=0 Program, chan=1 program=1 Time=0 Note on, chan=1 pitch=57 vol=127 Error: unexpected byte: 0xfe # What am I doing wrong!! Help appreciated. ta sree -- http://mail.python.org/mailman/listinfo/python-list
Re: problems with midi programming in python
Total godsend. Had to reverse the list but now it works perfectly. Not only it solved the problem of longer notes but also that of rests. If you don't terribly mind, during the development of this particular program , I would love to ask for help. If that is ok with you, please reply to sreekant UNDER_SCORE At Yahoo DhoTT Com Thanks sree > Here's a snippit which does work: > > def intToVarNumber(x): > """ Convert INT to a variable length MIDI value. """ > > lst = chr(x & 0x7f) > while 1: > x = x >> 7 > if x: > lst = chr((x & 0x7f) | 0x80) + lst > else: > return lst > > See my program MMA for lots of ugly tricks. > http://users.xplornet.com/~bvdp/mma > > Best, > -- http://mail.python.org/mailman/listinfo/python-list
Re: problems with midi programming in python
Simon Forman wrote: > Not related to your actual question, but note: > >> if len(result) == 0: > > empty lists test as False, so this can just be > >> if not result: > > > > and > >> result[len(result)-1] -= 128 > > you can index lists with negative ints, backwards from the end of the > list, so this can be > >> result[-1] -= 128 > > > Those are two of my favorite things about python. :-) > > > Peace, > ~Simon > I love python. However, not so shamefully, the above isn't my code. I am not that good :-( I scavenged most of the bit shifting code from the net. I am ok with most of the data structures but bit shifting flies past my head, too far above. Ta sree -- http://mail.python.org/mailman/listinfo/python-list
Announcement : Octavia
Hi folks I just released a text to midi converter. Have a look at http://sourceforge.net/projects/octavia http://sourceforge.net/project/showfiles.php?group_id=171815 It uses a text description of music and runs the body of the music source file in python, leaving full facilities of python in your hands! Ta sree -- http://mail.python.org/mailman/listinfo/python-list
threading troubles
Hi folks What am I doing wrong in the following? I just want to run fluidsynth in the background. # class MyThread(threading.Thread): def __init__(self, cmd, callback): self.__cmd = cmd self.__callback = callback threading.Thread.__init__(self) def run(self): os.system(self.__cmd) self.__callback('abcd') return cmd=midiplay+' '+fmidi xc=MyThread(cmd,addlog) xc.start() ## midiplay is 'fluidsynth -ni /home/mysndfont.sf2 mymidi.mid' addlog is a function which prints the log. If I run it only with xc.start() it does not run the program as in os.system. However if I put xc.start() xc.run() then it starts and runs it in foreground with my pygtk ui non responsive. What am I missing! Thanks for any ideas sree -- http://mail.python.org/mailman/listinfo/python-list
Re: Howto or Tutorial for tokenize module for a newbie?
TY wrote: > Hi, > > Can someone point me to a Howto or Tutorial for tokenize module for a > newbie? I read the documentation but it doesn't have a lot of info... > Thanks! > Hi there I don't know if I got your requirement. But I used a own version of tokenizer which can use more than one delimiters. It is below. Hopefully of some use to you. def gettokens(dat): delims={'=':'',';':',','=':'','(':'',')':'',':':'','[':'',']':''} wlist=[] appended=0 for n in string.split(dat,'\n'): word='' for m in n: appended=0 if delims.has_key(m): wlist.append(word) wlist.append(m) word='' appended=1 else: word=word+m if appended==0: wlist.append(word) appended=1 wlist.append("\n") return wlist I am sure there are plenty of ways to write it better than that. Good luck sree -- http://mail.python.org/mailman/listinfo/python-list
Re: threading troubles
Hi there I tried as advised. Now the function gets called only after I hit quit button which calls gtk.main_quit() at which point, the ui stays on but not responsive, while the fluidsynth runs in the fg, then ui disappears as the fluidsynth finishes and presumably the thread dies. xc = threading.Thread(target=player,args=(midicmd,fmidi,addlog)) xc.start() def player(mp,fm,callback): res=os.system(mp+' '+fm) os.remove(fm) return I tried in the player, both os.popen3 and os.system and os.popen3 with cmd+' &' and the same with os.system . But all do the same thing. Any ideas! Ta sree > > you can use threads, but try doing it the python way instead of the > java way. ;-) > def func(cmd, callback): > os.system(cmd) > callback() > xc = threading.Thread(target=func, args=(cmd, callback)) > xc.start() > > -- http://mail.python.org/mailman/listinfo/python-list
Re: threading troubles
I decided in the end to use fork and all is well. Thanks sree -- http://mail.python.org/mailman/listinfo/python-list