Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.80 KB | None | 0 0
  1. bool mi::Work(float *pout, int numsamples, int const mode)
  2. {
  3.     CSubTickInfo const *psti = pCB->GetSubTickInfo();
  4.     if (psti != NULL && psti->PosInSubTick == 0 && pPlayingPattern != NULL)
  5.     {
  6.         int t = patternPos * (PIANOROLL_TPB / 4) + psti->CurrentSubTick * (PIANOROLL_TPB / 4) / psti->SubTicksPerTick;
  7.         int tn = t + (PIANOROLL_TPB / 4) / psti->SubTicksPerTick;
  8.  
  9.         //if (pEditorPattern == pPlayingPattern)
  10.             //nd.PlayPos = t;
  11.  
  12.         if (pPlayingPattern->tracks.size() > 0)
  13.         {
  14.             CMachineTrack &mt = *pPlayingPattern->tracks[0].get();
  15.  
  16.             vector<MTEvent> e;
  17.  
  18.             for (MapIntToMTEvent::iterator i = playingNotes.lower_bound(pair<int, int>(t, 0)); i != playingNotes.end() && (*i).first < pair<int, int>(tn, 0); i++)
  19.                 pCB->SendMidiNote(TargetMac, 0, (*i).second.D1, 0);
  20.  
  21.             ::EnterCriticalSection(&nd.PatternCS);
  22.  
  23.             for (MapIntToMTEvent::iterator i = playingNotes.lower_bound(pair<int, int>(t, 0)); i != playingNotes.end() && (*i).first < pair<int, int>(tn, 0);)
  24.             {
  25.                 MapIntToMTEvent::iterator t = i++;
  26.                 nd.notesToGUI.push_back(NoteToGUI((*t).second.Off(), false));
  27.                 playingNotes.erase(t);
  28.             }
  29.  
  30.             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++)
  31.             {
  32.                 int endt = (*i).first.first + (*i).second.Length;
  33.                 if (endt >= tn)
  34.                 {
  35.                     e.push_back((*i).second);
  36.                     playingNotes[pair<int, int>(endt, (*i).first.second)] = (*i).second;
  37.                     nd.notesToGUI.push_back(NoteToGUI((*i).second, false));
  38.                 }
  39.             }
  40.  
  41.             if (noteOffRecBuffer.size() > 0)
  42.             {
  43.                 for (vector<MTEvent>::iterator i = noteOffRecBuffer.begin(); i != noteOffRecBuffer.end(); i++)
  44.                 {
  45.                     map<int, MTEvent>::iterator j = recordingNotes.find((*i).D1);
  46.                     if (j != recordingNotes.end())
  47.                     {
  48.                         int len = t - (*j).second.Length;
  49.                         len = max(len, tn - t); // <---- maybe not a good idea
  50.                         if (len > 0)
  51.                         {
  52.                             mt.events[pair<int, int>((*j).second.Length, (*j).second.D1)] = MTEvent((*j).second.D1, (*j).second.D2, len);
  53.                             nd.recNotesToGUI.push_back(pair<int, MTEvent>((*j).second.Length, MTEvent((*j).second.D1, (*j).second.D2, len)));
  54.                         }
  55.  
  56.                         recordingNotes.erase(j);
  57.                     }
  58.  
  59.                 }
  60.  
  61.                 noteOffRecBuffer.clear();
  62.             }
  63.  
  64.             if (noteOnRecBuffer.size() > 0)
  65.             {
  66.                 for (vector<MTEvent>::iterator i = noteOnRecBuffer.begin(); i != noteOnRecBuffer.end(); i++)
  67.                     recordingNotes[(*i).D1] = MTEvent((*i).D1, (*i).D2, t); // using length to store time
  68.  
  69.                 noteOnRecBuffer.clear();
  70.             }
  71.  
  72.             ::LeaveCriticalSection(&nd.PatternCS);
  73.        
  74.             for (int i = 0; i < (int)e.size(); i++)
  75.                 pCB->SendMidiNote(TargetMac, 0, e[i].D1, e[i].D2);
  76.  
  77.         }
  78.     }
  79.  
  80.     if (psti != NULL && psti->PosInSubTick == 0)
  81.         nd.playingNoteSet->Process(PIANOROLL_TPB / 4 / psti->SubTicksPerTick);
  82.  
  83.     return false;
  84.  
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement