{
  "version": 0,
  "entry": "b1",
  "blocks": {
    "b1": {
      "type": "setVar",
      "inputs": {
        "name": "outputFolder",
        "value": "::HOME::/automation-agent-runtime-tests/equal-distance-frames"
      },
      "next": "b2"
    },
    "b2": {
      "type": "setVar",
      "inputs": {
        "name": "resolvedOutputFolder",
        "value": {
          "type": "resolveSpecialPath",
          "inputs": {
            "path": {
              "var": "outputFolder"
            }
          }
        }
      },
      "next": "b3"
    },
    "b3": {
      "type": "if",
      "inputs": {
        "branches": [
          {
            "condition": {
              "type": "folderExists",
              "inputs": {
                "path": {
                  "var": "resolvedOutputFolder"
                }
              }
            },
            "body": [
              {
                "type": "deleteFolder",
                "inputs": {
                  "path": {
                    "var": "resolvedOutputFolder"
                  },
                  "recursive": true
                }
              }
            ]
          }
        ]
      },
      "next": "b4"
    },
    "b4": {
      "type": "createFolder",
      "inputs": {
        "path": {
          "var": "resolvedOutputFolder"
        }
      },
      "next": "b5"
    },
    "b5": {
      "type": "setVar",
      "inputs": {
        "name": "sampleCount",
        "value": 3
      },
      "next": "b6"
    },
    "b6": {
      "type": "setVar",
      "inputs": {
        "name": "frameWidth",
        "value": {
          "type": "prGetSequenceProperty",
          "inputs": {
            "sequence": "::SEQ\\ACTIVE",
            "property": "FRAME_WIDTH"
          }
        }
      },
      "next": "b7"
    },
    "b7": {
      "type": "setVar",
      "inputs": {
        "name": "frameHeight",
        "value": {
          "type": "prGetSequenceProperty",
          "inputs": {
            "sequence": "::SEQ\\ACTIVE",
            "property": "FRAME_HEIGHT"
          }
        }
      },
      "next": "b8"
    },
    "b8": {
      "type": "setVar",
      "inputs": {
        "name": "sequenceZeroPointSeconds",
        "value": {
          "type": "prGetSequenceProperty",
          "inputs": {
            "sequence": "::SEQ\\ACTIVE",
            "property": "ZERO_POINT_SECONDS"
          }
        }
      },
      "next": "b9"
    },
    "b9": {
      "type": "setVar",
      "inputs": {
        "name": "sequenceEndSeconds",
        "value": {
          "type": "prGetSequenceProperty",
          "inputs": {
            "sequence": "::SEQ\\ACTIVE",
            "property": "END_SECONDS"
          }
        }
      },
      "next": "b10"
    },
    "b10": {
      "type": "setVar",
      "inputs": {
        "name": "sequenceVisibleDurationSeconds",
        "value": {
          "type": "mathArithmetic",
          "inputs": {
            "op": "MINUS",
            "a": {
              "var": "sequenceEndSeconds"
            },
            "b": {
              "var": "sequenceZeroPointSeconds"
            }
          }
        }
      },
      "next": "b11"
    },
    "b11": {
      "type": "if",
      "inputs": {
        "branches": [
          {
            "condition": {
              "type": "logicCompare",
              "inputs": {
                "op": "LTE",
                "a": {
                  "var": "sequenceVisibleDurationSeconds"
                },
                "b": 0
              }
            },
            "body": [
              {
                "type": "fail",
                "inputs": {
                  "message": "Active sequence duration must be greater than zero for equal-distance frame sampling."
                }
              }
            ]
          }
        ]
      },
      "next": "b12"
    },
    "b12": {
      "type": "setVar",
      "inputs": {
        "name": "sampleSpacingSeconds",
        "value": {
          "type": "mathArithmetic",
          "inputs": {
            "op": "DIVIDE",
            "a": {
              "var": "sequenceVisibleDurationSeconds"
            },
            "b": {
              "var": "sampleCount"
            }
          }
        }
      },
      "next": "b13"
    },
    "b13": {
      "type": "setVar",
      "inputs": {
        "name": "exportedFrameCount",
        "value": 0
      },
      "next": "b14"
    },
    "b14": {
      "type": "setVar",
      "inputs": {
        "name": "firstFramePath",
        "value": ""
      },
      "next": "b15"
    },
    "b15": {
      "type": "forRange",
      "inputs": {
        "indexVar": "sampleIndex",
        "from": 0,
        "to": {
          "type": "mathArithmetic",
          "inputs": {
            "op": "MINUS",
            "a": {
              "var": "sampleCount"
            },
            "b": 1
          }
        }
      },
      "body": [
        {
          "type": "setVar",
          "inputs": {
            "name": "sampleIndexOneBased",
            "value": {
              "type": "mathArithmetic",
              "inputs": {
                "op": "ADD",
                "a": {
                  "var": "sampleIndex"
                },
                "b": 1
              }
            }
          }
        },
        {
          "type": "setVar",
          "inputs": {
            "name": "sampleOffsetSeconds",
            "value": {
              "type": "mathArithmetic",
              "inputs": {
                "op": "MULTIPLY",
                "a": {
                  "var": "sampleSpacingSeconds"
                },
                "b": {
                  "type": "mathArithmetic",
                  "inputs": {
                    "op": "ADD",
                    "a": {
                      "var": "sampleIndex"
                    },
                    "b": 0.5
                  }
                }
              }
            }
          }
        },
        {
          "type": "setVar",
          "inputs": {
            "name": "sampleTimeSeconds",
            "value": {
              "type": "mathArithmetic",
              "inputs": {
                "op": "ADD",
                "a": {
                  "var": "sequenceZeroPointSeconds"
                },
                "b": {
                  "var": "sampleOffsetSeconds"
                }
              }
            }
          }
        },
        {
          "type": "setVar",
          "inputs": {
            "name": "sampleTimeTextRaw",
            "value": {
              "type": "prFormatTime",
              "inputs": {
                "timeSeconds": {
                  "var": "sampleTimeSeconds"
                },
                "format": "HH_MM_SS_MS"
              }
            }
          }
        },
        {
          "type": "setVar",
          "inputs": {
            "name": "sampleTimeText",
            "value": {
              "type": "textReplace",
              "inputs": {
                "text": {
                  "type": "textReplace",
                  "inputs": {
                    "text": {
                      "var": "sampleTimeTextRaw"
                    },
                    "from": ":",
                    "to": "_"
                  }
                },
                "from": ",",
                "to": "_"
              }
            }
          }
        },
        {
          "type": "setVar",
          "inputs": {
            "name": "framePath",
            "value": {
              "type": "textJoin",
              "inputs": {
                "items": [
                  {
                    "var": "resolvedOutputFolder"
                  },
                  "/sample-",
                  {
                    "var": "sampleIndexOneBased"
                  },
                  "-",
                  {
                    "var": "sampleTimeText"
                  },
                  ".png"
                ]
              }
            }
          }
        },
        {
          "type": "setVar",
          "inputs": {
            "name": "lastFrameExportOk",
            "value": false
          }
        },
        {
          "type": "if",
          "inputs": {
            "branches": [
              {
                "condition": {
                  "type": "logicCompare",
                  "inputs": {
                    "op": "EQ",
                    "a": {
                      "var": "exportedFrameCount"
                    },
                    "b": 0
                  }
                },
                "body": [
                  {
                    "type": "setVar",
                    "inputs": {
                      "name": "firstFramePath",
                      "value": {
                        "var": "framePath"
                      }
                    }
                  }
                ]
              }
            ]
          }
        },
        {
          "type": "prExportSequenceFrame",
          "inputs": {
            "sequence": "::SEQ\\ACTIVE",
            "timeSeconds": {
              "var": "sampleTimeSeconds"
            },
            "outputPath": {
              "var": "framePath"
            },
            "width": {
              "var": "frameWidth"
            },
            "height": {
              "var": "frameHeight"
            },
            "onError": "STOP",
            "storeResultIn": "lastFrameExportOk"
          }
        },
        {
          "type": "setVar",
          "inputs": {
            "name": "exportedFrameCount",
            "value": {
              "type": "mathArithmetic",
              "inputs": {
                "op": "ADD",
                "a": {
                  "var": "exportedFrameCount"
                },
                "b": 1
              }
            }
          }
        }
      ],
      "next": "b16"
    },
    "b16": {
      "type": "setVar",
      "inputs": {
        "name": "exportedFiles",
        "value": {
          "type": "listFilesInFolder",
          "inputs": {
            "path": {
              "var": "resolvedOutputFolder"
            },
            "includeSubfolders": false
          }
        }
      },
      "next": "b17"
    },
    "b17": {
      "type": "setVar",
      "inputs": {
        "name": "exportedFileCount",
        "value": {
          "type": "listLength",
          "inputs": {
            "list": {
              "var": "exportedFiles"
            }
          }
        }
      },
      "next": "b18"
    },
    "b18": {
      "type": "setVar",
      "inputs": {
        "name": "firstFrameExists",
        "value": {
          "type": "fileExists",
          "inputs": {
            "path": {
              "var": "firstFramePath"
            }
          }
        }
      },
      "next": "b19"
    },
    "b19": {
      "type": "esConsoleLog",
      "inputs": {
        "message": {
          "type": "textJoin",
          "inputs": {
            "items": [
              "equalDistanceFrameExportCount=",
              {
                "var": "exportedFrameCount"
              },
              " exportedFileCount=",
              {
                "var": "exportedFileCount"
              }
            ]
          }
        }
      },
      "next": null
    }
  }
}
