From 7c5f799123a52f4460aec482472a1f1d31aae1f4 Mon Sep 17 00:00:00 2001
From: Michiel Cottaar <michiel.cottaar@ndcn.ox.ac.uk>
Date: Tue, 5 Mar 2024 14:28:27 +0000
Subject: [PATCH] Always return events as tuples

---
 src/containers/building_blocks.jl | 4 ++--
 src/parts/trapezoids.jl           | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/containers/building_blocks.jl b/src/containers/building_blocks.jl
index d65db1c..2293399 100644
--- a/src/containers/building_blocks.jl
+++ b/src/containers/building_blocks.jl
@@ -24,7 +24,7 @@ Main interface:
 
 Sub-types need to implement:
 - `Base.keys`: returns sequence of keys to all the components.
-- `Base.getindex`: returns the actual component for each key.
+- `Base.getindex`: returns the actual component for each key. For `events` (readout/pulses) this should return a tuple with `(time delay till start, event)`.
 """
 abstract type BaseBuildingBlock <: ContainerBlock end
 
@@ -42,7 +42,7 @@ Base.getindex(bb::BaseBuildingBlock, s::Symbol) = bb[Val(s)]
 Returns just the non-gradient (i.e., RF pulses/readouts) events as a sequence of [`EventComponent`](@ref) objects (with their keys).
 """
 function events(bb::BaseBuildingBlock)
-    return [(key, bb[key]) for key in keys(bb) if bb[key] isa EventComponent]
+    return [(key, bb[key][2]) for key in keys(bb) if bb[key] isa Tuple{<:Number, <:EventComponent}]
 end
 
 """
diff --git a/src/parts/trapezoids.jl b/src/parts/trapezoids.jl
index 209e606..469f1ba 100644
--- a/src/parts/trapezoids.jl
+++ b/src/parts/trapezoids.jl
@@ -144,7 +144,7 @@ function SliceSelect(pulse::RFPulseComponent; orientation=nothing, rise_time=not
 end
 
 Base.keys(::SliceSelect) = (Val(:rise), Val(:flat), Val(:pulse), Val(:fall))
-Base.getindex(pg::SliceSelect, ::Val{:pulse}) = pg.pulse
+Base.getindex(pg::SliceSelect, ::Val{:pulse}) = (0., pg.pulse)
 
 inverse_slice_thickness(ss::SliceSelect) = 1e3 * gradient_strength(ss.trapezoid) .* inverse_bandwidth(ss.pulse)
 
@@ -189,7 +189,7 @@ function LineReadout(adc::ADC; ramp_overlap=nothing, orientation=nothing, group=
 end
 
 Base.keys(::LineReadout) = (Val(:rise), Val(:adc), Val(:flat), Val(:fall))
-Base.getindex(lr::LineReadout, ::Val{:adc}) = (ramp_overlap(lr) * rise_time(lr), lr.adc)
+Base.getindex(lr::LineReadout, ::Val{:adc}) = ((1 - ramp_overlap(lr)) * rise_time(lr), lr.adc)
 
 ramp_overlap(lr::LineReadout) = lr.ramp_overlap
 inverse_fov(lr::LineReadout) = 1e3 * dwell_time(lr.adc) * gradient_strength(lr.trapezoid) * lr.adc.oversample
-- 
GitLab