# Path: vocto/transitions.py
# V = 2  # distance (velocity) index
# class Transitions:
# class Transition:
#     def __init__(self, targets=[], fps=25):
#     def __str__(self):
#     def __len__(self):
#     def count(self):
#     def add(self,transition,frames):
#     def configure(cfg, composites, targets=None, fps=25):
#         def index(composite):
#     def solve(self, begin, end, flip):
#     def travel(composites, previous=None):
#     def __init__(self, name, a=None, b=None):
#     def __str__(self):
#         def hidden( x, hidden ):
#     def phi(self):
#     def name(self):
#     def append(self, composite):
#     def frames(self): return len(self.composites)
#     def A(self, n=None):
#     def B(self, n=None):
#     def Az(self, z0, z1):
#     def Bz(self, z0, z1):
#     def begin(self): return self.composites[0]
#     def end(self): return self.composites[-1]
#     def reversed(self):
#     def swapped(self):
#     def calculate_flip(self):
#             def overlap(a, b):
#     def calculate(self, frames, a_corner=(R, T), b_corner=(L, T)):
#     def keys(self):
# def parse_asterisk(sequence, composites):
# def frange(x, y, jump):
# def bspline(points):
# def find_nearest(spline, points):
# def measure(points):
# def smooth(x):
# def distribute(points, positions, begin, end, x0, x1, n):
# def fade(begin, end, factor):
# def morph(begin, end, pt, corner, factor):
# def interpolate(key_frames, num_frames, corner):
# def is_in(sequence, part):
# def fade_alpha(frame,alpha,frames):
# 
# Path: vocto/composite_commands.py
# class CompositeCommand:
# 
#     def __init__(self, composite, A, B):
#         self.composite = composite
#         self.A = A
#         self.B = B
# 
#     def from_str(command):
#         A = None
#         B = None
#         # match case: c(A,B)
#         r = re.match(
#             r'^\s*([|+-]?\w[-_\w]*)\s*\(\s*([-_\w*]+)\s*,\s*([-_\w*]+)\)\s*$', command)
#         if r:
#             A = r.group(2)
#             B = r.group(3)
#         else:
#             # match case: c(A)
#             r = re.match(r'^\s*([|+-]?\w[-_\w]*)\s*\(\s*([-_\w*]+)\s*\)\s*$', command)
#             if r:
#                 A = r.group(2)
#             else:
#                 # match case: c
#                 r = re.match(r'^\s*([|+-]?\w[-_\w]*)\s*$', command)
#                 assert r
#         composite = r.group(1)
#         if composite == '*':
#             composite = None
#         if A == '*':
#             A = None
#         if B == '*':
#             B = None
#         return CompositeCommand(composite,A,B)
# 
#     def modify(self, mod, reverse=False):
#         # get command as string and process all replactions
#         command = original = str(self)
#         for r in mod.split(','):
#             what, _with = r.split('->')
#             if reverse:
#                 what, _with = _with, what
#             command = command.replace(what.strip(), _with.strip())
#         modified = original != command
#         # re-convert string to command and take the elements
#         command = CompositeCommand.from_str(command)
#         self.composite = command.composite
#         self.A = command.A
#         self.B = command.B
#         return modified
# 
#     def unmodify(self, mod):
#         return self.modify(mod, True)
# 
#     def __str__(self):
#         return "%s(%s,%s)" % (self.composite if self.composite else "*",
#                                self.A if self.A else "*",
#                                self.B if self.B else "*")
# 
#     def __eq__(self, other):
#         return ((self.composite == other.composite or not(self.composite and other.composite))
#                 and (self.A == other.A or not(self.A and other.A))
#                 and (self.B == other.B or not(self.B and other.B)))


import logging
import gi
from configparser import NoOptionError
from enum import Enum, unique
from gi.repository import Gst
from lib.config import Config
from vocto.transitions import Composites, Transitions, Frame, fade_alpha
from lib.scene import Scene
from lib.overlay import Overlay
from lib.args import Args
from vocto.composite_commands import CompositeCommand
                    # apply new scene (hard cut)
                    self.log.debug(
                        "setting new background to scene")
                    # just switch to new background
                    bgFrame = Frame(True, zorder=0, rect=[0,0,*Config.getVideoResolution()])
                    self.bgScene.set(newBgSource, bgFrame)
                # make all other background sources invisible
                for source in self.bgSources:
                    if source not in [curBgSource,newBgSource]:
                        self.log.debug("making background source %s invisible", source)
                        self.bgScene.set(source, Frame(True, alpha=0, zorder=-1))
        else:
            # report unknown elements of the target scene
            if not newComposite:
                self.log.error("Unknown composite '%s'", newCompositeName)
            if not newA in self.sources:
                self.log.error("Unknown source '%s'", newA)
            if not newB in self.sources:
                self.log.error("Unknown source '%s'", newB)

        # remember scene we've set
        self.compositeMode = newComposite.name
        self.sourceA = newA
        self.sourceB = newB

    def setComposite(self, command, useTransitions=False):
        ''' parse switch to the composite described by string command '''
        # expect string as parameter
        assert type(command) == str
        # parse command

# Path: vocto/transitions.py
# V = 2  # distance (velocity) index
# class Transitions:
# class Transition:
#     def __init__(self, targets=[], fps=25):
#     def __str__(self):
#     def __len__(self):
#     def count(self):
#     def add(self,transition,frames):
#     def configure(cfg, composites, targets=None, fps=25):
#         def index(composite):
#     def solve(self, begin, end, flip):
#     def travel(composites, previous=None):
#     def __init__(self, name, a=None, b=None):
#     def __str__(self):
#         def hidden( x, hidden ):
#     def phi(self):
#     def name(self):
#     def append(self, composite):
#     def frames(self): return len(self.composites)
#     def A(self, n=None):
#     def B(self, n=None):
#     def Az(self, z0, z1):
#     def Bz(self, z0, z1):
#     def begin(self): return self.composites[0]
#     def end(self): return self.composites[-1]
#     def reversed(self):
#     def swapped(self):
#     def calculate_flip(self):
#             def overlap(a, b):
#     def calculate(self, frames, a_corner=(R, T), b_corner=(L, T)):
#     def keys(self):
# def parse_asterisk(sequence, composites):
# def frange(x, y, jump):
# def bspline(points):
# def find_nearest(spline, points):
# def measure(points):
# def smooth(x):
# def distribute(points, positions, begin, end, x0, x1, n):
# def fade(begin, end, factor):
# def morph(begin, end, pt, corner, factor):
# def interpolate(key_frames, num_frames, corner):
# def is_in(sequence, part):
# def fade_alpha(frame,alpha,frames):
# 
# Path: vocto/composite_commands.py
# class CompositeCommand:
# 
#     def __init__(self, composite, A, B):
#         self.composite = composite
#         self.A = A
#         self.B = B
# 
#     def from_str(command):
#         A = None
#         B = None
#         # match case: c(A,B)
#         r = re.match(
#             r'^\s*([|+-]?\w[-_\w]*)\s*\(\s*([-_\w*]+)\s*,\s*([-_\w*]+)\)\s*$', command)
#         if r:
#             A = r.group(2)
#             B = r.group(3)
#         else:
#             # match case: c(A)
#             r = re.match(r'^\s*([|+-]?\w[-_\w]*)\s*\(\s*([-_\w*]+)\s*\)\s*$', command)
#             if r:
#                 A = r.group(2)
#             else:
#                 # match case: c
#                 r = re.match(r'^\s*([|+-]?\w[-_\w]*)\s*$', command)
#                 assert r
#         composite = r.group(1)
#         if composite == '*':
#             composite = None
#         if A == '*':
#             A = None
#         if B == '*':
#             B = None
#         return CompositeCommand(composite,A,B)
# 
#     def modify(self, mod, reverse=False):
#         # get command as string and process all replactions
#         command = original = str(self)
#         for r in mod.split(','):
#             what, _with = r.split('->')
#             if reverse:
#                 what, _with = _with, what
#             command = command.replace(what.strip(), _with.strip())
#         modified = original != command
#         # re-convert string to command and take the elements
#         command = CompositeCommand.from_str(command)
#         self.composite = command.composite
#         self.A = command.A
#         self.B = command.B
#         return modified
# 
#     def unmodify(self, mod):
#         return self.modify(mod, True)
# 
#     def __str__(self):
#         return "%s(%s,%s)" % (self.composite if self.composite else "*",
#                                self.A if self.A else "*",
#                                self.B if self.B else "*")
# 
#     def __eq__(self, other):
#         return ((self.composite == other.composite or not(self.composite and other.composite))
#                 and (self.A == other.A or not(self.A and other.A))
#                 and (self.B == other.B or not(self.B and other.B)))


# Path: voctocore/lib/videomix.py
import logging
import gi
from configparser import NoOptionError
from enum import Enum, unique
from gi.repository import Gst
from lib.config import Config
from vocto.transitions import Composites, Transitions, Frame, fade_alpha
from lib.scene import Scene
from lib.overlay import Overlay
from lib.args import Args
from vocto.composite_commands import CompositeCommand

                    # apply new scene (hard cut)
                    self.log.debug(
                        "setting new background to scene")
                    # just switch to new background
                    bgFrame = Frame(True, zorder=0, rect=[0,0,*Config.getVideoResolution()])
                    self.bgScene.set(newBgSource, bgFrame)
                # make all other background sources invisible
                for source in self.bgSources:
                    if source not in [curBgSource,newBgSource]:
                        self.log.debug("making background source %s invisible", source)
                        self.bgScene.set(source, Frame(True, alpha=0, zorder=-1))
        else:
            # report unknown elements of the target scene
            if not newComposite:
                self.log.error("Unknown composite '%s'", newCompositeName)
            if not newA in self.sources:
                self.log.error("Unknown source '%s'", newA)
            if not newB in self.sources:
                self.log.error("Unknown source '%s'", newB)

        # remember scene we've set
        self.compositeMode = newComposite.name
        self.sourceA = newA
        self.sourceB = newB

    def setComposite(self, command, useTransitions=False):
        ''' parse switch to the composite described by string command '''
        # expect string as parameter
        assert type(command) == str
        # parse command

        command = CompositeCommand.from_str(command)