示例#1
0
文件: Event.py 项目: Barbosabyte/bard
    def SetProperties(self):
        """
		Sets basic Event properties like location, start, duration, etc.
		"""
        if self.file:
            if self.single_decode_bin:
                self.gnlsrc.remove(self.single_decode_bin)
                self.single_decode_bin.set_state(gst.STATE_NULL)

            Globals.debug("creating SingleDecodeBin")
            caps = gst.caps_from_string("audio/x-raw-int;audio/x-raw-float")
            f = PlatformUtils.pathname2url(self.GetAbsFile())
            Globals.debug("file uri is:", f)
            self.single_decode_bin = SingleDecodeBin(caps=caps, uri=f)
            self.gnlsrc.add(self.single_decode_bin)
            Globals.debug("setting event properties:")
            propsDict = {
                "caps": caps,
                "start": long(self.start * gst.SECOND),
                "duration": long(self.duration * gst.SECOND),
                "media-start": long(self.offset * gst.SECOND),
                "media-duration": long(self.duration * gst.SECOND),
                "priority": 2,
            }

            for prop, value in propsDict.iteritems():
                self.gnlsrc.set_property(prop, value)
                Globals.debug("\t", prop, "=", value)
示例#2
0
    def SetProperties(self):
        """
		Sets basic Event properties like location, start, duration, etc.
		"""
        if self.file:
            if self.single_decode_bin:
                self.gnlsrc.remove(self.single_decode_bin)
                self.single_decode_bin.set_state(gst.STATE_NULL)

            Globals.debug("creating SingleDecodeBin")
            caps = gst.caps_from_string("audio/x-raw-int;audio/x-raw-float")
            f = PlatformUtils.pathname2url(self.GetAbsFile())
            Globals.debug("file uri is:", f)
            self.single_decode_bin = SingleDecodeBin(caps=caps, uri=f)
            self.gnlsrc.add(self.single_decode_bin)
            Globals.debug("setting event properties:")
            propsDict = {
                "caps": caps,
                "start": long(self.start * gst.SECOND),
                "duration": long(self.duration * gst.SECOND),
                "media-start": long(self.offset * gst.SECOND),
                "media-duration": long(self.duration * gst.SECOND),
                "priority": 2
            }

            for prop, value in propsDict.iteritems():
                self.gnlsrc.set_property(prop, value)
                Globals.debug("\t", prop, "=", value)
示例#3
0
    def OnOK(self, button):
        """
		Tries to create and set a new Project with the user input name, author
		and location.
		If the process fails, a message is issued to the user stating the error.
		
		Parameters:
			button -- reserved for GTK callbacks, don't use it explicitly.
		"""
        name = self.name.get_text()
        if not name:
            name = _("New Project")

        author = self.author.get_text()
        if not author:
            author = _("Unknown Author")

        # CreateNewProject expects a URI
        folder = PlatformUtils.pathname2url(self.folder.get_filename())

        # Save the selected folder as the default folder
        Globals.settings.general["projectfolder"] = folder
        Globals.settings.write()
        if not folder:
            folder = "~"

        try:
            project = ProjectManager.CreateNewProject(folder, name, author)
        except ProjectManager.CreateProjectError, e:
            if e.errno == 1:
                message = _("Could not initialize project.")
            elif e.errno == 2:
                message = _(
                    "A file or folder with this name already exists. Please choose a different project name and try again."
                )
            elif e.errno == 3:
                message = _("The file or folder location is write-protected.")
            elif e.errno == 4:
                message = _("Invalid name or author.")
            elif e.errno == 5:
                message = _(
                    "The URI scheme given is either invalid or not supported")
            elif e.errno == 6:
                message = "%s %s" % (
                    _("Unable to load required Gstreamer plugin:"), e.message)

            # show the error dialog with the relavent error message
            dlg = gtk.MessageDialog(
                self.dlg, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
                gtk.MESSAGE_ERROR, gtk.BUTTONS_OK,
                _("Unable to create project.\n\n%s") % message)
            dlg.run()
            dlg.destroy()
示例#4
0
	def OnOK(self, button):
		"""
		Tries to create and set a new Project with the user input name, author
		and location.
		If the process fails, a message is issued to the user stating the error.
		
		Parameters:
			button -- reserved for GTK callbacks, don't use it explicitly.
		"""
		name = self.name.get_text()
		if not name:
			name = _("New Project")
			
		author = self.author.get_text()
		if not author:
			author = _("Unknown Author")
			
		# CreateNewProject expects a URI	
		folder = PlatformUtils.pathname2url(self.folder.get_filename())
		
		# Save the selected folder as the default folder
		Globals.settings.general["projectfolder"] = folder
		Globals.settings.write()
		if not folder:
			folder = "~"

		try:
			project = ProjectManager.CreateNewProject(folder, name, author)
		except ProjectManager.CreateProjectError, e:
			if e.errno == 1:
				message = _("Could not initialize project.")
			elif e.errno == 2:
				message = _("A file or folder with this name already exists. Please choose a different project name and try again.")
			elif e.errno == 3:
				message = _("The file or folder location is write-protected.")
			elif e.errno == 4:
				message = _("Invalid name or author.")
			elif e.errno == 5:
				message = _("The URI scheme given is either invalid or not supported")
			elif e.errno == 6:
				message = "%s %s" % (_("Unable to load required Gstreamer plugin:"), e.message)
			
			# show the error dialog with the relavent error message	
			dlg = gtk.MessageDialog(self.dlg,
				gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
				gtk.MESSAGE_ERROR,
				gtk.BUTTONS_OK,
				_("Unable to create project.\n\n%s") % message)
			dlg.run()
			dlg.destroy()
示例#5
0
	def CreateEventFromFile(self, event=None):
		"""
		Called when "Import Audio File..." is selected from the right-click context menu.
		Opens up a file chooser dialog to import an Event.
		
		Parameters:
			event -- reserved for GTK callbacks, don't use it explicitly.
		"""
		filenames, copyfile = self.mainview.ShowImportFileChooser()
		#filename will be None is the user cancelled the dialog
		if filenames:
			start = 0
			if event:
				#if we we're called from a mouse click, use the mouse position as the start
				start = (self.mouseDownPos[0]/self.project.viewScale) + self.project.viewStart
	
			uris = [PlatformUtils.pathname2url(filename) for filename in filenames]
			self.instrument.AddEventsFromList(start, uris)
示例#6
0
    def CreateEventFromFile(self, event=None):
        """
		Called when "Import Audio File..." is selected from the right-click context menu.
		Opens up a file chooser dialog to import an Event.
		
		Parameters:
			event -- reserved for GTK callbacks, don't use it explicitly.
		"""
        filenames, copyfile = self.mainview.ShowImportFileChooser()
        #filename will be None is the user cancelled the dialog
        if filenames:
            start = 0
            if event:
                #if we we're called from a mouse click, use the mouse position as the start
                start = (self.mouseDownPos[0] /
                         self.project.viewScale) + self.project.viewStart

            uris = [
                PlatformUtils.pathname2url(filename) for filename in filenames
            ]
            self.instrument.AddEventsFromList(start, uris)
示例#7
0
def CreateNewProject(name, author, projecturi=None):
	"""
	Creates a new Project.

	Parameters:
		name --	the name of the Project.
		author - the name of the Project's author.
		projecturi -- the filesystem location for the new Project.
						Currently, only file:// URIs are considered valid.
		
	Returns:
		the newly created Project object.
	"""
	
	if not projecturi:
		projecturi = PlatformUtils.pathname2url(Globals.PROJECTS_PATH)
		
	project = InitProjectLocation(projecturi)
	project.name = name
	project.author = author
	
	project.SaveProjectFile(project.projectfile)
	return project
示例#8
0
	except OSError, e:
		Globals.debug("Cannot remove project. Have the permissions been changed, or other directories created inside the project folder?:\n\t%s" % main_dir)

#_____________________________________________________________________

def ImportProject(project_uri):
	try:
		old_project = LoadProjectFile(project_uri)
	except OpenProjectError, e:
		raise
		
	all_files = old_project.GetAudioAndLevelsFilenames(include_deleted=True)
	abs_audio_files, rel_audio_files, levels_files = all_files
	
	try:
		new_project = InitProjectLocation(PlatformUtils.pathname2url(Globals.PROJECTS_PATH))
	except CreateProjectError, e:
		return None
	
	delete_on_fail_list = []
	
	try:
		for audio_filename in rel_audio_files:
			src = gio.File(path=old_project.audio_path).get_child(audio_filename)
			dst = gio.File(path=new_project.audio_path).get_child(audio_filename)
		
			src.copy(dst)
			delete_on_fail_list.append(dst.get_uri())
		
			Globals.debug("Copy:\n\t" + src.get_uri() + "\n\t" + dst.get_uri())