def dup(self): current_scene = S.obs_scene_from_source( S.obs_frontend_get_current_scene()) scene_item = S.obs_scene_find_source(current_scene, self.source_name) info = S.obs_transform_info() crop = S.obs_sceneitem_crop() S.obs_sceneitem_get_info(scene_item, info) S.obs_sceneitem_get_crop(scene_item, crop) duplicate = S.obs_sceneitem_get_source(scene_item) duplicated = S.obs_source_duplicate(duplicate, "duplicate" + self.source_name, False) scenes = S.obs_frontend_get_scenes() for scene in scenes: name = S.obs_source_get_name(scene) if name == self.scene_name: scene = S.obs_scene_from_source(scene) scene_item2 = S.obs_scene_add(scene, duplicated) S.obs_sceneitem_set_info(scene_item2, info) S.obs_sceneitem_set_crop(scene_item2, crop) S.obs_scene_release(scene) S.obs_source_release(duplicated) S.source_list_release(scenes) S.obs_scene_release(current_scene)
def playsound(filename, volume, speed): obs.script_log(obs.LOG_DEBUG, "Trying to play " + filename + " to source " + sourcename) scenesource = obs.obs_frontend_get_current_scene() scene = obs.obs_scene_from_source(scenesource) #obs.script_log(obs.LOG_DEBUG,"Scene "+str(scene)) sceneitem = obs.obs_scene_find_source(scene, sourcename) #obs.script_log(obs.LOG_DEBUG,"Scene item "+str(sceneitem)) source = obs.obs_sceneitem_get_source(sceneitem) obs.obs_source_set_volume(source, volume) set_source_speed(source, speed) obs.obs_sceneitem_set_visible(sceneitem, False) settings = obs.obs_source_get_settings(source) #obs.script_log(obs.LOG_DEBUG,str(obs.obs_data_get_json(settings))) obs.obs_data_set_string(settings, "local_file", audiofolder + filename) #obs.script_log(obs.LOG_DEBUG,str(obs.obs_data_get_json(settings))) obs.obs_source_update(source, settings) obs.obs_sceneitem_set_visible(sceneitem, True) obs.obs_data_release(settings) obs.obs_source_release(scenesource)
def should_switch_scenes(): current = obs.obs_frontend_get_current_scene() name = obs.obs_source_get_name(current) obs.obs_source_release(current) if name in scene_names and name != scene_names[get_active_monitor()]: return True return False
def startCountClick(props, prop): global itemSource global xCoord global yCoord global Debug_Mode global jsonItemData global imagePath global imageName global widthCount global heightCount if (obs.obs_frontend_preview_program_mode_active()): sceneSource = obs.obs_frontend_get_current_preview_scene() else: sceneSource = obs.obs_frontend_get_current_scene() sceneWidth = obs.obs_source_get_width(sceneSource) sceneHeight = obs.obs_source_get_height(sceneSource) xWidth = math.ceil(sceneWidth / widthCount) yHeight = math.ceil(sceneHeight / heightCount) blankImage = np.zeros(shape=[yHeight, xWidth, 4], dtype=np.uint8) cv2.rectangle(blankImage, (0, 0), (xWidth, yHeight), (169, 169, 169, 255), 2) if (os.path.isfile(imagePath + imageName)): os.remove(imagePath + imageName) cv2.imwrite(imagePath + imageName, blankImage) if Debug_Mode: print("startCount") print(imagePath + imageName) gridWidth = 0 gridHeight = 0 scene = obs.obs_scene_from_source(sceneSource) itemData = obs.obs_data_create_from_json(jsonItemData) itemSource = obs.obs_load_source(itemData) vec2 = obs.vec2() position = 0 if itemSource != None: item = obs.obs_scene_find_source(scene, "OBSWindowGridItem") while item != None: obs.obs_sceneitem_remove(item) item = obs.obs_scene_find_source(scene, "OBSWindowGridItem") vec2.y = 0 while gridHeight < sceneHeight: gridWidth = 0 vec2.x = 0 while gridWidth < sceneWidth: newItem = obs.obs_scene_add(scene, itemSource) obs.obs_sceneitem_set_pos(newItem, vec2) obs.obs_sceneitem_set_locked(newItem, True) obs.obs_sceneitem_set_order_position(newItem, position) position += 1 vec2.x += xWidth gridWidth += xWidth vec2.y += yHeight gridHeight += yHeight
def crete_text_scene_source(panels, menus): "Adds scene with text sources to current scene" current_scene_source = obs.obs_frontend_get_current_scene() with scene_from_source_ar(current_scene_source) as scene_source: with scene_create_ar("_scene") as _scene: py_scene_source = obs.obs_scene_get_source(_scene) with scene_from_source_ar(py_scene_source) as scene: height_ruler = 0 for i in panels: sn, ds = i.source_name, i.description height_ruler += place_row(scene, TextElement(sn, ds), height_ruler) height_ruler += 30 for i in menus: i = i.text_obs_obj sn, ds = i.source_name, i.description height_ruler += place_row(scene, TextElement(sn, ds), height_ruler) # add created scene to current scene ( nested scene) _scene_source = obs.obs_scene_get_source(scene) obs.obs_scene_add(scene_source, _scene_source)
def getCurrentSceneItem(self, itemName): source = obs.obs_frontend_get_current_scene() item = '' scene = obs.obs_scene_from_source(source) item = obs.obs_scene_find_source(scene, itemName) obs.obs_source_release(source) return item
def update_cursor(self): source = obs.obs_get_source_by_name(self.source_name) settings = obs.obs_data_create() if source is not None: scene_source = obs.obs_frontend_get_current_scene() scene_width = obs.obs_source_get_width(source) scene_height = obs.obs_source_get_height(source) scene = obs.obs_scene_from_source(scene_source) scene_item = obs.obs_scene_find_source(scene, self.source_name) if scene_item: scale = obs.vec2() obs.obs_sceneitem_get_scale(scene_item, scale) scene_width, scene_height = apply_scale( scale.x, scale.y, scene_width, scene_height ) next_pos = obs.vec2() next_pos.x, next_pos.y = get_position() next_pos.x -= scene_width / 2 next_pos.y -= scene_height / 2 # set position to center of source where cursor is obs.obs_sceneitem_set_pos(scene_item, next_pos) obs.obs_data_release(settings) obs.obs_scene_release(scene) obs.obs_source_release(source)
def on_frontend_event(event): global TALLY_STATUS if event in (obs.OBS_FRONTEND_EVENT_SCENE_CHANGED, obs.OBS_FRONTEND_EVENT_PREVIEW_SCENE_CHANGED): # Check the status of the tally sources program_source = obs.obs_frontend_get_current_scene() preview_source = obs.obs_frontend_get_current_preview_scene() program_scene = obs.obs_scene_from_source(program_source) preview_scene = obs.obs_scene_from_source(preview_source) try: for source_name in TALLY_STATUS.keys(): color = "000000" source = obs.obs_scene_find_source(preview_scene, source_name) if source: color = "00ff00" source = obs.obs_scene_find_source(program_scene, source_name) if source: color = "ff0000" if TALLY_STATUS[source_name] != color: CLIENT.publish("cmnd/%s/COLOR" % source_name, color) TALLY_STATUS[source_name] = color finally: obs.obs_source_release(program_source) obs.obs_source_release(preview_source)
def handle_program_change(): global program_items program_source = obs.obs_frontend_get_current_scene() program_items = get_item_names_by_scene(program_source) set_lights_by_items(program_items, program_color, program_brightness) obs.obs_source_release(program_source) set_idle_lights()
def get_sceneitem_from_source_name_in_current_scene(name): result_sceneitem = None current_scene_as_source = obs.obs_frontend_get_current_scene() if current_scene_as_source: current_scene = obs.obs_scene_from_source(current_scene_as_source) result_sceneitem = obs.obs_scene_find_source_recursive(current_scene, name) obs.obs_source_release(current_scene_as_source) return result_sceneitem
def switchToTweener(tweenerName): currentCollection = obs.obs_frontend_get_current_scene_collection() currentSceneName = obs.obs_source_get_name( obs.obs_frontend_get_current_scene()) for collection in scriptSettings['configs']: if collection['sceneCollection'] == currentCollection and collection[ 'sceneName'] == currentSceneName: for tweener in collection['tweeners']: if tweener['tweenName'] == tweenerName: srcArray = {} for item in dumpSceneData(): name = item['name'] pos = item['pos'] rot = item['rot'] scale = item['scale'] alignment = item['alignment'] bounds = item['bounds'] boundsType = item['boundsType'] boundsAlignment = item['boundsAlignment'] crop = item['crop'] srcArray[name] = { "pos": pos, "rot": rot, "scale": scale, "alignment": alignment, "bounds": bounds, "boundsType": boundsType, "boundsAlignment": boundsAlignment, "crop": crop } scriptSettings['anim']['src'] = srcArray destArray = {} for item in tweener['tweenItems']: name = item['name'] pos = item['pos'] rot = item['rot'] scale = item['scale'] alignment = item['alignment'] bounds = item['bounds'] boundsType = item['boundsType'] boundsAlignment = item['boundsAlignment'] crop = item['crop'] destArray[name] = { "pos": pos, "rot": rot, "scale": scale, "alignment": alignment, "bounds": bounds, "boundsType": boundsType, "boundsAlignment": boundsAlignment, "crop": crop } scriptSettings['anim']['dest'] = destArray scriptSettings['anim']['time'] = 0 scriptSettings['anim']['length'] = tweener['length'] / 1000 scriptSettings['anim']['tweener'] = tweener scriptSettings['anim']['animating'] = True
def toggle(source): scene = obs.obs_frontend_get_current_scene() sceneitem = obs.obs_scene_find_source(obs.obs_scene_from_source(scene), source) obs.obs_sceneitem_set_visible(sceneitem, not obs.obs_sceneitem_visible(sceneitem)) obs.obs_source_release(scene) obs.obs_source_release(sceneitem)
def frontendGetCurrentScene(): """ Context manager to call obs_frontend_get_current_scene() and release the source when done. """ source = obs.obs_frontend_get_current_scene() yield source if source is not None: obs.obs_source_release(source)
def currentSceneName(): src = obs.obs_frontend_get_current_scene() if src is None: return None name = obs.obs_source_get_name(src) obs.obs_source_release(src) if name is None: return None return name
def deleteGridClick(props, prop): if (obs.obs_frontend_preview_program_mode_active()): sceneSource = obs.obs_frontend_get_current_preview_scene() else: sceneSource = obs.obs_frontend_get_current_scene() scene = obs.obs_scene_from_source(sceneSource) item = obs.obs_scene_find_source(scene, "OBSWindowGridItem") while item: obs.obs_sceneitem_remove(item) item = obs.obs_scene_find_source(scene, "OBSWindowGridItem")
def switch_scenes(): if is_active and should_switch_scenes(): sources = obs.obs_enum_sources() scenes = obs.obs_frontend_get_scenes(sources) obs.source_list_release(sources) current = obs.obs_frontend_get_current_scene() for s in scenes: if s != current and obs.obs_source_get_name(s) in scene_names: obs.obs_frontend_set_current_scene(s) obs.obs_source_release(current)
def change_to_scene(scene_name): scenes = obs.obs_frontend_get_scenes() for scene in scenes: print(obs.obs_source_get_name(scene)) if obs.obs_source_get_name(scene) == scene_name: current_scene = obs.obs_frontend_get_current_scene() scenes.remove(current_scene) obs.obs_frontend_set_current_scene(scene)
def printBaseData(pressedState): if pressedState: sceneCollection = obs.obs_frontend_get_current_scene_collection() sceneName = obs.obs_source_get_name( obs.obs_frontend_get_current_scene()) baseArray = [{ 'sceneCollection': sceneCollection, 'sceneName': sceneName, 'tweeners': [] }] print(json.dumps(baseArray))
def transition(num=-1): trans = None if num >= 0: setTransition(num) trans = obs.obs_frontend_get_current_transition() act = obs.obs_frontend_get_current_scene() mode = obs.OBS_TRANSITION_MODE_AUTO duration = 0 dest = obs.obs_frontend_get_current_preview_scene() obs.obs_transition_start(trans, mode, duration, dest) obs.obs_frontend_set_current_scene(dest) obs.obs_frontend_set_current_preview_scene(act)
def reorder(): current_scene = S.obs_frontend_get_current_scene() with scene_ar(current_scene) as scene: with scene_enum(scene) as scene_items: order = get_order(scene_items) # change second index with pre last order[1]["index"], order[-2]["index"] = ( order[-2]["index"], order[1]["index"], ) for s in sorted(order, key=lambda i: i["index"]): S.obs_sceneitem_set_order_position(s["scene_item"], s["index"])
def update(): current_scene = obs.obs_frontend_get_current_scene() current_scene_name = obs.obs_source_get_name(current_scene) if current_scene_name in scenes: debug_write( f"Currently on target scene. Writing on value ({onvalue}) to COM port." ) write_value(onvalue) else: debug_write( f"Currently on non-target scene. Writing off value ({offvalue}) to COM port." ) write_value(offvalue)
def add_scene_with_sources(): current_scene_source = obs.obs_frontend_get_current_scene() with scene_from_source_ar(current_scene_source) as scene_source: with scene_create_ar("_nested_scene") as _scene: py_scene_source = obs.obs_scene_get_source(_scene) with scene_from_source_ar(py_scene_source) as scene: add_random_text_source(scene) add_random_text_source(scene) add_random_text_source(scene) # add created scene to current scene ( nested scene) _scene_source = obs.obs_scene_get_source(scene) obs.obs_scene_add(scene_source, _scene_source)
def crete_text_source(self): current_scene = obs.obs_frontend_get_current_scene() scene = obs.obs_scene_from_source(current_scene) settings = obs.obs_data_create() obs.obs_data_set_string(settings, "text", "The quick brown fox jumps over the lazy dog") source = obs.obs_source_create_private("text_gdiplus", "test_py", settings) obs.obs_scene_add(scene, source) obs.obs_scene_release(scene) obs.obs_data_release(settings) obs.obs_source_release(source)
def save(*args): currentScene = obs.obs_frontend_get_current_scene() sceneName = obs.obs_source_get_name(currentScene) sceneObject = obs.obs_scene_from_source(currentScene) items = obs.obs_scene_enum_items(sceneObject) transformations = getTransformationList(items) loc = filedialog.asksaveasfilename(filetypes=[("JSON", "*.json")], title="Save Template File", initialfile=sceneName + ".json") f = open(loc, 'w') f.write(json.dumps(transformations)) f.close() #obs.obs_scene_release(sceneObject) obs.obs_source_release(currentScene) return True
def refresh_screen(self): source = obs.obs_frontend_get_current_scene() scene = obs.obs_scene_from_source(source) sceneitem = obs.obs_scene_find_source_recursive(scene, self.source_name) if sceneitem is not None: obs.obs_sceneitem_set_visible(sceneitem, False) if self.debug: print("off") time.sleep(self.blink_speed) obs.obs_sceneitem_set_visible(sceneitem, True) if self.debug: print("on") obs.obs_sceneitem_release(sceneitem) obs.obs_scene_release(scene) obs.obs_source_release(source)
def change_to_scene(bot, message, args): time_to_wait = time.time() - last_scene_change["t"] last_scene_change["t"] = time.time() if time_to_wait < DELAY: message['ttw'] = "{:.1f}".format(time_to_wait) return "CommandToSoon" scene_name = args['scene'] scenes = obs.obs_frontend_get_scenes() for scene in scenes: print(obs.obs_source_get_name(scene)) if obs.obs_source_get_name(scene) == scene_name: current_scene = obs.obs_frontend_get_current_scene() scenes.remove(current_scene) obs.obs_frontend_set_current_scene(scene) return 'Success'
def open_gui(*args): global app global globSettings app.show() currentScene = obs.obs_frontend_get_current_scene() sceneName = obs.obs_source_get_name(currentScene) obs.obs_data_set_string(globSettings, "scene", sceneName) obs.obs_source_release(currentScene) scenes = obs.obs_frontend_get_scene_names() result = [] if scenes is not None: for scene in scenes: result.append(scene) app.scenes = tuple(result) app.scene.set(sceneName) app.update()
def loadConfig(jsonData): for collection in jsonData: if collection[ 'sceneCollection'] == obs.obs_frontend_get_current_scene_collection( ): if collection['sceneName'] == obs.obs_source_get_name( obs.obs_frontend_get_current_scene()): scriptSettings['configs'].append(collection) for tweener in collection['tweeners']: tweenerFunction = createTweenerFunction( tweener['tweenName']) scriptSettings['tweenerFunctions'].append(tweenerFunction) obs.obs_hotkey_register_frontend( tweener['tweenName'], 'Tweener - %s' % (tweener['tweenName']), tweenerFunction)
def setup_source(source_name, height, width): # Get the current scene current_scene = obs.obs_frontend_get_current_scene() scene = obs.obs_scene_from_source(current_scene) obs.obs_source_release(current_scene) # Grab the source source = obs.obs_scene_find_source(scene, source_name) # This makes sure that the scaling is done right obs.obs_sceneitem_set_bounds_type(source, obs.OBS_BOUNDS_SCALE_INNER) # Set the bounding box size new_scale = obs.vec2() new_scale.x = height new_scale.y = width obs.obs_sceneitem_set_bounds(source, new_scale)
def move_text_source(self): current_scene = obs.obs_frontend_get_current_scene() source = obs.obs_get_source_by_name("test_py") scene = obs.obs_scene_from_source(current_scene) scene_item = obs.obs_scene_find_source(scene, "test_py") if scene_item: dx, dy = 10, 10 print("old values", self.location.x) obs.obs_sceneitem_get_pos( scene_item, self.location ) # update to last position if its changed from OBS self.location.x += dx self.location.y += dy print("new values", self.location.x) obs.obs_sceneitem_set_pos(scene_item, self.location) obs.obs_scene_release(scene) obs.obs_source_release(source)