示例#1
0
  def run(self, ticks):
    if self.wizardStarted:
      return
    self.wizardStarted = True

    name = ""
    while True:
      masks = ["*.ogg"]
      name  = Dialogs.getText(self.engine, prompt = _("Enter a name for the song."), text = name)

      if not name:
        self.engine.view.popLayer(self)
        return

      path = os.path.abspath(self.engine.resource.fileName("songs", name))
      if os.path.isdir(path):
        Dialogs.showMessage(self.engine, _("That song already exists."))
      else:
        break

    guitarTrack     = Dialogs.chooseFile(self.engine, masks = masks, prompt = _("Choose the Instrument Track (OGG format)."))

    if not guitarTrack:
      self.engine.view.popLayer(self)
      return

    backgroundTrack = Dialogs.chooseFile(self.engine, masks = masks, prompt = _("Choose the Background Track (OGG format) or press Escape to skip."))

    # Create the song
    loader = self.engine.resource.load(self, "song", lambda: createSong(self.engine, name, guitarTrack, backgroundTrack))
    Dialogs.showLoadingScreen(self.engine, lambda: self.song or loader.exception, text = _("Importing..."))

    if not loader.exception:
      self.songName = name
    self.engine.view.popLayer(self)
示例#2
0
  def run(self, ticks):
    if self.wizardStarted:
      return
    self.wizardStarted = True

    name = ""
    while 1:
      masks = ["*.ogg"]
      name  = Dialogs.getText(self.engine, prompt = str("Enter a name for the song."), text = name)

      if not name:
        self.engine.view.popLayer(self)
        return

      path = os.path.abspath(self.engine.resource.fileName("songs", name))
      if os.path.isdir(path):
        Dialogs.showMessage(self.engine, str("That song already exists."))
      else:
        break

    guitarTrack     = Dialogs.chooseFile(self.engine, masks = masks, prompt = str("Choose the Instrument Track (OGG format)."))

    if not guitarTrack:
      self.engine.view.popLayer(self)
      return

    backgroundTrack = Dialogs.chooseFile(self.engine, masks = masks, prompt = str("Choose the Background Track (OGG format) or press Escape to skip."))

    # Create the song
    loader = self.engine.resource.load(self, "song", lambda: createSong(self.engine, name, guitarTrack, backgroundTrack))
    Dialogs.showLoadingScreen(self.engine, lambda: self.song or loader.exception, text = str("Importing..."))

    if not loader.exception:
      self.songName = name
    self.engine.view.popLayer(self)
示例#3
0
  def importSongs(self, headerPath, archivePath, workPath):
    try:
      try:
        os.mkdir(workPath)
      except:
        pass

      # Read the song map
      self.statusText = _("Reading the song list.")
      songMap = {}
      vgsMap  = {}
      library = DEFAULT_LIBRARY
      for line in open(self.engine.resource.fileName("ghmidimap.txt")):
        fields = map(lambda s: s.strip(), line.strip().split(";"))
        if fields[0] == "$library":
          library = os.path.join(DEFAULT_LIBRARY, fields[1])
        else:
          songName, fullName, artist = fields
          songMap[songName] = (library, fullName, artist)

      self.statusText = _("Reading the archive index.")
      archive = ArkFile(headerPath, archivePath)
      songs    = []

      # Filter out the songs that aren't in this archive
      for songName, data in songMap.items():
        library, fullName, artist = data
        songPath = self.engine.resource.fileName(library, songName, writable = True)

        vgsMap[songName] = "songs/%s/%s.vgs" % (songName, songName)
        if not vgsMap[songName] in archive.files:
          vgsMap[songName] = "songs/%s/%s_sp.vgs" % (songName, songName)
          if not vgsMap[songName] in archive.files:
            Log.warn("VGS file for song '%s' not found in this archive." % songName)
            del songMap[songName]
            continue

        if os.path.exists(songPath):
          Log.warn("Song '%s' already exists." % songName)
          del songMap[songName]
          continue

      for songName, data in songMap.items():
        library, fullName, artist = data
        songPath = self.engine.resource.fileName(library, songName, writable = True)
        print songPath

        Log.notice("Extracting song '%s'" % songName)
        self.statusText = _("Extracting %s by %s. %d of %d songs imported. Yeah, this is going to take forever.") % (fullName, artist, len(songs), len(songMap))

        archiveMidiFile = "songs/%s/%s.mid" % (songName, songName)
        archiveVgsFile  = vgsMap[songName]

        # Check that the required files exist
        if not archiveMidiFile in archive.files:
          Log.warn("MIDI file for song '%s' not found." % songName)
          continue

        if not archiveVgsFile in archive.files:
          Log.warn("VGS file for song '%s' not found." % songName)
          continue

        # Debug dump
        #vgsFile       = archive.openFile(archiveVgsFile)
        #open("/tmp/test.vgs", "wb").write(vgsFile.read(archive.fileLength(archiveVgsFile)))

        # Grab the VGS file
        vgsFile       = archive.openFile(archiveVgsFile)
        vgsFileLength = archive.fileLength(archiveVgsFile)
        guitarOggFile = os.path.join(workPath, "guitar.ogg")
        songOggFile   = os.path.join(workPath, "song.ogg")
        rhythmOggFile = os.path.join(workPath, "rhythm.ogg")
        self.decodeVgsFile(vgsFile, vgsFileLength, songOggFile, guitarOggFile, rhythmOggFile, workPath)
        vgsFile.close()

        # Create the song
        if not os.path.isfile(rhythmOggFile):
          rhythmOggFile = None

        song = createSong(self.engine, songName, guitarOggFile, songOggFile, rhythmOggFile, library = library)
        song.info.name   = fullName.strip()
        song.info.artist = artist.strip()
        song.save()

        # Grab the MIDI file
        archive.extractFile(archiveMidiFile, os.path.join(songPath, "notes.mid"))

        # Done with this song
        songs.append(songName)

      # Clean up
      shutil.rmtree(workPath)

      self.stageInfoText = _("Ready")
      self.stageProgress = 1.0
      Log.debug("Songs imported: " + ", ".join(songs))
      return songs
    except:
      self.done = True
      raise
示例#4
0
文件: Editor.py 项目: Gamer125/fofix
    def importSongs(self, headerPath, archivePath, workPath):
        try:
            try:
                os.mkdir(workPath)
            except:
                pass

            # Read the song map
            self.statusText = _("Reading the song list.")
            songMap = {}
            vgsMap = {}
            for line in open(self.engine.resource.fileName("ghmidimap.txt")):
                songName, fullName, artist = map(lambda s: s.strip(),
                                                 line.strip().split(";"))
                songMap[songName] = (fullName, artist)

            self.statusText = _("Reading the archive index.")
            archive = ArkFile(headerPath, archivePath)
            songPath = self.engine.resource.fileName("songs", writable=True)
            songs = []

            # Filter out the songs that aren't in this archive
            for songName, data in songMap.items():
                vgsMap[songName] = "songs/%s/%s.vgs" % (songName, songName)
                if not vgsMap[songName] in archive.files:
                    vgsMap[songName] = "songs/%s/%s_sp.vgs" % (songName,
                                                               songName)
                    if not vgsMap[songName] in archive.files:
                        Log.warn(
                            "VGS file for song '%s' not found in this archive."
                            % songName)
                        del songMap[songName]
                        continue

                if os.path.exists(os.path.join(songPath, songName)):
                    Log.warn("Song '%s' already exists." % songName)
                    del songMap[songName]
                    continue

            for songName, data in songMap.items():
                fullName, artist = data

                Log.notice("Extracting song '%s'" % songName)
                self.statusText = _(
                    "Extracting %s by %s. %d of %d songs imported. Yeah, this is going to take forever."
                ) % (fullName, artist, len(songs), len(songMap))

                archiveMidiFile = "songs/%s/%s.mid" % (songName, songName)
                archiveVgsFile = vgsMap[songName]

                # Check that the required files exist
                if not archiveMidiFile in archive.files:
                    Log.warn("MIDI file for song '%s' not found." % songName)
                    continue

                if not archiveVgsFile in archive.files:
                    Log.warn("VGS file for song '%s' not found." % songName)
                    continue

                # Debug dump
                #vgsFile       = archive.openFile(archiveVgsFile)
                #open("/tmp/test.vgs", "wb").write(vgsFile.read(archive.fileLength(archiveVgsFile)))

                # Grab the VGS file
                vgsFile = archive.openFile(archiveVgsFile)
                vgsFileLength = archive.fileLength(archiveVgsFile)
                guitarOggFile = os.path.join(workPath, "guitar.ogg")
                songOggFile = os.path.join(workPath, "song.ogg")
                rhythmOggFile = os.path.join(workPath, "rhythm.ogg")
                self.decodeVgsFile(vgsFile, vgsFileLength, songOggFile,
                                   guitarOggFile, rhythmOggFile, workPath)
                vgsFile.close()

                # Create the song
                if not os.path.isfile(rhythmOggFile):
                    rhythmOggFile = None

                song = createSong(self.engine, songName, guitarOggFile,
                                  songOggFile, rhythmOggFile)
                song.info.name = fullName.strip()
                song.info.artist = artist.strip()
                song.save()

                # Grab the MIDI file
                archive.extractFile(
                    archiveMidiFile,
                    os.path.join(songPath, songName, "notes.mid"))

                # Done with this song
                songs.append(songName)

            # Clean up
            shutil.rmtree(workPath)

            self.stageInfoText = _("Ready")
            self.stageProgress = 1.0
            Log.debug("Songs imported: " + ", ".join(songs))
            return songs
        except:
            self.done = True
            raise