Any good donothing?

Dialtone Dialtone.NOSPAM.ME at aruba.it
Wed Apr 16 00:47:11 CEST 2003


Hi all. I'm working on a kind of all-in-one cd2mp3 encoder based on lame
and cdda2wav and pygame.

A little code snippet is the following (it is already indented once
because it is part of a bigger class, not so bigger, named cd2mp3).
My problem is to sync the 2 processes which are launched with the
os.system() call but without having the main program locked.
I initially thought that a wait inside a cicle would have got me an easy
solution but it didn't since it locks the main program anyway... Is
there any other way to make a do_nothing_for_some_time(n) function? Or
otherwise... is there another good way to sync those 2 processes without
having the main program locked (and also without having the encoder to
finish ecoding before the ripper has finished).  thanks a lot.

    def start(self, cdda=1, input_file=None, output_file=None, path="./library/audio/", bitrate=128):
#        mkdir_cmd = "mkdir %s%s" % (path, self.artist)
 #       os.system(mkdir_cmd)
  #      path = path + self.artist + "/"
        
        for i in xrange(self.start_track, self.num_tracks):
            try:
                self.infos = "Ripping: %s" % (self.tracks[i])
                self.infos2 = "Encoding: %s" % (self.tracks[i])
            except:
                self.infos = "Ripping track num %d" % (i)
                self.infos2 = "Encoding track num %d" % (i)
                
            self.surface.blit(self.text_bg, self.text_rect)
            pygame.display.flip()
            self.rendered_text = pygame.font.Font(None, 20).render(self.infos, 1, [255, 255, 255])
            self.text_surf.blit(self.rendered_text, (0,0))
            pygame.display.flip()
           
            # If tracks' names found
            if self.succeded:
                output_file = 1
                
            self.cdda2wav_string, self.wav2mp3_string = self.prefs(i, input_file, output_file, path, bitrate)
            if cdda:
                self.wav = os.system(self.cdda2wav_string)
                self.lose_time(20)
                self.progress_bar.inc(self.perc_incr)
                self.text_surf.blit(self.rendered_text, (0,0))
                pygame.display.flip()
            
            self.surface.blit(self.text_bg, self.text_rect)
            pygame.display.flip()
            self.rendered_text = pygame.font.Font(None, 20).render(self.infos2, 1, [255,255,255])
            self.text_surf.blit(self.rendered_text, (0,0))
            pygame.display.flip()
            
            self.mp3 = os.system(self.wav2mp3_string)
            self.lose_time(40)
            self.progress_bar.inc(self.perc_incr)
            self.clean = os.system('rm -rf *.inf && rm -rf *.wav')
        text = "%d track(s) successfully encoded" % (self.num_tracks-self.start_track)
        self.progress_bar.stop(text)
        
    def prefs(self, cur_track, input_file, output_file, path, bitrate=128, dev='/dev/cdrom'):
        """
        settare le preferenze tipo 
        bitrate della conversione etc..
        """
        if not output_file:
            output_file = "audio_%d.mp3" % (cur_track)
        else: output_file = "%s.mp3" % (self.__prepare(self.tracks[cur_track]))

        if not input_file:
            input_file = "audio.wav"
        
        cdda2wav_string = "cdda2wav -D %s -t %d+%d &" % (dev, cur_track, cur_track)
        wav2mp3_string = "lame -b %d %s %s%s &" % (bitrate, input_file, path, output_file)

        return cdda2wav_string, wav2mp3_string

    def lose_time(self, seconds):
        for i in xrange(seconds):
            pygame.time.wait(1000)


-- 
try: troll.uses(Brain)
except TypeError, data: 
   troll.plonk()
Co-Responsabile Hardware Information & Technology http://hit.edengames.net




More information about the Python-list mailing list