Exemplo n.º 1
0
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)
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
 def prepareForSfx(self):
     """
     Stop all playing sound effects, so that one can be played soon.
     """
     for sourceName in [
             self.ding1SourceName, self.ding10SourceName,
             self.ding50SourceName
     ]:
         for item in self.iterSceneItemsByName(sourceName):
             obs.obs_sceneitem_set_visible(item, False)
Exemplo n.º 4
0
def on_visibility_toggle(calldata):
    scenes_as_sources = obs.obs_frontend_get_scenes()
    sceneitem = obs.calldata_sceneitem(calldata, "item")
    visibility = obs.calldata_bool(calldata, "visible")
    name = obs.obs_source_get_name(obs.obs_sceneitem_get_source(sceneitem))
    for scene_as_source in scenes_as_sources:
        scene = obs.obs_scene_from_source(scene_as_source)
        match = obs.obs_scene_find_source(scene, name)
        if match:
            obs.obs_sceneitem_set_visible(match, visibility)
    obs.source_list_release(scenes_as_sources)
Exemplo n.º 5
0
    def set_visible_all(self, visible):
        """Cycle through all scenes, manually toggling visibility of the source

        Idea from GitHub user LukyLurks
        """
        scenes = obs.obs_frontend_get_scenes()
        for scene in scenes:
            scene_test = obs.obs_scene_from_source(scene)
            in_scene = obs.obs_scene_find_source(scene_test, self.source_name)
            if in_scene:
                obs.obs_sceneitem_set_visible(in_scene, visible)
        obs.source_list_release(scenes)
Exemplo n.º 6
0
 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)
Exemplo n.º 7
0
def hidesource():
    #obs.script_log(obs.LOG_DEBUG,"Trying to hide source "+sourcename)

    frontendscenes = obs.obs_frontend_get_scenes()
    #obs.script_log(obs.LOG_DEBUG,str(frontendscenes))

    for scenesource in frontendscenes:
        #obs.script_log(obs.LOG_DEBUG,str(scenesource))

        #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)
        if sceneitem:
            #obs.script_log(obs.LOG_DEBUG,"Scene item "+str(sceneitem))

            obs.obs_sceneitem_set_visible(sceneitem, False)

        #obs.obs_source_release(scenesource)
    obs.source_list_release(frontendscenes)
Exemplo n.º 8
0
def toggle_zoom_follow(pressed):
    if pressed:

        if zoom.source_name != "" and zoom.flag:
            zoom.first_Zoom = True
            print('Activating...')

            config = obs.obs_frontend_get_profile_config()
            #print(obs.config_get_string(config, "RecFilePath"))

            zoom.fullscreenTransform('zoom')

            zoom.update_monitor_size()
            obs.timer_add(zoom.tick, zoom.refresh_rate)
            zoom.lock = True
            zoom.flag = False
            zoom.frozen = False

            camera_item = zoom.getCurrentSceneItem('Camera - Circle')
            if obs.obs_sceneitem_visible(camera_item):
                obs.obs_sceneitem_set_visible(camera_item, False)

            camera_item = zoom.getCurrentSceneItem('Camera - Circle - Small')
            if not obs.obs_sceneitem_visible(camera_item):
                obs.obs_sceneitem_set_visible(camera_item, True)

        elif not zoom.flag:
            print('Deactivating...')

            zoom.fullscreenTransform('unzoom')

            zoom.flag = True
            zoom.lock = False
            zoom.frozen = False

            camera_item = zoom.getCurrentSceneItem('Camera - Circle')
            if not obs.obs_sceneitem_visible(camera_item):
                obs.obs_sceneitem_set_visible(camera_item, True)

            camera_item = zoom.getCurrentSceneItem('Camera - Circle - Small')
            if obs.obs_sceneitem_visible(camera_item):
                obs.obs_sceneitem_set_visible(camera_item, False)
Exemplo n.º 9
0
 def toggle(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)
     boolean = not S.obs_sceneitem_visible(scene_item)
     S.obs_sceneitem_set_visible(scene_item, boolean)
     S.obs_scene_release(current_scene)
Exemplo n.º 10
0
def visibility_source(source_name, hide):
    current_scene = obs.obs_scene_from_source(
        obs.obs_frontend_get_current_scene())
    scene_item = obs.obs_scene_find_source(current_scene, source_name)
    if scene_item is not None:
        obs.obs_sceneitem_set_visible(scene_item, hide)
Exemplo n.º 11
0
def toggle(Visible):
    goal_item = get_scene_item('Goal')
    obs.obs_sceneitem_set_visible(goal_item, Visible)
Exemplo n.º 12
0
def set_visibility(val):
	scene = get_scene()
	#source = obs.obs_get_source_by_name(image_source_name)
	source = obs.obs_scene_find_source(scene, image_source_name)
	obs.obs_sceneitem_set_visible(source, val)
Exemplo n.º 13
0
def script_tick(seconds):  # OBS script interface.
    global discord_source

    source_name = obs.obs_data_get_string(settings, 'discord_source')
    if source_name != obs.obs_source_get_name(discord_source):
        obs.obs_source_release(
            discord_source)  # Doesn’t error even if discord_source == None.
        discord_source = obs.obs_get_source_by_name(source_name)

    if not client:
        return

    # NOTE: These are 0 when the source isn’t visible at all in the current scene. Not that it matters, but I was just weirded out by it until I got it.
    source_width = obs.obs_source_get_width(discord_source)
    source_height = obs.obs_source_get_height(discord_source)

    margin_top = MARGIN_TOP
    if not obs.obs_data_get_bool(settings, 'full_screen'):
        margin_top = margin_top + TITLE_BAR

    # Get Discord call layout distribution and caller size.
    people = [x for x in client.video]  # Mutability and shiz.
    nonvideo = obs.obs_data_get_bool(settings, 'show_nonvideo_participants')
    if nonvideo:
        people += client.audio
    count = len(people)
    if count == 1 and (not client.audio or not client.video and nonvideo):
        count = 2  # Discord adds a call to action that occupies the same space as a second caller.
    rows = None
    cols = None
    width = 0
    height = None
    offsetx = 0
    offsety = 0
    offset_last = None
    if source_width and source_height:
        totalw = source_width - MARGIN_SIDES * 2
        totalh = source_height - margin_top - MARGIN_BTM
        if totalw > 0 and totalh > 0:
            wide = None
            # Discord packs the callers in as many columns as possible, unless their videos appear bigger with fewer columns.
            for c in reversed(range(1, count + 1)):
                r = math.ceil(count / c)
                w = (totalw - CALLER_SPACING * (c - 1)) / c
                h = (totalh - CALLER_SPACING * (r - 1)) / r
                wi = w / h > CALLER_ASPECT
                if wi:
                    w = h * CALLER_ASPECT
                if w > width:
                    rows = r
                    cols = c
                    width = w
                    height = h
                    wide = wi
            if rows:
                # If the window is wider or taller than the callers fit in, Discord will center them as a whole.
                inner_width = (width * cols + CALLER_SPACING * (cols - 1))
                if wide:  # Wider than needed, therefore center horizontally.
                    offsetx = (totalw - inner_width) / 2
                else:  # Taller than needed, therefore center vertically.
                    height = width / CALLER_ASPECT  # We compared using widths only before, so height needs to be adjusted.
                    offsety = (totalh - (height * rows + CALLER_SPACING *
                                         (rows - 1))) / 2

                # If last row contains fewer callers than columns, Discord will center it.
                offset_last = count % cols
                if offset_last > 0:
                    offset_last = (inner_width -
                                   (width * offset_last + CALLER_SPACING *
                                    (offset_last - 1))) / 2

    # Apply necessary changes to relevant scene items.
    scene_sources = obs.obs_frontend_get_scenes()
    for scene_src in scene_sources:
        scene = obs.obs_scene_from_source(scene_src)  # Shouldn’t be released.
        items = obs.obs_scene_enum_items(scene)
        i = 0
        next_vis = None
        for item in reversed(items):
            _next_vis = None
            if obs.obs_sceneitem_get_source(
                    item) == discord_source:  # Shouldn’t be released.
                uid = int(
                    obs.obs_data_get_string(settings, f'participant{i}') or -1)
                visible = True
                try:
                    index = people.index(uid)
                except (IndexError, ValueError):
                    visible = False
                i += 1
                obs.obs_sceneitem_set_visible(item, visible)
                if visible and rows:
                    crop = obs.obs_sceneitem_crop()
                    obs.obs_sceneitem_get_crop(item, crop)
                    scale = obs.vec2()
                    obs.obs_sceneitem_get_scale(item, scale)
                    bounds = obs.vec2()
                    obs.obs_sceneitem_get_bounds(item, bounds)

                    # If item was set to not use a bounding box policy, calculate it from its other transform properties.
                    if obs.obs_sceneitem_get_bounds_type(
                            item) == obs.OBS_BOUNDS_NONE:
                        obs.vec2_set(
                            bounds,
                            scale.x * (source_width - crop.right - crop.left),
                            scale.y * (source_height - crop.bottom - crop.top))
                        obs.obs_sceneitem_set_bounds(item, bounds)

                    obs.obs_sceneitem_set_bounds_type(
                        item, obs.OBS_BOUNDS_SCALE_OUTER)
                    obs.obs_sceneitem_set_bounds_alignment(
                        item, 0
                    )  # obs.OBS_ALIGN_CENTER doesn’t seem to be implemented.

                    # Get top left corner of this caller.
                    r = math.ceil((index + 1) / cols)
                    c = index % cols + 1
                    x = MARGIN_SIDES + offsetx + (width +
                                                  CALLER_SPACING) * (c - 1)
                    if r == rows:
                        x = x + offset_last
                    y = margin_top + offsety + (height + CALLER_SPACING) * (r -
                                                                            1)

                    # Make sure the crop doesn’t overflow the item bounds.
                    aspect = bounds.x / bounds.y
                    clipx = 0
                    clipy = 0
                    if aspect > CALLER_ASPECT:
                        clipy = (height - width / aspect) / 2
                    else:
                        clipx = (width - height * aspect) / 2

                    crop.left = math.ceil(x + CALLER_BORDER + clipx)
                    crop.top = math.ceil(y + CALLER_BORDER + clipy)
                    crop.right = source_width - int(x + width - CALLER_BORDER -
                                                    clipx)
                    crop.bottom = source_height - int(y + height -
                                                      CALLER_BORDER - clipy)
                    obs.obs_sceneitem_set_crop(item, crop)

                    sx = abs(scale.x)
                    if uid == int(
                            obs.obs_data_get_string(settings, 'myself')
                            or -1) and uid in client.video:
                        sx = -sx
                    sy = scale.y
                    obs.vec2_set(scale, sx, sy)
                    obs.obs_sceneitem_set_scale(item, scale)
                if not nonvideo and obs.obs_data_get_bool(
                        settings, 'item_right_below'):
                    _next_vis = uid in client.audio
            elif next_vis is not None:
                obs.obs_sceneitem_set_visible(item, next_vis)
            next_vis = _next_vis
        obs.sceneitem_list_release(items)
    obs.source_list_release(scene_sources)
Exemplo n.º 14
0
 def playSFX(self, sourceName):
     """
     Play the sound effect with the given source name.
     """
     for item in self.iterSceneItemsByName(sourceName):
         obs.obs_sceneitem_set_visible(item, True)