Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to change the universe on which we listen even when the code is in progress #44

Open
corentindrd opened this issue Oct 18, 2023 · 1 comment

Comments

@corentindrd
Copy link

import time
import tkinter
import rtmidi
import customtkinter
import sacn
import threading
receiver = sacn.sACNreceiver()
receiver.start()

def sacntomidi():
    global channel
    global joinok
    global uni
    while True:
        if activesacn.get() == 1 and joinok == 1 and entryuniverse.get() != "":
            channel = int(entrychannel.get()) - 1
            uni = int(entryuniverse.get())
            receiver.join_multicast(uni)
            joinok = 0
        elif activesacn.get() == 0 and joinok == 0:
            channel = int(entrychannel.get()) - 1
            uni = int(entryuniverse.get())
            receiver.leave_multicast(uni)
            joinok = 1
            pass
        else:
            time.sleep(0.01)
            pass


root = customtkinter.CTk()
customtkinter.set_appearance_mode("System")
root.title("Controle Reaper SACN")

activesacn = customtkinter.IntVar(value=0)
joinok = 1
uni = 1

midiout = rtmidi.MidiOut()
midiout.open_virtual_port("SACN REAPER")

textuniverse = customtkinter.CTkLabel(root, text="Univers", font=("Avenir-Black", 10))
textuniverse.place(relx=0.5, rely=0.2, anchor=tkinter.CENTER)

textchannel = customtkinter.CTkLabel(root, text="Adresse", font=("Avenir-Black", 10))
textchannel.place(relx=0.5, rely=0.5, anchor=tkinter.CENTER)

entryuniverse = customtkinter.CTkEntry(root)
entryuniverse.place(relx=0.5, rely=0.3, anchor=tkinter.CENTER)

entrychannel = customtkinter.CTkEntry(root)
entrychannel.place(relx=0.5, rely=0.6, anchor=tkinter.CENTER)

switchartnet = customtkinter.CTkSwitch(master=root, text="", fg_color="white", variable=activesacn, onvalue="1",
                                       offvalue="0")
switchartnet.place(relx=0.65, rely=0.8, anchor=tkinter.CENTER)

@receiver.listen_on('universe', universe=uni)  # listens on universe 1
def callback(packet):  # packet type: sacn.DataPacket
    if packet.dmxData:  # Vérifiez que la liste n'est pas vide
        print(uni)
        value = packet.dmxData[channel]  # Accédez à la première valeur de la liste
        print(value)
        midiout.send_message([0x90, 60, int(value / 255 * 127)])


th1 = threading.Thread(target=sacntomidi, daemon=True)
th1.start()

root.mainloop()
receiver.stop()
@Hundemeier
Copy link
Owner

I don't know if I understood the question correctly, but the only way I can think of to change the universe of a listener is to unregister the listener and then re-registering the listener.
You should be able to use the remove_listener or remove_listener_from_universe functions even from within your callback and also should be able to register inside the callback.
However, I'm not quite sure how the Python code for that should look like. Maybe something like receiver.listen_on('universe', callback)() works?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants