Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- #Default JSON variables
- server_ip = "localhost"
- server_port = 4444
- server_password = "secret"
- ConfigName = "SOS"
- StudioMode = False
- DefaultTransition = "Cut"
- DefaultTransitionDuration = 300
- from obswebsocket import obsws, requests
- import pygame.midi as midi
- import time
- import json
- def Setup():
- global setup_json
- try:
- setup_json = json.loads(''.join(open("setup.json", "r")))
- if "config_general" in setup_json:
- config_general = setup_json["config_general"]
- if "ConfigName" in config_general:
- global ConfigName
- ConfigName = config_general["ConfigName"]
- else:
- print("ERROR 404: ConfigName argument was not found")
- if "StudioMode" in config_general:
- global StudioMode
- StudioMode = config_general["StudioMode"]
- else:
- print("ERROR 404: StudioMode argument was not found")
- if "DefaultTransition" in config_general:
- global DefaultTransition
- DefaultTransition = config_general["DefaultTransition"]
- else:
- print("ERROR 404: DefaultTransition argument was not found")
- if "DefaultTransitionDuration" in config_general:
- global DefaultTransitionDuration
- DefaultTransitionDuration = config_general["DefaultTransitionDuration"]
- else:
- print("ERROR 404: DefaultTransitionDuration argument was not found")
- if "server_ip" in config_general:
- global server_ip
- server_ip = config_general["server_ip"]
- else:
- print("ERROR 404: server_ip argument was not found")
- if "server_port" in config_general:
- global server_port
- server_port = config_general["server_port"]
- else:
- print("ERROR 404: server_port argument as not found")
- if "server_password" in config_general:
- global server_password
- server_password = config_general["server_password"]
- else:
- print("ERROR 404 server_password argument was not found")
- else:
- print("No general config in config file")
- except FileNotFoundError:
- print("Config file not found")
- global ws
- try:
- ws = obsws(server_ip, server_port, server_password)
- ws.connect()
- except:
- print("Connection to OBS Websocket is impossible")
- print("Exiting program")
- exit()
- global midi_in
- try:
- midi.init()
- midi_in = midi.Input(1, 1024)
- except:
- print("Chaque année, des millions de programmeurs disent qu'ils vont régler ce problème, et ils ne le font jamais. Si vous voyez ce message, c'et que nous faisons parti de ces programmeurs.")
- print("Exiting program")
- exit()
- def CheckStudioState():
- StudioState = False
- try:
- StudioState = ws.call(requests.GetStudioModeStatus())
- StudioState = StudioState.getStudioMode()
- print("Studiostate:" + str(StudioState))
- except:
- print("Couldn't get StudioModeStatus")
- def press_button(Button, Event):
- Action = None
- if "config_pad" in setup_json:
- if "Buttons" in setup_json["config_pad"]:
- if Button in setup_json["config_pad"]["Buttons"]:
- BUTTONCONF = setup_json["config_pad"]["Buttons"][Button]
- if "Event" in BUTTONCONF:
- if (BUTTONCONF["Event"] == "OnRelease" and Event == 138) or (BUTTONCONF["Event"] == "OnPress" and Event == 154):
- if "Action" in BUTTONCONF:
- Action = BUTTONCONF["Action"]
- else:
- print("No Action argument in Button config")
- else:
- print("No Event argument in Button config")
- else:
- print("Button not found")
- else:
- print("No Button argument in config_pad argument")
- else:
- print("No config_pad argument in config")
- if Action == "SwitchScene":
- StudioState = False
- try:
- StudioState = ws.call(requests.GetStudioModeStatus())
- StudioState = StudioState.getStudioMode()
- print("Studiostate:" + str(StudioState))
- except:
- print("Couldn't get StudioModeStatus")
- if StudioState == True:
- try:
- ws.call(requests.SetPreviewScene(BUTTONCONF["DestinationScene"]))
- print("Set Target to preview")
- except:
- print(f"Couldn't set Target to preview")
- else:
- try:
- ws.call(requests.SetCurrentTransition(BUTTONCONF["Transition"]))
- ws.call(requests.SetCurrentScene(BUTTONCONF["DestinationScene"]))
- print("Set Target to program")
- except:
- print(f"Couldn't set Target to program")
- if Action == "TransitionToProgram":
- StudioState = False
- try:
- StudioState = ws.call(requests.GetStudioModeStatus())
- StudioState = StudioState.getStudioMode()
- print("Studiostate:" + str(StudioState))
- except:
- print("Couldn't get StudioModeStatus")
- if StudioState == True:
- try:
- CurrentsceneObject = ws.call(requests.GetPreviewScene())
- Currentscene = CurrentsceneObject.getName()
- # ws.call(requests.SetCurrentTransition("Fade"))
- ws.call(requests.SetCurrentScene(Currentscene))
- print("Sent preview to program")
- except:
- print("Couldn't send preview to program")
- else:
- print("StudioMode not enabled")
- Setup()
- while True:
- while midi_in.poll():
- midi_read = midi_in.read(1)
- # print(midi_read)
- if midi_read[0][0][0] == 154:
- press_button(str(midi_read[0][0][1]), 154)
- time.sleep(0.01)
- -----------------------------------------------------------------------------------------------------------------------------------
- {
- "config_general" : {
- "ConfigName": "Cafe Kawa",
- "StudioMode": "True",
- "DefaultTransition" : "Cut",
- "DefaultTransitionDuration" : 300,
- "server_ip" : "localhost",
- "server_port" : 4444,
- "server_password" : "banana"
- },
- "config_pad" : {
- "Buttons" : {
- "8":{
- "Event" : "OnPress",
- "Action" : "SwitchScene",
- "DestinationScene" : "Scene 1",
- "Transition" : "Fade",
- "TransitionDuration" : 300
- },
- "16":{
- "Action" : "SetTransition",
- "Transition" : "Fade",
- "TransitionDuration": 300
- },
- "15":{
- "Action" : "TransitionToProgram",
- "Transition" : "Cut"
- }
- },
- "Fader" : {
- "1":{
- "Action" : "SetTransitionDuration",
- "MaxValue" : 500,
- "MinValue": 300
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement