Esempio n. 1
0
def init(lokumBorg=None):

    def calibjoy(val):
        if 0.49<val<0.51: return False
        return 10*(val-0.5)

    def joysx1(*msg):
        global X
        x = calibjoy(float(msg[2][0]))
        if x: X+= -x

    def joysy1(*msg):
        global Y
        y = calibjoy(float(msg[2][0]))
        if y: Y+= y

    def joysx2(*msg):
        global W
        w = calibjoy(float(msg[2][0]))
        if w: W+= -w

    def joysy2(*msg):
        global H
        h = calibjoy(float(msg[2][0]))
        if h: H+= h

    def joysb2(*msg):
        print 'joy but2'

    def focus(*msg):
        if msg[2][0]=='borg':
            window.activate()
            window.switch_to()
            window.minimize()
            window.maximize()
            window.set_visible(False)
            window.set_visible(True)

        if msg[2][0]=='max':
            import appscript
            appscript.app('MaxMSP Runtime').activate()

    def dimensions(*msg):
        if msg[2][0]=='/width':
            global W
            #W = int(msg[2][1])
            window.width = W
        if msg[2][0]=='/height':
            global H
            #H = int(msg[2][1])
            window.height = H
        if msg[2][0]=='/x':
            global X,Y
            X = int(msg[2][1])
            window.set_location(X,Y)
        if msg[2][0]=='/y':
            global Y,X
            window.set_location(X,Y)
            Y = int(msg[2][1])
            
    def keyb(*msg):
        global keyboard
        if msg[2][0]=='french' and keyboard!='french':
            os.system('osascript /data/git/lokum/borg/keyb_french.scpt &')
            keyboard = msg[2][0]
            print keyboard
            lokumBorg.langue = 'french'

        if msg[2][0]=='turk' and keyboard!='turk':
            os.system('osascript /data/git/lokum/borg/keyb_turk.scpt &')
            keyboard = msg[2][0]
            print keyboard
            lokumBorg.langue = 'turk'

    r = vsosc.Receiver('127.0.0.1', 9005)
    r.init()
    r.bind('/joy/x1', joysx1)
    r.bind('/joy/y1', joysy1)
    r.bind('/joy/x2', joysx2)
    r.bind('/joy/y2', joysy2)
    r.bind('/joy/b2', joysb2)
    r.bind('/focus', focus)
    r.bind('/dimensions', dimensions)

    rpd = vsosc.Receiver('127.0.0.1', 9006)
    rpd.init()
    rpd.bind('/keyb', keyb)

    global W,H,X,Y
    default_system = None
    platform = pyglet.window.get_platform() 
    display = platform.get_default_display() 
    

    # Attention W,et y sont lies
    W = 600
    H = 200
    X = 20
    Y = 30



    window = pyglet.window.Window(width=W, height=H, caption ="borg", resizable=True)
    window.set_location(X,Y)

    if 0:
        # window = pyglet.window.Window(width=W, height=H)
        # window = pyglet.window.Window(width=W, height=H, style=pyglet.window.Window.WINDOW_STYLE_BORDERLESS)
        window = pyglet.window.Window(width=W, height=H)
        window.set_location(X,Y)


        window = pyglet.window.Window(width=1024, height=768, style=pyglet.window.Window.WINDOW_STYLE_BORDERLESS)
        window.set_location(1440,0)
        #window.set_location(200,0)

    # window.set_exclusive_mouse()
    # window.set_exclusive_keyboard()
    window.clear()

    # CONSOLE
    #console = Console(x=X, y=Y,width=W, height=H, window=window, style=Borgstyle['borg'])
    console = Console(x=X, y=Y, window=window, style=Borgstyle['borg'])
    console.prompt(" ")
    window.push_handlers(console) # focus handles to console...
    
    @window.event
    def on_draw():
        global X,Y,W,H

        if 1:
            console.borg_move(X,Y)
            console.borg_resize(W-20,H-40)

        glEnable(GL_BLEND)
        glShadeModel(GL_SMOOTH)
        glBlendFunc(GL_SRC_ALPHA,GL_ONE)
        glDisable(GL_DEPTH_TEST)
        
        glClearColor(0,0,0,1)
        # glClearColor(0.1,0.1,1,1)
        window.clear()
        glLoadIdentity()
        if default_system:
            default_system.draw()

        console.draw()
                
#    @window.event
    def on_resize(width, height):
       print width, height 
       # console.resize(width,height)

#    @window.event
    def on_mouse_motion(x, y, dx, dy):
        global X,Y,W,H,MOUSE
        if MOUSE:
            print x,y
            console.borg_move(x,y)
            X=x;Y=y

#    @window.event
    def on_mouse_drag(x, y, dx, dy, buttons, modifiers):
        global W,H,MOUSE
        if MOUSE:
            W+=dx
            H+=dy
            console.borg_resize(W,H)

    @console.event
    def on_command(command):
        global ANS,NBSEC
        if lokumBorg:
            ANS, dursec = lokumBorg.reply(command)

            # ---------------- save borg answers
            if ANS: lokumBorg.save_line(ANS.strip())

            ANS = list(ANS)
            ANS.reverse()
            if dursec!=0:
                nblettres = len(ANS)
                NBSEC = float(dursec)/nblettres
                # set color for the borg
                console.write ('\n',attributes={'color': (255, 0, 0, 255)})
                clock.schedule_interval(callborg, NBSEC)
        
        # window.set_location(random.randrange(200,2000),0)
        # window.set_size(random.randrange(200,2000),300)

    def callborg(dt):
        global ANS, NBSEC
        if ANS:
            c = ANS.pop()
            console.write(c)
            console._caret.position = len(console._document.text)

        elif ANS==[]:
            console.write (' ',attributes={'color': (255, 255, 255, 255)})
            console.write ('\n')
            console.prompt()
            #console._document.delete_text(0, len(console._document.text)-1)
            #console._prompt_end = 0
            ANS = None
            clock.unschedule(callborg)
        else: ANS=None

    if fx:
        default_system = fx.init(window)

    if default_system:
        default_system.run_ahead(2, 30)

    pyglet.app.run()
    r.quit() # quit vsosc
    rpd.quit() # quit vsosc
Esempio n. 2
0
def init(lokumBorg=None):

    def joysx1(*msg):
        global X,Y
        x = float(msg[2][0])
        videos['x']+= -10*(x-0.5)
    def joysy1(*msg):
        global X,Y
        y = float(msg[2][0])
        videos['y']+= 10*(y-0.5)
    def joysx2(*msg):
        global videos
        x = float(msg[2][0])
        videos['w']+= -10*(x-0.5)
    def joysy2(*msg):
        global videos
        y = float(msg[2][0])
        videos['h']+= 10*(y-0.5)
    def joysb2(*msg):
        global player
        if 0:
            import glob, random
            path = "/data/lokum_data/video/lokum/"
            files = glob.glob(path+'/*.dv')
            f = random.choice(files)
            #player.pause
            #player = None
            print f
            source2 = pyglet.media.load(f,streaming=True)
            print f
            player3 = pyglet.media.Player()
            player3.queue(source)
            player3.play()
            player.pause()
            player.next()
            print f

    def focus(*msg):
        if msg[2][0]=='borg':
            window.activate()
            window.switch_to()
            window.minimize()
            window.maximize()
            window.set_visible(False)
            window.set_visible(True)
        if msg[2][0]=='max':
            import appscript
            appscript.app('MaxMSP Runtime').activate()

    r = vsosc.Receiver('127.0.0.1', 9005)
    r.init()
    r.bind('/joy/x1', joysx1)
    r.bind('/joy/y1', joysy1)
    r.bind('/joy/x2', joysx2)
    r.bind('/joy/y2', joysy2)
    r.bind('/joy/b2', joysb2)

    r.bind('/focus', focus)

    global W,H,X,Y,videos
    default_system = None

    platform = pyglet.window.get_platform() 
    display = platform.get_default_display() 
    
    W = 300
    H = 200
    X = 0
    Y = 0
    screens = display.get_screens() 
    # window = pyglet.window.Window(fullscreen=True, screen=screens[1])
    # window = pyglet.window.Window(width=800, height=500, resizable=True)
    if 0:
        window = pyglet.window.Window(width=800, height=500, style=pyglet.window.Window.WINDOW_STYLE_BORDERLESS)
    else:
        window = pyglet.window.Window(width=1024, height=768, style=pyglet.window.Window.WINDOW_STYLE_BORDERLESS)
        window.set_location(1440,0)

    # window.set_exclusive_mouse()
    # window.set_exclusive_keyboard()
    # window = pyglet.window.Window(resizable=True, visible=False)
    window.clear()

    # CONSOLE
    console = Console(x=X, y=Y,width=W, height=H, window=window, style=Borgstyle['test'])
    console.prompt(" ")
    window.push_handlers(console)
    
    @window.event
    def on_draw():
        global X,Y
        glEnable(GL_BLEND)
        glShadeModel(GL_SMOOTH)
        glBlendFunc(GL_SRC_ALPHA,GL_ONE)
        glDisable(GL_DEPTH_TEST)
        
        glClearColor(0,0,0,1)
        # glClearColor(1,0,0,1)
        window.clear()
        glLoadIdentity()
        if default_system:
            default_system.draw()


        if 0:
            for p in players:
                player.get_texture().blit(rr(), rr(),width=rr(),height=rr())

        if player:
            if player.get_texture():
                player.get_texture().blit(videos['x'], videos['y'],width=videos['w'],height=videos['h'])
        console.draw()
                
    @window.event
    def on_resize(width, height):
        # console.resize(width,height)
        pass

    @window.event
    def on_mouse_motion(x, y, dx, dy):
        global X,Y,W,H
        console.borg_move(x,y)
        X=x;Y=y

    @window.event
    def on_mouse_drag(x, y, dx, dy, buttons, modifiers):
        global W,H
        W+=dx
        H+=dy
        console.borg_resize(W,H)

    @console.event
    def on_command(command):
        global ANS,NBSEC
        if lokumBorg:
            ANS, dursec = lokumBorg.reply(command)

            # ---------------- save borg answers
            if ANS: lokumBorg.save_line(ANS.strip())

            ANS = list(ANS)
            ANS.reverse()
            if dursec!=0:
                nblettres = len(ANS)
                NBSEC = float(dursec)/nblettres
                # set color for the borg
                console.write ('\n',attributes={'color': (0, 255, 0, 255)})
                clock.schedule_interval(callborg, NBSEC)
        
        # window.set_location(random.randrange(200,2000),0)
        # window.set_size(random.randrange(200,2000),300)

    def callborg(dt):
        global ANS, NBSEC
        if ANS:
            c = ANS.pop()
            console.write(c)
            console._caret.position = len(console._document.text)

        elif ANS==[]:
            console.write (' ',attributes={'color': (255, 255, 255, 120)})
            console.write ('\n')
            console.prompt()
            #console._document.delete_text(0, len(console._document.text)-1)
            #console._prompt_end = 0
            ANS = None
            clock.unschedule(callborg)
        else: ANS=None

    if 0:
        # source = pyglet.media.load('/data/lokum_data/video/tests/test.dv')
        # source = pyglet.media.load('/data/lokum_data/video/couperets/couperet.mov')

        # source2 = pyglet.media.load('/data/lokum_data/video/lokum/rael_1.mov') 
        #format = source.video_format
        # source = pyglet.media.load('/data/lokum_data/video/lokum/guray_fond_noir.mov') 
        # source = pyglet.media.load('/data/lokum_data/video/lokum/la_danse_des_ombres.mov') 
        #format2 = source2.video_format
        global player, player2, players
        player = None
        player2 = None
        players = []
        # source = pyglet.media.load('/data/lokum_data/video/lokum/rael_1.mov' ,streaming=True) 
        # source = pyglet.media.load('/data/lokum_data/video/lokum/essais_dada.mov' ,streaming=True) 
        source = pyglet.media.load('/data/lokum_data/video/lokum/oeil_vincent.dv') 
        format = source.video_format
        player = pyglet.media.Player()
        player.eos_action = player.EOS_LOOP
        player.volume = 0
        player.queue(source)
        #player.eos_action = player.EOS_LOOP

        player.play()
        #player.eos_action = player.EOS_LOOP

        player2 = None

        if 0:
            source2 = pyglet.media.load('/data/lokum_data/video/lokum/oeil_vincent.dv', streaming=True) 
            player2 = pyglet.media.Player()
            
        # player.eos_action = player.EOS_NEXT
            player2.eos_action = player2.EOS_LOOP
            
            player2.volume = 0
            

            player2.queue(source2)
            player2.play()

        if 0:
            path = "/data/lokum_data/video/lokum/"
            files = glob.glob(path+'/*')
            for f in files:
                print f
                p = pyglet.media.Player()
                p.queue(pyglet.media.load(f))
                p.volume = 0
                players.append(p)
                p.play()

    else: 
        source = None
        player = None

    if fx:
        default_system = fx.init(window)

    if default_system:
        default_system.run_ahead(2, 30)

    pyglet.app.run()
    r.quit() # quit vsosc