Changeset 1501

Show
Ignore:
Timestamp:
Sun May 4 18:19:11 2008
Author:
laszlop
Message:

* Move instrument.path to project.audio_path. This is a more centralized location.
* Add in a levels_file attribute for Event. This will be used to store levels data when then levels storage is changed.

Files:

Legend:

Unmodified
Added
Removed
Modified
  • JonoEdit/trunk/Jokosher/ProjectManager.py

    r1500 r1501  
    53 53         project.author = author  
    54 54         project.projectfile = os.path.join(projectdir, filename)  
      55         project.audio_path = os.path.join(projectdir, "audio")  
      56         project.levels_path = os.path.join(projectdir, "levels")  
    55 57  
    56 58         if os.path.exists(projectdir):  
     
    128 130         project = Project.Project()  
    129 131         project.projectfile = projectfile  
      132         projectdir = os.path.split(projectfile)[0]  
      133         project.audio_path = os.path.join(projectdir, "audio")  
      134         project.levels_path = os.path.join(projectdir, "levels")  
    130 135          
    131 136         #only open projects with the proper version number  
     
    201 206                         except ValueError:  
    202 207                                 id = None  
    203                           e = Event.Event(instr, None, id)  
      208                         e = Event.Event(instr, None, None,  id)  
    203 208                         self.LoadEvent(e, ev)  
      209                         e.levels_file = os.path.basename(e.file + Event.Event.LEVELS_FILE_EXTENSION)  
    204 210                         instr.events.append(e)  
    205 211                  
     
    338 344                 Utils.LoadParametersFromXML(instr, params)  
    339 345                  
    340                   #figure out the instrument's path based on the location of the projectfile  
    341                   instr.path = os.path.join(os.path.dirname(self.project.projectfile), "audio")  
    342                    
    343 346                 globaleffect = xmlNode.getElementsByTagName("GlobalEffect")  
    344 347                  
     
    357 360                         except ValueError:  
    358 361                                 id = None  
    359                           event = Event.Event(instr, None, id)  
      362                         event = Event.Event(instr, None, None,  id)  
    359 362                         self.LoadEvent(event, ev)  
      363                         event.levels_file = os.path.basename(event.file + Event.Event.LEVELS_FILE_EXTENSION)  
    360 364                         instr.events.append(event)  
    361 365                  
     
    366 370                         except ValueError:  
    367 371                                 id = None  
    368                           event = Event.Event(instr, None, id)  
      372                         event = Event.Event(instr, None, None,  id)  
    368 372                         self.LoadEvent(event, ev, True)  
      373                         event.levels_file = os.path.basename(event.file + Event.Event.LEVELS_FILE_EXTENSION)  
    369 374                         instr.graveyard.append(event)  
    370 375  
     
    401 406                 if not os.path.isabs(event.file):  
    402 407                         # If there is a relative path for event.file, assume it is in the audio dir  
    403                           event.file = os.path.join(event.instrument.path, event.file)  
      408                         event.file = os.path.join(event.instrument.project.audio_path, event.file)  
    403 408                  
    404 409                 try:  
  • JonoEdit/trunk/Jokosher/Instrument.py

    r1496 r1501  
    96 96                 self.project = project  
    97 97                  
    98                   self.path = ""                          # The 'audio' directory for this instrument  
    99 98                 self.events = []                                # List of events attached to this instrument  
    100 99                 self.graveyard = []                     # List of events that have been deleted (kept for undo)  
     
    486 485         def GetRecordingEvent(self):  
    487 486                 """  
    488                   Obtain an Event suitable for recording. *CHECK*  
      487                 Obtain an Event suitable for recording.  
    488 487                 Returns:  
    489 488                         an Event suitable for recording.  
     
    494 493                 event.isRecording = True  
    495 494                 event.name = _("Recorded audio")  
    496                   event.file = "%s_%d_%d.ogg" % (os.path.join(self.path, Globals.FAT32SafeFilename(self.name)), self.id, int(time.time()))  
      495                  
      496                 filename = "%s_%d.ogg" % (Globals.FAT32SafeFilename(self.name), event.id)  
      497                 event.file = os.path.join(self.project.audio_path, filename)  
      498                 event.levels_file = filename + Event.Event.LEVELS_FILE_EXTENSION  
      499                  
    497 500                 #must add it to the instrument's list so that an update of the event lane will not remove the widget  
    498 501                 self.events.append(event)  
     
    581 584                 """  
    582 585                 filelabel=file  
      586                 event_id = self.project.GenerateUniqueID(None,  reserve=False)  
      587                 name = os.path.basename(file)  
      588                 root,  extension = os.path.splitext(name.replace(" ", "_"))  
      589                  
      590                 if extension:  
      591                         newfile = "%s_%d.%s" % (root, event_id, extension)  
      592                 else:  
      593                         newfile = "%s_%d" % (root, event_id)  
      594                  
      595                 levels_file = newfile + Event.Event.LEVELS_FILE_EXTENSION  
    583 596  
    584 597                 if copyfile:  
    585                           basename = os.path.split(file.replace(" ", "_"))[1]  
    586                           basecomp = basename.rsplit('.', 1)  
    587                           if len(basecomp) > 1:  
    588                                   newfile = "%s_%d_%d.%s" % (basecomp[0], self.id, int(time.time()), basecomp[len(basecomp)-1])  
    589                           else:  
    590                                   newfile = "%s_%d_%d" % (basecomp[0], self.id, int(time.time()))  
    591    
    592                           audio_file = os.path.join(self.path, newfile)  
      598                         audio_file = os.path.join(self.project.audio_path, newfile)  
    593 599                          
    594 600                         try:  
     
    600 606                          
    601 607                         file = audio_file  
    602                           name = basename  
    603                   else:  
    604                           name = file.split(os.sep)[-1]  
    605 608  
    606                   ev = Event.Event(self, file, None, filelabel)  
      609                 ev = Event.Event(self, file, levels_file, event_id, filelabel)  
    606 609                 ev.start = start  
    607 610                 ev.name = name  
     
    634 637                         the added Event.  
    635 638                 """  
      639                 event_id = self.project.GenerateUniqueID(None,  reserve=False)  
    636 640                 # no way of knowing whether there's a filename, so make one up  
    637                   newfile = "%d_%d" % (self.id, int(time.time()))  
    638    
    639                   audio_file = os.path.join(self.path, newfile)  
      641                 newfile = str(event_id)  
      642                 levels_file = newfile + Event.Event.LEVELS_FILE_EXTENSION  
      643                  
      644                 audio_file = os.path.join(self.project.audio_path, newfile)  
    640 645                 self.project.deleteOnCloseAudioFiles.append(audio_file)  
    641 646                  
    642 647                 # Create the event now so we can return it, and fill in the file later  
    643                   ev = Event.Event(self, audio_file, None, url)  
      648                 ev = Event.Event(self, audio_file, levels_file, event_id, url)  
    643 648                 ev.start = start  
    644 649                 ev.name = os.path.split(audio_file)[1]  
     
    671 676                         event - the Event to be cloned on this instrument.  
    672 677                 """  
    673                   ev = Event.Event(self, event.file)  
      678                 ev = Event.Event(self, event.file,  event.levels_file)  
    673 678                 ev.start = start  
    674 679                 for i in ["duration", "name", "offset"]:  
  • JonoEdit/trunk/Jokosher/Event.py

    r1497 r1501  
    53 53         """ The level sample interval in seconds """  
    54 54         LEVEL_INTERVAL = 0.01  
      55         LEVELS_FILE_EXTENSION = ".leveldata"  
    55 56          
    56 57         #_____________________________________________________________________  
    57 58          
    58           def __init__(self, instrument, file=None, id=None, filelabel=None):  
      59         def __init__(self, instrument, file=None, levels_file=None,  id=None, filelabel=None):  
    58 59                 """  
    59 60                 Creates a new instance of Event.  
     
    63 64                         instrument -- Instrument associated with this Event.  
    64 65                         file -- the file this Event should play.  
      66                         levels_file -- the file name (not directory path!) where the event's levels data will be stored  
    65 67                         id -- unique ID for this Event. If it's taken, a new one will be generated.  
    66 68                         filelabel -- label to print in error messages.  
     
    75 77                 # but **do not** assign it to this variable.  
    76 78                 self.file = file  
      79                 self.levels_file = levels_file          # a filename only, no directory information for levels here.  
    77 80  
    78 81                 # the label is the filename to print in error messages  
     
    198 201                  
    199 202                 items = ["start", "duration", "isSelected",  
    200                                     "name", "offset", "file", "filelabel", "isLoading", "isRecording"  
      203                                   "name", "offset", "file", "filelabel", "levels_file",  
      204                                   "isLoading", "isRecording"  
    201 205                                 ]  
    202 206                                  
     
    206 210                  
    207 211                 self.temp = self.file  
    208                   if os.path.samefile(self.instrument.path, os.path.dirname(self.file)):  
      212                 if os.path.samefile(self.instrument.project.audio_path, os.path.dirname(self.file)):  
    208 212                         # If the file is in the audio dir, just include the filename, not the absolute path  
    209 213                         self.file = os.path.basename(self.file)  
     
    337 341                         self.instrument.graveyard.remove(e)  
    338 342                 else:  
    339                           e = Event(self.instrument, self.file)  
      343                         e = Event(self.instrument, self.file,  self.levels_file)  
    339 343                 e.name = self.name  
    340 344                  
  • JonoEdit/trunk/Jokosher/Project.py

    r1493 r1501  
    90 90                 self.name = ""                          #the name of this project  
    91 91                 self.projectfile = ""           #the name of the project file, complete with path  
      92                 self.audio_path = ""  
      93                 self.levels_path = ""  
    92 94                 self.___id_list = []            #the list of IDs that have already been used, to avoid collisions  
    93 95                 self.instruments = []           #the list of instruments held by this project  
     
    678 680                 head.appendChild(params)  
    679 681                  
    680                   items = ["viewScale", "viewStart", "name", "author", "transportMode", "bpm", "meter_nom", "meter_denom"]  
      682                 items = ["viewScale", "viewStart", "name", "author", "project_audio_path",  "project_levels_path",  
      683                               "transportMode", "bpm", "meter_nom", "meter_denom"]  
    681 684                  
    682 685                 Utils.StoreParametersToXML(self, doc, params, items)  
     
    987 990                         #If this is the first instrument, arm it by default  
    988 991                         instr.isArmed = True  
    989                   audio_dir = os.path.join(os.path.split(self.projectfile)[0], "audio")  
    990                   instr.path = os.path.join(audio_dir)  
    991 992                  
    992 993                 self.temp = instr.id  
     
    1176 1177         #_____________________________________________________________________  
    1177 1178          
    1178           def GenerateUniqueID(self, id = None):  
      1179         def GenerateUniqueID(self, id = None,  reserve=True):  
    1178 1179                 """  
    1179 1180                 Creates a new unique ID which can be assigned to an new Project object.  
     
    1182 1183                 Parameters:  
    1183 1184                         id -- an unique ID proposal. If it's already taken, a new one is generated.  
      1185                         reserve -- if True, the ID will be recorded and never returned again.  
    1184 1186                          
    1185 1187                 Returns: