source MCPXutils;

global string $MCPXLastRealtimeDeviceUuid;

global proc AEMCPXRealTimeDeviceTemplate( string $nodeName ){
    
    editorTemplate -beginScrollLayout;

    editorTemplate -beginLayout "Realtime playback controls" -collapse false;

        editorTemplate -callCustom "MCPXRealTimeDeviceCreateView" "MCPXRealTimeDeviceUpdateView" "ipAddress" "wifiPort" "usbPort" "recordVideo";

    editorTemplate -endLayout;

    editorTemplate -beginLayout "Realtime playback options" -collapse true;

        editorTemplate -addControl "frameRate";

    editorTemplate -endLayout;

    editorTemplate -beginLayout "Record controls" -collapse false;

        editorTemplate -callCustom "MCPXRealTimeDeviceCreateRecordVideo" "MCPXRealTimeDeviceUpdateRecordVideo" "clipPathTemplate" "clipLength";

    editorTemplate -endLayout;

    editorTemplate -beginLayout "Incoming attributes" -collapse false;

        editorTemplate -callCustom "MCPXRealTimeDeviceCreateAttrList" "MCPXRealTimeDeviceUpdateAttrList" "connectionStatus";

    editorTemplate -endLayout;

    editorTemplate -suppress "refreshNode";
    editorTemplate -suppress "connectionStatus";
    editorTemplate -suppress "connectionType";
    editorTemplate -suppress "live";
    editorTemplate -suppress "caching";
    editorTemplate -suppress "frozen";
    editorTemplate -suppress "nodeState";

    editorTemplate -addExtraControls;

    editorTemplate -endScrollLayout;
}

global proc MCPXRealTimeDeviceCreateView(string $ipAddress, int $wifiPort, int $usbPort, int $recordVideo){
    python("from mocapx.ui.ae.datasource import realtime_device_create_view");
    string $par = `setParent -q`;
    python("realtime_device_create_view('" + $par + "', '" + $ipAddress  + "')");

    global string $MCPXLastRealtimeDeviceUuid;
    $MCPXLastRealtimeDeviceUuid = MCPXGetNodeUUID($ipAddress);
}

global proc MCPXRealTimeDeviceUpdateView(string $ipAddress, int $wifiPort, int $usbPort, int $recordVideo){
    python("from mocapx.ui.ae.datasource import realtime_device_update_view");
    string $par = `setParent -q`;

    global string $MCPXLastRealtimeDeviceUuid; //value will be updated after last panel refresh

    python("realtime_device_update_view('" + $par + "', '" + $ipAddress +  "', '" + $MCPXLastRealtimeDeviceUuid + "')");
}

global proc MCPXRealTimeDeviceCreateRecordVideo(string $clipPathTemplate, int $clipLength){
    python("from mocapx.ui.ae.datasource import realtime_device_records_create_view");
    string $par = `setParent -q`;
    python("realtime_device_records_create_view('" + $par + "', '" + $clipPathTemplate + "')");
}

global proc MCPXRealTimeDeviceUpdateRecordVideo(string $clipPathTemplate, int $clipLength){
    python("from mocapx.ui.ae.datasource import realtime_device_records_update_view");
    string $par = `setParent -q`;

    global string $MCPXLastRealtimeDeviceUuid; //value will be updated after last panel refresh

    python("realtime_device_records_update_view('" + $par + "', '" + $clipPathTemplate + "', '" + $MCPXLastRealtimeDeviceUuid + "')");
}

global proc MCPXRealTimeDeviceCreateAttrList( string $attrName ){
    python("from mocapx.ui.ae.datasource import attr_list_create_view");
    string $par = `setParent -q`;
    python("attr_list_create_view('" + $par + "', '" + $attrName  + "')");
}

global proc MCPXRealTimeDeviceUpdateAttrList( string $attrName ){
    python("from mocapx.ui.ae.datasource import attr_list_update_view");
    string $par = `setParent -q`;

    global string $MCPXLastRealtimeDeviceUuid; //value will be updated after last panel refresh

    python("attr_list_update_view('" + $par + "', '" + $attrName +  "', '" + $MCPXLastRealtimeDeviceUuid + "')");

    $MCPXLastRealtimeDeviceUuid = MCPXGetNodeUUID($attrName);
}
