Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool mi::Work(float *pout, int numsamples, int const mode)
- {
- CSubTickInfo const *psti = pCB->GetSubTickInfo();
- if (psti != NULL && psti->PosInSubTick == 0 && pPlayingPattern != NULL)
- {
- int t = patternPos * (PIANOROLL_TPB / 4) + psti->CurrentSubTick * (PIANOROLL_TPB / 4) / psti->SubTicksPerTick;
- int tn = t + (PIANOROLL_TPB / 4) / psti->SubTicksPerTick;
- //if (pEditorPattern == pPlayingPattern)
- //nd.PlayPos = t;
- if (pPlayingPattern->tracks.size() > 0)
- {
- CMachineTrack &mt = *pPlayingPattern->tracks[0].get();
- vector<MTEvent> e;
- for (MapIntToMTEvent::iterator i = playingNotes.lower_bound(pair<int, int>(t, 0)); i != playingNotes.end() && (*i).first < pair<int, int>(tn, 0); i++)
- pCB->SendMidiNote(TargetMac, 0, (*i).second.D1, 0);
- ::EnterCriticalSection(&nd.PatternCS);
- for (MapIntToMTEvent::iterator i = playingNotes.lower_bound(pair<int, int>(t, 0)); i != playingNotes.end() && (*i).first < pair<int, int>(tn, 0);)
- {
- MapIntToMTEvent::iterator t = i++;
- nd.notesToGUI.push_back(NoteToGUI((*t).second.Off(), false));
- playingNotes.erase(t);
- }
- for (MapIntToMTEvent::const_iterator i = mt.events.lower_bound(pair<int, int>(t, 0)); i != mt.events.end() && (*i).first < pair<int, int>(tn, 0); i++)
- {
- int endt = (*i).first.first + (*i).second.Length;
- if (endt >= tn)
- {
- e.push_back((*i).second);
- playingNotes[pair<int, int>(endt, (*i).first.second)] = (*i).second;
- nd.notesToGUI.push_back(NoteToGUI((*i).second, false));
- }
- }
- if (noteOffRecBuffer.size() > 0)
- {
- for (vector<MTEvent>::iterator i = noteOffRecBuffer.begin(); i != noteOffRecBuffer.end(); i++)
- {
- map<int, MTEvent>::iterator j = recordingNotes.find((*i).D1);
- if (j != recordingNotes.end())
- {
- int len = t - (*j).second.Length;
- len = max(len, tn - t); // <---- maybe not a good idea
- if (len > 0)
- {
- mt.events[pair<int, int>((*j).second.Length, (*j).second.D1)] = MTEvent((*j).second.D1, (*j).second.D2, len);
- nd.recNotesToGUI.push_back(pair<int, MTEvent>((*j).second.Length, MTEvent((*j).second.D1, (*j).second.D2, len)));
- }
- recordingNotes.erase(j);
- }
- }
- noteOffRecBuffer.clear();
- }
- if (noteOnRecBuffer.size() > 0)
- {
- for (vector<MTEvent>::iterator i = noteOnRecBuffer.begin(); i != noteOnRecBuffer.end(); i++)
- recordingNotes[(*i).D1] = MTEvent((*i).D1, (*i).D2, t); // using length to store time
- noteOnRecBuffer.clear();
- }
- ::LeaveCriticalSection(&nd.PatternCS);
- for (int i = 0; i < (int)e.size(); i++)
- pCB->SendMidiNote(TargetMac, 0, e[i].D1, e[i].D2);
- }
- }
- if (psti != NULL && psti->PosInSubTick == 0)
- nd.playingNoteSet->Process(PIANOROLL_TPB / 4 / psti->SubTicksPerTick);
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement