MCPcopy Create free account
hub / github.com/audacity/audacity / DoAlign

Function DoAlign

src/menus/TrackMenus.cpp:169–295  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

167const size_t kAlignLabelsCount(){ return alignLabels().size(); }
168
169void DoAlign(AudacityProject &project, int index, bool moveSel)
170{
171 auto &tracks = TrackList::Get( project );
172 auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
173 auto &viewport = Viewport::Get(project);
174
175 TranslatableString action, shortAction;
176 double delta = 0.0;
177 double newPos = -1.0;
178
179 auto trackRange = tracks.Selected<AudioTrack>();
180
181 auto FindOffset =
182 [](const Track *pTrack) { return pTrack->GetStartTime(); };
183
184 auto firstTrackOffset = [&]{ return FindOffset( *trackRange.begin() ); };
185 auto minOffset = [&]{ return trackRange.min( FindOffset ); };
186 auto avgOffset = [&]{
187 return trackRange.sum( FindOffset ) /
188 std::max( size_t(1), trackRange.size() ); };
189
190 auto maxEndOffset = [&]{
191 return std::max(0.0, trackRange.max(&Track::GetEndTime)); };
192
193 switch(index) {
194 case kAlignStartZero:
195 delta = -minOffset();
196 action = moveSel
197 /* i18n-hint: In this and similar messages describing editing actions,
198 the starting or ending points of tracks are re-"aligned" to other
199 times, and the time selection may be "moved" too. The first
200 noun -- "start" in this example -- is the object of a verb (not of
201 an implied preposition "from"). */
202 ? XO("Aligned/Moved start to zero")
203 : XO("Aligned start to zero");
204 shortAction = moveSel
205 /* i18n-hint: This and similar messages give shorter descriptions of
206 the aligning and moving editing actions */
207 ? XO("Align/Move Start")
208 : XO("Align Start");
209 break;
210 case kAlignStartSelStart:
211 delta = selectedRegion.t0() - minOffset();
212 action = moveSel
213 ? XO("Aligned/Moved start to cursor/selection start")
214 : XO("Aligned start to cursor/selection start");
215 shortAction = moveSel
216 ? XO("Align/Move Start")
217 : XO("Align Start");
218 break;
219 case kAlignStartSelEnd:
220 delta = selectedRegion.t1() - minOffset();
221 action = moveSel
222 ? XO("Aligned/Moved start to selection end")
223 : XO("Aligned start to selection end");
224 shortAction = moveSel
225 ? XO("Align/Move Start")
226 : XO("Align Start");

Callers 2

OnAlignNoSyncFunction · 0.85
OnAlignFunction · 0.85

Calls 15

GetFunction · 0.85
maxFunction · 0.85
kAlignLabelsCountFunction · 0.85
minMethod · 0.80
sumMethod · 0.80
maxMethod · 0.80
ZoomFitHorizontallyMethod · 0.80
moveMethod · 0.80
GetStartTimeMethod · 0.45
beginMethod · 0.45
sizeMethod · 0.45
MoveToMethod · 0.45

Tested by

no test coverage detected