Rational time and ranges

PostProject represents reusable time values without floating point. A RationalRate is a positive, reduced fraction such as 24/1 or 30000/1001. A RationalTime combines an integer value with that rate. Its exact duration in seconds is:

value × rate denominator / rate numerator

The canonical text forms are numerator/denominator for a rate and value@numerator/denominator for a time. For example, 1,001 units at the exact fractional rate are 1001@24000/1001, without a rounded decimal rate.

Comparison and conversion

Ordinary Rust equality compares the stored value and normalized rate. Use RationalTime::equivalent to compare the exact times represented at different rates. For example, 24@24/1 and 48@48/1 are equivalent.

RationalTime::rescaled_to succeeds only when the target rate can represent the result as an exact integer and the value fits in i64. It never rounds. Comparison, rescaling, and range-end calculation use checked integer arithmetic and report overflow as a domain error.

Time ranges

A TimeRange is half-open: it contains a start and a non-negative duration at the same rate. Its canonical text form is start+duration, for example:

1001@30000/1001+300@30000/1001

end_exclusive computes start plus duration with overflow checking.

Not formatted timecode

Rational time is a mathematical value for exact interchange. It is not a timeline, edit, track, wall-clock timestamp, SMPTE timecode label, or drop-frame formatting rule. Those concepts may map to rational values, but their display and contextual semantics belong in later adapters. PostProject does not infer them from a rate alone.

Across public surfaces

Image-sequence creation carries an exact rational rate and an inclusive, stepped frame range through every public surface:

static pp_error_code_t add_render_sequence(pp_production_t *production,
                                           const pp_asset_id_t *asset_id,
                                           const char *directory,
                                           pp_representation_id_t *out_sequence_id,
                                           pp_error_t **error) {
  const int64_t missing_frames[] = {1003};
  pp_media_source_t *sequence = NULL;
  pp_transaction_t *transaction = NULL;
  pp_representation_set_t *representations = NULL;

  /* Directory and file naming, frame range and step, exact rate, and the
   * frames already known to be missing. */
  const pp_sequence_naming_t naming = {"shot010.", ".exr", 4};
  pp_error_code_t status = pp_media_source_create_image_sequence(
      directory, &naming, 1001, 1004, 1, 24000, 1001, missing_frames, 1,
      &sequence, error);
  if (status == PP_OK) {
    status = pp_production_begin_edit(production, NULL, NULL, &transaction, error);
  }
  if (status == PP_OK) {
    status = pp_transaction_add_representation(
        transaction, *asset_id, PP_REPRESENTATION_DERIVED, sequence,
        out_sequence_id, error);
  }
  pp_media_source_release(sequence);
  if (status == PP_OK) {
    pp_commit_receipt_t commit_receipt;
    status = pp_transaction_commit(transaction, &commit_receipt, error);
  }
  if (status == PP_OK) {
    status = pp_production_representations(production, *asset_id,
                                           &representations, error);
  }
  for (uint64_t index = 0;
       status == PP_OK && index < pp_representation_set_count(representations);
       ++index) {
    pp_representation_id_t id;
    pp_asset_id_t owner;
    pp_representation_kind_t kind;
    pp_content_structure_kind_t structure;
    uint64_t members = 0;
    uint64_t resources = 0;
    uint64_t fingerprints = 0;
    status = pp_representation_set_get(representations, index, &id, &owner,
                                       &kind, &structure, &members, &resources,
                                       &fingerprints, error);
    if (status == PP_OK && structure == PP_CONTENT_IMAGE_SEQUENCE) {
      int64_t start = 0;
      int64_t end = 0;
      uint32_t step = 0;
      uint32_t rate_numerator = 0;
      uint32_t rate_denominator = 0;
      uint64_t missing_count = 0;
      status = pp_representation_set_get_sequence(
          representations, index, &start, &end, &step, &rate_numerator,
          &rate_denominator, &missing_count, error);
      if (status == PP_OK) {
        printf("frames %lld-%lld at %u/%u, %llu known missing\n",
               (long long)start, (long long)end, rate_numerator,
               rate_denominator, (unsigned long long)missing_count);
      }
    }
  }

  pp_representation_set_release(representations);
  pp_transaction_release(transaction);
  return status;
}
postproject::RepresentationId add_render_sequence(postproject::Production &production,
                                      const postproject::AssetId &asset_id,
                                      const std::string &directory) {
  postproject::ImageSequenceInput sequence{};
  sequence.directory = directory;
  sequence.naming = {"shot010.", ".exr", 4};
  sequence.start = 1001;
  sequence.end = 1004;
  sequence.step = 1;
  sequence.rate_numerator = 24000;
  sequence.rate_denominator = 1001;
  sequence.missing_frames = {1003};

  auto transaction = production.edit().value();
  const auto sequence_id = transaction.addRepresentation(
      asset_id, postproject::RepresentationKind::derived,
      postproject::MediaSource::imageSequence(sequence)).value();
  transaction.commit().value();

  for (const auto &representation : production.representations(asset_id).value()) {
    if (representation.id == sequence_id && representation.imageSequence()) {
      const auto &stored = *representation.imageSequence();
      std::cout << "frames " << stored.start << '-' << stored.end << " at "
                << stored.rate_numerator << '/' << stored.rate_denominator
                << ", "
                << stored.missing_frames.size() << " known missing\n";
    }
  }
  return sequence_id;
}
def add_render_sequence(
    production: Production, asset_id: AssetId, directory: Path
) -> RepresentationId:
    with production.edit() as transaction:
        sequence_id = transaction.add_representation(
            asset_id,
            RepresentationKind.DERIVED,
            ImageSequenceSource(
                directory=directory,
                naming=SequenceNaming("shot010.", ".exr", 4),
                start=1001,
                end=1004,
                step=1,
                rate=Fraction(24000, 1001),
                missing_frames=(1003,),
            ),
        )
        transaction.commit()

    stored = next(
        item for item in production.representations[asset_id] if item.id == sequence_id
    )
    sequence = stored.image_sequence
    assert sequence is not None
    print(
        f"frames {sequence.start}-{sequence.end} at "
        f"{sequence.rate_numerator}/{sequence.rate_denominator}, "
        f"{len(sequence.missing_frames)} known missing"
    )
    return sequence_id
fn add_render_sequence(
    production: &mut SqliteProduction,
    asset_id: AssetId,
    directory: &Path,
) -> Result<RepresentationId> {
    let source = ImageSequenceSource::new(
        directory,
        SequenceNaming::new("shot010.", ".exr", 4)?,
        FrameRange::new(1001, 1004, 1)?,
        RationalRate::new(24000, 1001)?,
        vec![1003],
    );
    let import = prepare_representation(asset_id, RepresentationKind::Derived, source)?;
    let sequence_id = import.representation().id();
    {
        let mut transaction = production.begin_transaction()?;
        transaction.add_representation(&import)?;
        transaction.commit()?;
    }

    let stored = production
        .representations(asset_id)?
        .into_iter()
        .find(|representation| representation.id() == sequence_id)
        .expect("committed representation");
    println!("structure: {:?}", stored.content_structure().kind());
    Ok(sequence_id)
}
cat > shot010.json <<'EOF'
{
  "structure": "image_sequence",
  "directory": "renders/shot010",
  "prefix": "shot010.",
  "suffix": ".exr",
  "padding": 4,
  "start": 1001,
  "end": 1004,
  "step": 1,
  "rate_numerator": 24000,
  "rate_denominator": 1001,
  "missing_frames": [1003]
}
EOF
SEQUENCE_ID=$(postproject --json representation add production.pproj \
  "$ASSET_ID" derived shot010.json | jq -r .representation_id)
postproject media show production.pproj "$ASSET_ID"