ca96e3431e2d — Leonard Ritter a month ago
* GLMain, GUI, DockGUI no longer use global handlers
M lib/tukan/DockGUI.sc +41 -43
@@ 4,7 4,6 @@ using import FunctionChain
 
 using import .imgui
 using import .GUI
-import .stage
 import .icons
 import .sdl
 

          
@@ 15,60 14,59 @@ fn PushStyleRootWindow ()
 fn PopStyleRootWindow ()
     PopStyleVar 3
 
-typedef DockGUI
-    fnchain on-frame
-    fnchain on-define-main-menu
-    fnchain on-define-dock
-    fnchain on-define-windows
+type DockGUI <:: GUI
+    inline on-define-main-menu (self)
+    inline on-define-dock (self)
+    inline on-define-windows (self)
 
-    inline __typecall (cls glmain)
-        @@ 'on GUI.on-frame
-        inline draw (time size)
-            on-frame time size
+    inline on-frame (self)
 
-            let viewport = (GetMainViewport)
-            SetNextWindowPos ('GetWorkPos viewport)
-            SetNextWindowSize ('GetWorkSize viewport)
-            SetNextWindowViewport viewport.ID
+        let viewport = (GetMainViewport)
+        SetNextWindowPos ('GetWorkPos viewport)
+        SetNextWindowSize ('GetWorkSize viewport)
+        SetNextWindowViewport viewport.ID
 
-            PushStyleRootWindow;
-            Begin "Main" none
-                |
-                    ImGuiWindowFlags_NoTitleBar
-                    ImGuiWindowFlags_NoResize
-                    ImGuiWindowFlags_NoMove
-                    ImGuiWindowFlags_NoCollapse
-                    ImGuiWindowFlags_NoScrollWithMouse
-                    ImGuiWindowFlags_MenuBar
-                    ImGuiWindowFlags_NoSavedSettings
-                    ImGuiWindowFlags_NoBringToFrontOnFocus
-                    ImGuiWindowFlags_NoFocusOnAppearing
-                    ImGuiWindowFlags_NoDocking
-                    ImGuiWindowFlags_NoNavFocus
-            PopStyleRootWindow;
+        PushStyleRootWindow;
+        Begin "Main" none
+            |
+                ImGuiWindowFlags_NoTitleBar
+                ImGuiWindowFlags_NoResize
+                ImGuiWindowFlags_NoMove
+                ImGuiWindowFlags_NoCollapse
+                ImGuiWindowFlags_NoScrollWithMouse
+                ImGuiWindowFlags_MenuBar
+                ImGuiWindowFlags_NoSavedSettings
+                ImGuiWindowFlags_NoBringToFrontOnFocus
+                ImGuiWindowFlags_NoFocusOnAppearing
+                ImGuiWindowFlags_NoDocking
+                ImGuiWindowFlags_NoNavFocus
+        PopStyleRootWindow;
+
+        # DockSpace
+        io := (GetIO)
 
-            # DockSpace
-            io := (GetIO)
+        DockSpace
+            GetID "DockSpace"
+            vec2 0
+            ImGuiDockNodeFlags_None
 
-            DockSpace
-                GetID "DockSpace"
-                vec2 0
-                ImGuiDockNodeFlags_None
+        do
+            if (WithMenuBar)
+                'on-define-main-menu self
 
-            do
-                if (WithMenuBar)
-                    on-define-main-menu;
+        End;
 
-            End;
+        'on-define-dock self
 
-            on-define-dock;
+        'on-define-windows self
 
-            on-define-windows;
+    from GUI let run handle-events draw
 
-        let gui = (GUI glmain)
+    inline __typecall (cls ...)
+        let self = (GUI.__typecall cls ...)
         let io = (GetIO)
         io.ConfigFlags |= (ImGuiConfigFlags_DockingEnable as integer as i32)
-        gui
+        self
 
 do
     let DockGUI

          
M lib/tukan/FIR.sc +30 -0
@@ 298,6 298,8 @@ define-type "fetchimagelod" (RIFF "FILD"
 # FIR Level 0
 ################################################################################
 
+define-type "static"    (RIFF "STAT") (tuple (params = AnyId) (init = AnyId) (break = AnyId) (repeat = AnyId))
+    funccolor...
 define-type "fn"        (RIFF "FN  ") (tuple (params = AnyId) (body = AnyId))
     funccolor...
 define-type "params"    (RIFF "PARA") (tuple (level = u32) (count = u32))

          
@@ 2699,8 2701,36 @@ sugar FIRfn (name (args...) body...)
         list let name '= expr
     else expr
 
+sugar FIRstatic ((args... '= init...) ('break break...) ('repeat repeat...))
+    print args...
+    print init...
+    print break...
+    print repeat...
+    let module =
+        try ('@ sugar-scope 'fir-module)
+        else
+            error "`fir-module` must be defined in scope"
+    let level =
+        try (('@ sugar-scope 'fir-fn-level) as u32)
+        else 0:u32
+    let builder = `(getattr module 'builder)
+    let argcount = ((countof args...) as u32)
+    let params = `('params builder level argcount)
+    let expr =
+        list ''fn builder params
+            cons do
+                list let 'fir-fn-level '= (level + 1)
+                fold (body = body...) for i arg in (enumerate args... u32)
+                    cons
+                        list let arg '= `(report ('va builder i params))
+                        body
+    if (('typeof name) == Symbol)
+        list let name '= expr
+    else expr
+
 do
     let FIR NoId AnyId SystemKey ImageDim ImageFormat ImageFlags TypeId
         \ PrimitiveMode InterpolationMode DepthTestType FIRTyper FIRfn
+        \ FIRstatic
         \ CullMode
     locals;

          
M lib/tukan/GLMain.sc +26 -44
@@ 1,26 1,13 @@ 
-
-import .stage
 
 using import glm
-using import FunctionChain
 using import struct
 using import property
 
 using import .gl
 using import .sdl
-
-let controllerdb =
-    import .gamecontrollerdb
+using import .system
 
 fn _init (title width height resizable hidden)
-    SDL_SetHint "SDL_GAMECONTROLLERCONFIG" controllerdb
-
-    SDL_Init
-        | SDL_INIT_AUDIO
-            SDL_INIT_VIDEO
-            SDL_INIT_GAMECONTROLLER
-            #SDL_INIT_JOYSTICK
-
     SDL_GL_SetAttribute SDL_GL_DOUBLEBUFFER 1
 
     SDL_GL_SetAttribute SDL_GL_STENCIL_SIZE 8

          
@@ 59,34 46,31 @@ fn _init (title width height resizable h
     _ (window = window) (glcontext = context)
 
 fn _shutdown (window glcontext)
+    report "shutting down GLMain..."
     SDL_GL_DeleteContext glcontext
     SDL_DestroyWindow window
-    SDL_Quit;
 
 fn _swap (window)
     GL.BindFramebuffer GL.FRAMEBUFFER 0
     SDL_GL_SwapWindow window
 
 struct GLMain
+    system : System
     window : (returnof SDL_CreateWindow)
     glcontext : (returnof SDL_GL_CreateContext)
 
-    fnchain on-event
-    fnchain on-draw
-
     inline __typecall (cls opts...)
         let
-            title = (va-option title opts... "Tukan")
+            title = (va-option title opts... "GLMain")
             width = (va-option width opts... 640)
             height = (va-option height opts... 480)
             resizable = (va-option resizable opts... false)
             hidden = (va-option hidden opts... false)
 
+        let system = (System)
         let state... = (_init title width height resizable hidden)
-        stage.on-init;
         let self =
-            super-type.__typecall cls state...
-        stage.init-gfx (glmain = self)
+            super-type.__typecall cls system state...
         self
 
     title :=

          
@@ 96,10 80,13 @@ struct GLMain
             inline (self title)
                 SDL_SetWindowTitle self.window title
 
-    fn show-window (self)
+    fn show (self)
         SDL_ShowWindow self.window
 
-    inline handle-events (self)
+    fn hide (self)
+        SDL_HideWindow self.window
+
+    fn handle-events (self on-event)
         local event = (SDL_Event)
         loop (quit = false)
             if ((SDL_PollEvent &event) == 0)

          
@@ 113,9 100,7 @@ struct GLMain
                     event.window.windowID == (SDL_GetWindowID self.window)
                 repeat true
             else
-                on-event
-                    event = event
-                    glmain = self
+                on-event event
                 repeat quit
 
     fn size (self)

          
@@ 125,27 110,24 @@ struct GLMain
         _ (deref w) (deref h)
 
     inline __drop (self)
-        stage.shutdown-gfx (glmain = self)
         _shutdown self.window self.glcontext
-        stage.on-shutdown;
+        super-type.__drop self
+
+    fn swap (self)
+        _swap self.window
 
-    inline step (self)
-        if (handle-events self)
-            return false
-        let w h = (size self)
-        on-draw
-            time = 0.0
-            size = (ivec2 w h)
-            glmain = self
-        _swap self.window
-        true
-
-    inline run (self)
+    fn run (self on-event on-draw)
         loop ()
-            if (step self)
-                repeat;
+            if (handle-events self on-event)
+                false
             else
-                break;
+                let swap? = (on-draw)
+                static-if (none? swap?)
+                    swap self
+                else
+                    if swap?
+                        swap self
+                true
 
 do
     let GLMain

          
M lib/tukan/GUI.sc +31 -19
@@ 1,10 1,9 @@ 
 
 using import glm
-using import FunctionChain
 using import struct
+using import Capture
 
 using import .GLMain
-import .stage
 import .icons
 import .sdl
 

          
@@ 218,21 217,28 @@ fn _init (glmain)
         FixedFont = FixedFont
 
 struct GUI
+    glmain : GLMain
     SansFont : (returnof ImFontAtlas_AddFontFromFileTTF)
     FixedFont : (returnof ImFontAtlas_AddFontFromFileTTF)
     imctx : (returnof CreateContext)
 
-    fnchain on-frame
+    inline on-frame (self)
 
     fn on-event (event)
         sdl.ImGui_ImplSDL2_ProcessEvent &event
 
-    inline draw (time size glmain)
+    fn handle-events (self on-event)
+        'handle-events self.glmain
+            capture (event) {on-event}
+                sdl.ImGui_ImplSDL2_ProcessEvent &event
+                on-event event
+
+    fn draw (self)
         ImGui_ImplOpenGL3_NewFrame;
-        sdl.ImGui_ImplSDL2_NewFrame glmain.window
+        sdl.ImGui_ImplSDL2_NewFrame self.glmain.window
         NewFrame;
 
-        on-frame time size
+        'on-frame self
 
         #glViewport(0, 0, (int)io.DisplaySize.x, (int)io.DisplaySize.y);
         #glClearColor(clear_color.x, clear_color.y, clear_color.z, clear_color.w);

          
@@ 258,25 264,31 @@ struct GUI
         #glClear GL_COLOR_BUFFER_BIT
         #blit-framebuffer screen.framebuffer 0 size
 
-    inline __typecall (cls glmain)
+    fn run (self on-event on-draw)
+        viewing on-event on-draw
+        loop ()
+            if ('handle-events self on-event)
+                break;
+            else
+                'draw self
+                let swap? = (on-draw)
+                static-if (none? swap?)
+                    'swap self.glmain
+                else
+                    if swap?
+                        'swap self.glmain
+                repeat;
+
+    inline __typecall (cls ...)
+        let glmain = (GLMain ...)
         let state... = (_init glmain)
-        let self =
-            super-type.__typecall cls state...
-        # ensure that imgui goes out of scope before glmain
-        'append stage.shutdown-gfx
-            inline (glmain)
-                drop self
-        'append GLMain.on-event
-            inline (event glmain)
-                on-event event
-        'append GLMain.on-draw draw
-        self
+        super-type.__typecall cls glmain state...
 
     fn __drop (self)
         ImGui_ImplOpenGL3_Shutdown;
         sdl.ImGui_ImplSDL2_Shutdown;
         DestroyContext self.imctx
-
+        super-type.__drop self
 
 do
     let GUI

          
M lib/tukan/Screen.sc +2 -3
@@ 1,8 1,6 @@ 
 
 import glsl
 
-import .stage
-
 using import .gl
 using import glm
 using import struct

          
@@ 13,7 11,8 @@ let screen-tri-vertices =
         vec2  3 -1
         vec2 -1  3
 
-run-stage;
+static-assert
+    constant? screen-tri-vertices
 
 struct Screen
     vao : GL.VertexArray

          
M lib/tukan/main.sc +74 -76
@@ 13,11 13,11 @@ using import .imgui
 using import .nfd
 using import .module
 
-using import .view.events
+#using import .view.events
 
 using import .view.blocktree
-using import .view.shader
-using import .view.hexedit
+#using import .view.shader
+#using import .view.hexedit
 
 #-------------------------------------------------------------------------------
 

          
@@ 27,6 27,72 @@ struct App
     path : string = (string "")
     module : OptModule
 
+global app : App
+
+#-------------------------------------------------------------------------------
+
+fn handle-gui-error (err)
+    print "error:" err
+
+#-------------------------------------------------------------------------------
+
+type AppDockGUI <:: DockGUI
+    from DockGUI let run handle-events __typecall on-frame draw
+
+    global test-window-visible = false
+    inline on-define-windows (self)
+        if test-window-visible
+            ShowDemoWindow test-window-visible
+
+    inline on-define-main-menu (self)
+        if (WithMenu "File")
+            if (MenuItem "New Module")
+                local target_path : (mutable rawstring)
+                let result =
+                    NFD_SaveDialog "tuk"
+                        module-dir
+                        &target_path
+                if (result as integer == 1)
+                    try
+                        'new-module app target_path
+                    except (err)
+                        handle-gui-error err
+            if (MenuItem "Open Module")
+                local target_path : (mutable rawstring)
+                let result =
+                    NFD_OpenDialog "tuk"
+                        module-dir
+                        &target_path
+                if (result as integer == 1)
+                    try
+                        'new-module app target_path
+                    except (err)
+                        handle-gui-error err
+        if (WithMenu "View")
+            MenuItem "Show Demo Window"
+                selected = test-window-visible
+            #on-define-view-menu;
+            define-blocktree-view-menu;
+
+    inline on-define-dock (self)
+        define-blocktree-dock;
+
+global dockgui =
+    AppDockGUI
+        title = "Tukan"
+        width = 960
+        height = 540
+        resizable = true
+
+type+ App
+    fn on-module-changed (self)
+        let title =
+            if (empty? app.path) "Tukan"
+            else
+                .. app.path " - Tukan"
+        dockgui.glmain.title = title
+        ;
+
     fn init (self)
         on-module-changed self
 

          
@@ 44,83 110,15 @@ struct App
             raise err
         ;
 
-global app : App
-
 #-------------------------------------------------------------------------------
 
-fn handle-gui-error (err)
-    print "error:" err
-
-#-------------------------------------------------------------------------------
-
-global glmain =
-    GLMain
-        title = "Tukan"
-        width = 960
-        height = 540
-        resizable = true
-
-DockGUI glmain
-
-#-------------------------------------------------------------------------------
-
-@@ 'on on-module-changed
-inline (app)
-    let title =
-        if (empty? app.path) "Tukan"
-        else
-            .. app.path " - Tukan"
-    glmain.title = title
-
-global test-window-visible = false
-@@ 'on DockGUI.on-define-windows
-inline ()
-    if test-window-visible
-        ShowDemoWindow test-window-visible
-
-@@ 'on DockGUI.on-define-main-menu
-inline ()
-    if (WithMenu "File")
-        if (MenuItem "New Module")
-            local target_path : (mutable rawstring)
-            let result =
-                NFD_SaveDialog "tuk"
-                    module-dir
-                    &target_path
-            if (result as integer == 1)
-                try
-                    'new-module app target_path
-                except (err)
-                    handle-gui-error err
-        if (MenuItem "Open Module")
-            local target_path : (mutable rawstring)
-            let result =
-                NFD_OpenDialog "tuk"
-                    module-dir
-                    &target_path
-            if (result as integer == 1)
-                try
-                    'new-module app target_path
-                except (err)
-                    handle-gui-error err
-    if (WithMenu "View")
-        MenuItem "Show Demo Window"
-            selected = test-window-visible
-        on-define-view-menu;
-
-@@ 'on DockGUI.on-frame
-fn (s size)
-    #glBlitNamedFramebuffer fb 0
-        \ 0 0 size.x size.y
-        \ 0 0 size.x size.y
-        GL_COLOR_BUFFER_BIT
-        GL_NEAREST
-
 print "running main program"
 
 'init app
-'run glmain
-
-__drop glmain
+'run dockgui
+    capture (event) {}
+    capture () {}
 
 print "done."
+
+

          
M lib/tukan/portmidi.sc +2 -2
@@ 4,11 4,11 @@ if (operating-system == 'windows)
     load-library "libportmidi.dll"
 else
     load-library
-        module-dir .. "/../bin/libportmidi.so"
+        module-dir .. "/../libportmidi.so"
 
 let pm =
     include "portmidi.h"
-        options "-I" (module-dir .. "/../cdefs")
+        options "-I" (module-dir .. "/../../cdefs")
 
 do
     #using pm.define filter "^(PM(.+))$"

          
R lib/tukan/stage.sc =>  +0 -9
@@ 1,9 0,0 @@ 
-
-using import FunctionChain
-
-fnchain on-init
-fnchain init-gfx
-fnchain shutdown-gfx
-fnchain on-shutdown
-
-locals;

          
A => lib/tukan/system.sc +53 -0
@@ 0,0 1,53 @@ 
+
+using import glm
+using import struct
+using import property
+
+using import .gl
+using import .sdl
+
+let controllerdb =
+    import .gamecontrollerdb
+
+global refcount = 0:u32
+
+fn setup ()
+    let rc = (deref refcount)
+    refcount += 1
+    if (rc > 0)
+        return;
+    report "system setup..."
+    SDL_SetHint "SDL_GAMECONTROLLERCONFIG" controllerdb
+
+    SDL_Init
+        | SDL_INIT_AUDIO
+            SDL_INIT_VIDEO
+            SDL_INIT_GAMECONTROLLER
+            #SDL_INIT_JOYSTICK
+    ;
+
+fn shutdown ()
+    let rc = (deref refcount)
+    assert (rc >= 0)
+    refcount -= 1
+    if (rc > 0)
+        return;
+    report "system shutdown..."
+    refcount -= 1
+    SDL_Quit;
+
+# handle
+struct System
+    tmp : u32
+
+    inline __typecall (cls)
+        setup;
+        super-type.__typecall cls
+    inline __drop (self)
+        shutdown;
+        super-type.__drop self
+
+do
+    let System
+
+    locals;

          
M lib/tukan/view/blocktree.sc +4 -6
@@ 12,7 12,7 @@ using import Rc
 using import ..DockGUI
 using import ..imgui
 
-using import .events
+#using import .events
 
 let NEGINVSQRT2 = (- (2.0 ** 0.5))
 fn DrawPort (dl pos radius thickness bgcol fgcol)

          
@@ 388,8 388,7 @@ inline ReturnPort (id color)
 
 global show-code = true
 
-@@ 'on on-define-view-menu
-inline ()
+inline define-blocktree-view-menu ()
     MenuItem "Show Blocktree Test"
         selected = show-code
 

          
@@ 544,9 543,7 @@ fn walk (node)
     if (IsBlockTreeDropped)
         perform-drop node (GetBlockTreeDropMode)
 
-
-@@ 'on DockGUI.on-define-dock
-inline ()
+fn define-blocktree-dock ()
     if show-code
         if (WithBegin "Blocktree Test" show-code)
             global blocktree : RcBlockTree

          
@@ 600,4 597,5 @@ inline ()
                     Button "Content"
 
 do
+    let define-blocktree-dock define-blocktree-view-menu
     locals;

          
R lib/tukan/view/events.sc =>  +0 -7
@@ 1,7 0,0 @@ 
-
-using import FunctionChain
-
-fnchain on-define-view-menu
-fnchain on-module-changed
-
-locals;

          
M lib/tukan/view/shader.sc +0 -2
@@ 4,8 4,6 @@ using import struct
 using import glsl
 using import Option
 
-import ..stage
-
 using import ..Screen
 using import ..gl
 using import ..GLMain

          
M testing/test_main.sc +3 -217
@@ 1,220 1,6 @@ 
 #!/usr/bin/env scopes
 
-using import struct
-
-#let stringtest = "Hello"
-#let booltest = true
-
-using import glm
-using import glsl
-
-using import .tukan.GLMain
-using import .tukan.Screen
-
-using import .tukan.DockGUI
-using import .tukan.sdf
-using import .tukan.rotation
-
-using import .tukan.gl
-using import .tukan.imgui
-
-vvv bind glmain
-GLMain
-    title = "Tukan"
-    width = 960
-    height = 540
-    resizable = true
-
-let screen = (Screen)
-DockGUI glmain
-
-print "setting up texture..."
-let fbsize =
-    ivec2 1920 1080
-global fbtex = (GL.CreateTexture GL.TEXTURE_2D)
-'setup fbtex
-    size = fbsize
-    format = GL.RGBA8
-local color =
-    arrayof u8 255 0 255 255
-GL.ClearTexImage fbtex 0 GL.RGBA GL.UNSIGNED_BYTE &color
-
-print "setting up framebuffer..."
-let fb = (GL.CreateFramebuffer)
-setup-framebuffer fb
-    color = fbtex
-
-print "building shaders"
-
-fn normsin (x)
-    (sin x) * 0.5 + 0.5
-
-struct ShaderGlobals
-    aspect : f32
-    time : f32
-
-let BUFFER_COUNT = 3
-#let UBO_ALIGN =
-    usize (gl-get-int GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT)
-#let SSBO_ALIGN =
-    usize (gl-get-int GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT)
-
-uniform phase : f32
-    location = 0
-
-uniform shglobals : ShaderGlobals
-    binding = 0
-
-let globals-data = (GL.CreateBuffer)
-setup-ubo globals-data shglobals BUFFER_COUNT
-
-#-------------------------------------------------------------------------------
-
-
-
-#-------------------------------------------------------------------------------
-
-inout uv : vec2 (location = 0)
-inout pos : vec2 (location = 1)
-
-fn test-vertex ()
-    uv.out =
-        ((Screen.set-vertex-position) * 0.5) + 0.5
-    return;
-
-fn make-phase ()
-    phase as immutable
-
-fn map (p)
-    let p =
-        versor-rotate
-            versor (vec3 0 1 0) (deref shglobals.time)
-            + p
-                vec3 0 0 -2
-    #let p =
-        * (rotation (versor (vec3 0 1 0) (shglobals.time as immutable)))
-            + p
-                vec3 0 0 -2
-    sdBox p
-        vec3 0.5
-    #sdUberprim p
-        vec4 1.0 1.0 0.25 0.25
-        vec3 1.0 0.25 0.0
+import ..lib.tukan.use
+import tukan.main
 
-let FAR_LIMIT = 100.0
-let MAX_STEPS = 50
-inline raymarch (mapf ro rd)
-    loop (i t = 0 0.0)
-        let p = (ro + rd * t)
-        let d = (mapf p)
-        if ((d > 1e-3) & (t < FAR_LIMIT) & (i < MAX_STEPS))
-            repeat (i + 1) (t + d)
-        else
-            break p (not (t >= FAR_LIMIT))
-
-out out_Color : vec4
-fn test-fragment ()
-    let uv =
-        (uv.in * 2.0 - 1.0) * (vec2 shglobals.aspect 1)
-    let p hit =
-        raymarch map (vec3 0)
-            normalize
-                vec3 uv 1
-    out_Color =
-        vec4
-            ? hit
-                (sdNormal map p) * 0.5 + 0.5
-                vec3 0.0
-            1
-    return;
-
-print "attaching shaders..."
-let pg-test = (GL.CreateProgram)
-call
-    attach-shaders pg-test
-        vertex = test-vertex
-        fragment = test-fragment
-        #debug = true
-locals;
-
-#-------------------------------------------------------------------------------
-
-print "running main program"
-
-global test-window-visible = false
-@@ 'on DockGUI.on-define-windows
-inline ()
-    if (test-window-visible as immutable)
-        ShowDemoWindow test-window-visible
-
-@@ 'on DockGUI.on-define-main-menu
-inline ()
-    if (BeginMenu "View")
-        MenuItem "Show Demo Window"
-            selected = test-window-visible
-        EndMenu;
-
-global g_phase = 0.0
-global g_frame = 0
-inline render-view (size)
-    GL.BindFramebuffer GL.FRAMEBUFFER fb
-    GL.Viewport 0 0 (i32 size.x) (i32 size.y)
-    GL.ClearColor 0 0 1 1
-    GL.Clear
-        |
-            GL.COLOR_BUFFER_BIT
-            GL.DEPTH_BUFFER_BIT
-            GL.STENCIL_BUFFER_BIT
-
-    GL.UseProgram pg-test
-    #glUniform phase (normsin (g_phase as immutable))
-
-    let buffer-index = (g_frame % BUFFER_COUNT)
-
-    local data =
-        ShaderGlobals
-            aspect = (size.x / size.y)
-            time = (g_frame / 60)
-    bind-ubo globals-data shglobals &data buffer-index
-
-    g_phase = (g_phase + 0.1)
-    g_frame = g_frame + 1
-    'draw screen
-    GL.UseProgram 0
-
-let source =
-    list-load module-path
-
-@@ 'on DockGUI.on-define-dock
-inline ()
-    SetNextDock ImGuiDockSlot_Right
-    if (BeginDock "3D")
-        let size =
-            GetContentRegionAvail;
-        render-view size
-        Image
-            inttoptr fbtex ImTextureID
-            size = size
-            uv0 =
-                vec2 0.0
-                    size.y / (f32 fbsize.y)
-            uv1 =
-                vec2
-                    size.x / (f32 fbsize.x)
-                    0.0
-    EndDock;
-
-#'append glmain.on-draw
-@@ 'on DockGUI.on-frame
-fn (s size)
-    #glBlitNamedFramebuffer fb 0
-        \ 0 0 size.x size.y
-        \ 0 0 size.x size.y
-        GL_COLOR_BUFFER_BIT
-        GL_NEAREST
-
-'run glmain
-
-drop glmain
-
-print "done."
+;
  No newline at end of file

          
M testing/test_midi.sc +3 -2
@@ 1,6 1,7 @@ 
 
-using import ..tukan.midi
-using import ..tukan.sdl
+import ..lib.tukan.use
+using import tukan.midi
+using import tukan.sdl
 
 SDL_Init SDL_INIT_AUDIO
 midi-init;

          
M testing/tukdag.sc +36 -4
@@ 268,12 268,12 @@ inline gen-level2-test-geometry ()
                 fvec3 (fconst 0.1) (fconst 0.1) (fconst 0.12)
 
     outputs
-        output SystemKey.Screen cube
-            #compute (input SystemKey.ScreenSize)
+        output SystemKey.Screen #cube
+            compute (input SystemKey.ScreenSize)
                 do
                     let x y =
                         unpack-comp (globalid) 2
-                    let D = (uconst 10)
+                    let D = (uconst 1)
                     let col0 = (fetch cube (uvec2 (sub x D) (add y (uconst 0))))
                     let col1 = (fetch cube (uvec2 (add x D) (add y (uconst 0))))
                     let col2 = (fetch cube (uvec2 (add x (uconst 0)) (sub y D)))

          
@@ 336,6 336,31 @@ inline gen-level2-test ()
                     let z = (fmul (fadd q0 q1) itsin)
                     fvec4 u v z (fconst 1)
 
+inline gen-level2-test-audio ()
+    from (methodsof module.builder) let output outputs mul unfold input
+    let fir-module = module
+
+    let inp_sr = (input SystemKey.SampleRate)
+    let inp_sc = (input SystemKey.SampleCount)
+    let inp_it = (input SystemKey.Iteration)
+
+    outputs
+        output SystemKey.Sound
+            FIRstatic (phase = (fconst 0))
+                break
+                    let result =
+                        unfold (mul inp_sc (uconst 2))
+                            FIRfn (i phase)
+                                vargs
+                                    sin (fmul phase (fconst tau))
+                                    fadd phase
+                                        fdiv (fconst 220) (utof inp_sr)
+                            phase
+                    va 0 result
+                repeat (va 1 result)
+    funccolor...
+
+
 # perform an identity transform and swap out the new module
     all transformations are immutable.
 inline cleanup (rootid)

          
@@ 362,7 387,7 @@ inline graphviz (rootid)
 #let prog = (gen-level1-test-geometry)
 #let prog = (gen-level1-test)
 
-let prog =
+#let prog =
     do
         let prog = (gen-level2-test-geometry)
         let prog = (cleanup prog)

          
@@ 377,6 402,13 @@ let prog =
         'dump module prog
         print "lowering..."
         'lower module prog
+let prog =
+    do
+        let prog = (gen-level2-test-audio)
+        'dump module prog
+        print "lowering..."
+        'lower module prog
+
 print "folding constants..."
 let prog = ('fold-constant-expressions module prog)
 #cleanup;