Пример #1
0
    def __init__(self, qtApp):
        super().__init__()

        self.qtApp = qtApp
        self.layout = QtWidgets.QVBoxLayout()
        self.layout.setAlignment(QtCore.Qt.AlignTop | QtCore.Qt.AlignLeft)
        self.setLayout(self.layout)

        niceTitle = "PyNSM v2 Example - JACK Noise"
        self.title = QtWidgets.QLabel("")
        self.saved = QtWidgets.QLabel("")
        self._value = QtWidgets.QSlider(orientation = 1) #horizontal
        self._value.setMinimum(0)
        self._value.setMaximum(100)
        self._value.setValue(50) #only visible for the first start.

        self.valueLabel = QtWidgets.QLabel("Noise Volume: " + str(self._value.value()))
        self._value.valueChanged.connect(lambda new: self.valueLabel.setText("Noise Volume: " + str(new)))

        self.layout.addWidget(self.title)
        self.layout.addWidget(self.saved)
        self.layout.addWidget(self._value)
        self.layout.addWidget(self.valueLabel)

        #Prepare the NSM Client
        #This has to be done as soon as possible because NSM provides paths and names for us.
        #and may quit if NSM environment var was not found.
        self.nsmClient = NSMClient(prettyName = niceTitle, #will raise an error and exit if this example is not run from NSM.
                      supportsSaveStatus = True,
                      saveCallback = self.saveCallback,
                      openOrNewCallback = self.openOrNewCallback,
                      exitProgramCallback = self.exitCallback,
                      loggingLevel = "info", #"info" for development or debugging, "error" for production. default is error.
                      )
        #If NSM did not start up properly the program quits here with an error message from NSM.
        #No JACK client gets created, no Qt window can be seen.


        self.title.setText("<b>" + self.nsmClient.ourClientNameUnderNSM +  "</b>")

        self.eventLoop = QtCore.QTimer()
        self.eventLoop.start(100) #10ms-20ms is smooth for "real time" feeling. 100ms is still ok.
        self.eventLoop.timeout.connect(self.nsmClient.reactToMessage)
Пример #2
0
    def __init__(self, client_name='jack_mixer'):
        self.visible = False
        self.nsm_client = None

        if os.environ.get('NSM_URL'):
            self.nsm_client = NSMClient(
                prettyName="jack_mixer",
                saveCallback=self.nsm_save_cb,
                openOrNewCallback=self.nsm_open_cb,
                supportsSaveStatus=False,
                hideGUICallback=self.nsm_hide_cb,
                showGUICallback=self.nsm_show_cb,
                exitProgramCallback=self.nsm_exit_cb,
                loggingLevel="error",
            )
            self.nsm_client.announceGuiVisibility(self.visible)
        else:
            self.visible = True
            self.create_mixer(client_name, with_nsm=False)
Пример #3
0
    def __init__(self, name, delayedFunctions=[], eventFunction=None):
        """delayedFunctions are a (timer delay in seconds, function call) list of tuples. They will
        be executed once.
        If the function is a string instead it will be evaluated in the BaseClient context,
        providing self. Do not give a lambda!


        Give eventFunction for repeated execution."""

        self.nsmClient = NSMClient(
            prettyName=
            name,  #will raise an error and exit if this example is not run from NSM.
            saveCallback=self.saveCallbackFunction,
            openOrNewCallback=self.openOrNewCallbackFunction,
            supportsSaveStatus=
            False,  # Change this to True if your program announces it's save status to NSM
            exitProgramCallback=self.exitCallbackFunction,
            broadcastCallback=self.broadcastCallbackFunction,
            hideGUICallback=
            None,  #replace with your hiding function. You need to answer in your function with nsmClient.announceGuiVisibility(False)
            showGUICallback=
            None,  #replace with your showing function. You need to answer in your function with nsmClient.announceGuiVisibility(True)
            loggingLevel=
            "info",  #"info" for development or debugging, "error" for production. default is error.
        )

        if eventFunction:
            self.event = eventFunction

        for delay, func in delayedFunctions:
            if type(func) is str:
                func = eval('lambda self=self: ' + func)
            t = Timer(interval=delay, function=func, args=())
            t.start()

        while True:
            self.nsmClient.reactToMessage()
            self.event(self.nsmClient)
            sleep(0.05)
Пример #4
0
    This is only an example after all. Nobody should use pure Xlib for
    a real program. Quitting a program is easily done with a real
    GUI Toolkit like Qt.

    """
    cjack.jack_client_close(
        ctypesJackClient
    )  #omitting this introduces problems. in Jack1 this would mute all jack clients for several seconds.
    #Exit is done by NSM kill.


nsmClient = NSMClient(
    prettyName=niceTitle,
    supportsSaveStatus=True,
    saveCallback=saveCallback,
    openOrNewCallback=openCallback,
    exitProgramCallback=exitProgram,
    loggingLevel=
    "info",  #"info" for development or debugging, "error" for production. default is error.
)

#If NSM did not start up properly the program quits here. No JACK client gets created, no X window can be seen.

########################################################################
#Prepare the JACK Client
#We can't do that without the values we got from nsmClient: path names.
########################################################################
cjack = ctypes.cdll.LoadLibrary("libjack.so.0")
clientName = nsmClient.prettyName
options = 0
status = None
Пример #5
0
def hideGUICallback():
    # Put your code that hides your GUI in here
    print("hideGUICallback")
    nsmClient.announceGuiVisibility(
        isVisible=False
    )  # Inform NSM that the GUI is now hidden. Put this at the end.


nsmClient = NSMClient(
    prettyName=niceTitle,
    saveCallback=saveCallback,
    openOrNewCallback=openCallback,
    showGUICallback=
    showGUICallback,  # Comment this line out if your program does not have an optional GUI
    hideGUICallback=
    hideGUICallback,  # Comment this line out if your program does not have an optional GUI
    supportsSaveStatus=
    False,  # Change this to True if your program announces it's save status to NSM
    exitProgramCallback=exitProgram,
    loggingLevel=
    "info",  # "info" for development or debugging, "error" for production. default is error.
)

# If NSM did not start up properly the program quits here.

########################################################################
# If your project uses JACK, activate your client here
# You can use jackClientName or create your own
########################################################################
jackClientName = nsmClient.ourClientNameUnderNSM