View Single Post
Old 08-30-2012, 12:45 PM   #15
Jeffos
Mortal
 
Jeffos's Avatar
 
Join Date: Dec 2008
Location: France
Posts: 1,969
Default

About the original issue/OP (i.e. PCM_Source_CreateFromType and how to generate MIDI events from scratch): I sorted this out thanks to the little clue schwa has posted above..
Quote:
Originally Posted by schwa View Post
There is another undocumented step needed to initialize the state of the MIDI source.
.. which I translated into C like (note_on+note_off example here):
Code:
PCM_source* src = NULL;
const char* state = "HASDATA 1 960 QN\nE 90 90 3d 60\nE 120 80 3d 00\n\nE 1 b1 7b 00\nIGNTEMPO 0 120.00000000 4 4\n>\n"; // <--- make sure the last MIDI evt is a (dummy) CC123!
int len = strlen(state);
WDL_HeapBuf hb;
void* p = hb.Resize(len, false);
if (p && hb.GetSize()==len)
{
  if (src = PCM_Source_CreateFromType("MIDI"))
  {
    memcpy(p, state, len);
    ProjectStateContext* ctx = ProjectCreateMemCtx(&hb);
    if (src->LoadState("<SOURCE MIDI\n", ctx) < 0)
      DELETE_NULL(src);
    delete ctx;
  }
}
Works great The PCM_source can then also be processed with midi_realtime_write_struct_t, etc.. (w/o having to add it to the arrange, i.e. w/o using the new CreateNewMIDIItemInProj)

___________

Hey Drew,
Quote:
does anyone have any info on how to write the state of a MIDI take/item?
this is no big deal in C but I guess you are talking of ReaScript here (?) If so, check out gofer's thread about that: http://forum.cockos.com/showthread.php?t=85951 (w/ a limitation I posted there)
Quote:
This CreateNewMIDIItemInProj call [...] allows me to create the 'container' but not populate it with any MIDI data.
may be you should post the code?
Jeffos is offline   Reply With Quote