|
|
|
04-12-2012, 04:27 PM
|
#1
|
Human being with feelings
Join Date: Feb 2012
Posts: 26
|
About PCM_Source_CreateFromType("MIDI")...
Hi,
I am trying to create multiple takes with multiple midi sources in a track with C++ codes, like this:
Code:
// add a media item
MediaItem* newMediaItem = AddMediaItemToTrack(newReaperTrack);
GetSetMediaItemInfo(newMediaItem, "D_POSITION", &startTime);
GetSetMediaItemInfo(newMediaItem, "D_LENGTH", &length);
PCM_source* newSource = PCM_Source_CreateFromType("MIDI");
// add a take
MediaItem_Take* newTake = AddTakeToMediaItem(newMediaItem);
GetSetMediaItemTakeInfo(newTake, "P_NAME", (void*)name);
GetSetMediaItemTakeInfo(newTake, "P_SOURCE", (void*)newSource);
GetSetMediaItemTakeInfo(newTake, "D_STARTOFFS", &startTime);
After I compiled the codes and put the plugin in reaper, it did create a new media item. However, there is a weird string of "offline" in the middle of that media item, and I cannot open it with the midi editor.
What does that mean? How do I fix it?
Also, when I search in SWS codes, there is only one place that use PCM_Source_CreateFromType(), and it's commented out. The comment says, "JFB!!! commented: generating evts from scratch does not work, unfortunately.. nailed it down to PCM_Source_CreateFromType("MIDI") which seems to be KO (?)". Does that mean this API function is not even working properly?
Thank you.
Last edited by KarlLai; 04-17-2012 at 02:12 PM.
|
|
|
04-17-2012, 05:28 AM
|
#2
|
Administrator
Join Date: Mar 2007
Location: NY
Posts: 15,750
|
There is another undocumented step needed to initialize the state of the MIDI source. For ease of use, we will add a new API function in the next REAPER prerelease build:
Code:
MediaItem* CreateNewMIDIItemInProj(double starttime, double endtime);
|
|
|
04-17-2012, 10:31 AM
|
#3
|
Human being with feelings
Join Date: Feb 2012
Posts: 26
|
Quote:
Originally Posted by schwa
There is another undocumented step needed to initialize the state of the MIDI source. For ease of use, we will add a new API function in the next REAPER prerelease build:
Code:
MediaItem* CreateNewMIDIItemInProj(double starttime, double endtime);
|
Thank you
For now, should I just wait for the new API or there is a way to initialize the state properly?
|
|
|
04-17-2012, 11:39 AM
|
#5
|
Human being with feelings
Join Date: Feb 2012
Posts: 26
|
Quote:
Originally Posted by schwa
|
COOL! Thanks a lot
|
|
|
04-17-2012, 01:52 PM
|
#6
|
Human being with feelings
Join Date: Feb 2012
Posts: 26
|
Quote:
Originally Posted by schwa
|
Sorry but another question... What is the proper way to link this new midi item to a track? Is MoveMediaItemToTrack() the right one?
Last edited by KarlLai; 04-17-2012 at 02:02 PM.
|
|
|
04-27-2012, 06:58 AM
|
#7
|
Administrator
Join Date: Mar 2007
Location: NY
Posts: 15,750
|
Oh, you wanted to add the MIDI item to a track? <ahem>
We will change the new API function to take a MediaTrack parameter as well.
|
|
|
05-06-2012, 07:26 AM
|
#8
|
Mortal
Join Date: Dec 2008
Location: France
Posts: 1,969
|
Quote:
Originally Posted by KarlLai
Sad... There is no change in pre7......
|
The generated .h is not up-to-date but the func is indeed there. It will work if you redefine it as:
Code:
REAPERAPI_DECL MediaItem* (*CreateNewMIDIItemInProj)(MediaTrack* track, double starttime, double endtime);
Quote:
Originally Posted by KarlLai
commented: generating evts from scratch does not work, unfortunately.. nailed it down to PCM_Source_CreateFromType("MIDI") which seems to be KO (?)
|
This comment is from me. I workarounded that but I would like to know that "undocumented step needed to initialize the state of the MIDI source" schwa talked about! Note: in my case I just want to create a PCM_source from scratch and fill it with midi_realtime_write_struct_t (I do not plan to insert it as take/item the arrange).
|
|
|
05-07-2012, 04:47 PM
|
#9
|
Human being with feelings
Join Date: Feb 2012
Posts: 26
|
@Jeffos: Thank you for letting me know! Yeah I should also check the update notes.
What I am doing is: I want to create a track, create a media item, and then insert midi events into the media item. For now I just create a simple and empty midi file at runtime and call PCM_Source_CreateFromFile(). It works but it's totally a hack.
I will try the new API after the next stable version is out, since my customer are not using the pre versions at their work
|
|
|
06-11-2012, 05:01 AM
|
#10
|
Mobile
Join Date: Jan 2006
Location: London & São Paulo. Hardcore commercial REAPERite
Posts: 1,669
|
Just to check on the latest situation re MIDI take creation on the fly, am I right to say it is still not possible to alter the textual state of an item or individual take in the way that we can change track state?
I managed to get CreateNewMIDIItemInProj working in ReaScript by changing that definition in reaper_python.py from
Code:
a=_ft['CreateNewMIDIItemInProj']
f=CFUNCTYPE(c_uint64,c_double,c_double)(a)
t=(c_double(p0),c_double(p1))
r=f(t[0],t[1])
to
Code:
a=_ft['CreateNewMIDIItemInProj']
f=CFUNCTYPE(c_uint64,c_uint64,c_double,c_double)(a)
t=(rpr_packp('MediaTrack*',p0),c_double(p1),c_double(p2))
r=f(t[0],t[1],t[2])
As a result it now works with the updated version of the schwa's call (the one which starts with MediaTrack parameter), but there still doesn't seem to be a way to write MIDI events to it in ReaScript.
Could there either be a call to trigger a new live item state after setting it using the existing GetSetItemState call, or maybe something on a per-take basis like a P_SOURCEMIDI call that could be read & written with GetSetMediaItemTakeInfo_String to allow us to write/overwrite MIDI data?
Thanks
Drew
__________________
Proudly using REAPER exclusively for...
* Media and event music composition & production, sound design + auto-processing at Qsonics.com
* Broadcast branding, promos, education & training and narration voice-overs at DrewWhite.com
|
|
|
08-28-2012, 01:17 PM
|
#11
|
Mobile
Join Date: Jan 2006
Location: London & São Paulo. Hardcore commercial REAPERite
Posts: 1,669
|
a little bumpity... does anyone have any info on how to write the state of a MIDI take/item? This CreateNewMIDIItemInProj call (which still shows as only start & end time parameters in ReaScript help, by the way) allows me to create the 'container' but not populate it with any MIDI data.
At the moment I'm creating a dummy track with an item (by writing track state) and then moving the item, before deleting that track - but this is quite a workaround!
Thanks
Drew
__________________
Proudly using REAPER exclusively for...
* Media and event music composition & production, sound design + auto-processing at Qsonics.com
* Broadcast branding, promos, education & training and narration voice-overs at DrewWhite.com
|
|
|
08-30-2012, 12:45 PM
|
#12
|
Mortal
Join Date: Dec 2008
Location: France
Posts: 1,969
|
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
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?
|
|
|
Thread Tools |
|
Display Modes |
Hybrid Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -7. The time now is 09:35 PM.
|