MCPcopy Create free account
hub / github.com/BespokeSynth/BespokeSynth / OnTransportAdvanced

Method OnTransportAdvanced

Source/NoteCanvas.cpp:144–255  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

142}
143
144void NoteCanvas::OnTransportAdvanced(float amount)
145{
146 PROFILER(NoteCanvas);
147
148 if (mFreeRecord && mFreeRecordStartMeasure != -1)
149 {
150 if (TheTransport->GetMeasurePos(gTime) < amount &&
151 !FreeRecordParityMatched())
152 {
153 int oldNumMeasures = mNumMeasures;
154 while (!FreeRecordParityMatched())
155 mNumMeasures *= 2;
156 int shift = mFreeRecordStartMeasure % mNumMeasures - mFreeRecordStartMeasure % oldNumMeasures;
157 SetNumMeasures(mNumMeasures);
158
159 for (auto* element : mCanvas->GetElements())
160 element->SetStart(element->GetStart() + float(shift) / mNumMeasures, true);
161 }
162 }
163
164 if (mStopQueued)
165 {
166 mNoteOutput.Flush(NextBufferTime(false));
167 for (int i = 0; i < mCurrentNotes.size(); ++i)
168 mCurrentNotes[i] = nullptr;
169 mStopQueued = false;
170 }
171
172 if (!mEnabled || !mPlay)
173 {
174 mCanvas->SetCursorPos(-1);
175 return;
176 }
177
178 double cursorPlayTime = gTime;
179 //if (Transport::sDoEventLookahead)??? should we?
180 // cursorPlayTime += Transport::sEventEarlyMs;
181 //else
182 cursorPlayTime += amount * TheTransport->MsPerBar();
183 double curPos = GetCurPos(cursorPlayTime);
184
185 mCanvas->FillElementsAt(curPos, mNoteChecker);
186 for (int i = 0; i < 128; ++i)
187 {
188 int pitch = 128 - i - 1;
189 bool wasOn = mCurrentNotes[pitch] != nullptr || mInputNotes[pitch];
190 bool nowOn = mNoteChecker[i] != nullptr || mInputNotes[pitch];
191 bool hasChanged = (nowOn || wasOn) && mCurrentNotes[pitch] != static_cast<NoteCanvasElement*>(mNoteChecker[i]);
192
193 if (wasOn && mInputNotes[pitch] == nullptr && hasChanged)
194 {
195 //note off
196 if (mCurrentNotes[pitch])
197 {
198 double cursorAdvanceSinceEvent = curPos - mCurrentNotes[pitch]->GetEnd();
199 if (cursorAdvanceSinceEvent < 0)
200 cursorAdvanceSinceEvent += 1;
201 double time = cursorPlayTime - cursorAdvanceSinceEvent * TheTransport->MsPerBar() * mNumMeasures;

Callers

nothing calls this directly

Calls 15

NextBufferTimeFunction · 0.85
SetStartMethod · 0.80
GetStartMethod · 0.80
sizeMethod · 0.80
SetCursorPosMethod · 0.80
MsPerBarMethod · 0.80
FillElementsAtMethod · 0.80
GetEndMethod · 0.80
GetVoiceIdxMethod · 0.80
GetVelocityMethod · 0.80
SetEndMethod · 0.80
WriteModulationMethod · 0.80

Tested by

no test coverage detected