diff --git a/src/containers/base_sequences.jl b/src/containers/base_sequences.jl index 67dfe5d2de4c80b24efa47acb1a147cf63f906ca..1ff4215ede906f0e1b9f110dcc140525a14f5fcf 100644 --- a/src/containers/base_sequences.jl +++ b/src/containers/base_sequences.jl @@ -33,18 +33,19 @@ function Base.getindex(bs::BaseSequence{N}, index::Integer) where {N} base_index = ((index - 1) % N) + 1 return get_index_single_TR(bs, base_index) end -function Base.getindex(sequence::BaseSequence{N}, time::AbstractFloat) where {N} - time_orig = time + +function (sequence::BaseSequence{N})(time::AbstractFloat) where {N} + var_time = mod(time, duration(sequence)) for block in sequence - time -= duration(block) - if time < 0 - return (time + duration(block), block) + var_time -= duration(block) + if var_time < 0 + return (var_time + duration(block), block) end end - if abs(time) <= 1e-6 - return (duration(sequence[N]) + time, sequence[N]) + if abs(var_time) <= 1e-6 + return (duration(sequence[N]) + var_time, sequence[N]) end - error("Requested time $time_orig is more than the sequence TR ($(TR(sequence)))") + error("Total duration of building blocks does not match duration of the sequence.") end Base.iterate(bs::BaseSequence) = Base.iterate(bs, 1) @@ -117,7 +118,7 @@ end for fn in (:gradient_strength, :amplitude, :phase, :gradient_strength3) @eval function $fn(sequence::BaseSequence, time::AbstractFloat) - (block_time, block) = sequence[time] + (block_time, block) = sequence(time) return $fn(block, block_time) end end