Skip to content
Snippets Groups Projects
Verified Commit 008e1602 authored by Michiel Cottaar's avatar Michiel Cottaar
Browse files

Call sequence with time rather than index

parent 8536d7f4
No related branches found
No related tags found
No related merge requests found
...@@ -33,18 +33,19 @@ function Base.getindex(bs::BaseSequence{N}, index::Integer) where {N} ...@@ -33,18 +33,19 @@ function Base.getindex(bs::BaseSequence{N}, index::Integer) where {N}
base_index = ((index - 1) % N) + 1 base_index = ((index - 1) % N) + 1
return get_index_single_TR(bs, base_index) return get_index_single_TR(bs, base_index)
end 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 for block in sequence
time -= duration(block) var_time -= duration(block)
if time < 0 if var_time < 0
return (time + duration(block), block) return (var_time + duration(block), block)
end end
end end
if abs(time) <= 1e-6 if abs(var_time) <= 1e-6
return (duration(sequence[N]) + time, sequence[N]) return (duration(sequence[N]) + var_time, sequence[N])
end 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 end
Base.iterate(bs::BaseSequence) = Base.iterate(bs, 1) Base.iterate(bs::BaseSequence) = Base.iterate(bs, 1)
...@@ -117,7 +118,7 @@ end ...@@ -117,7 +118,7 @@ end
for fn in (:gradient_strength, :amplitude, :phase, :gradient_strength3) for fn in (:gradient_strength, :amplitude, :phase, :gradient_strength3)
@eval function $fn(sequence::BaseSequence, time::AbstractFloat) @eval function $fn(sequence::BaseSequence, time::AbstractFloat)
(block_time, block) = sequence[time] (block_time, block) = sequence(time)
return $fn(block, block_time) return $fn(block, block_time)
end end
end end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment