Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void msg(string m) { //debug console
- ShowConsoleMsg(m.c_str()); //string
- ShowConsoleMsg("\n"); //newline
- }
- void main() {
- vector<double> ts, tr, tro, slope, tp, tdss, tdpp;
- MediaItem_Take* active_take;
- int total_sm;
- double take_start_offset, take_playrate, item_pos, item_length;
- auto create_sm = [&](size_t idx) {
- double ruler_pos = ((ts[idx] - take_start_offset)/take_playrate) + item_pos;
- double stored_ecp = GetCursorPosition();
- SetEditCurPos(ruler_pos, 0, 0);
- Main_OnCommandEx(41842, 0, 0);
- SetEditCurPos(stored_ecp, 0, 0);
- };
- ts ={ 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9 };
- tr ={ 0.97, 1.0, 0.99, 0.98, 1.0, 1.03, 1.07, 1.05, 0.98 };
- size_t num_ts = ts.size();
- tro.resize(num_ts+2);
- slope.resize(num_ts+2);
- tp.resize(num_ts+2);
- tdss.resize(num_ts+2);
- tdpp.resize(num_ts+2);
- ts.insert(ts.begin(), 0.0);
- tr.insert(tr.begin(), 0.0);
- Undo_BeginBlock();
- MediaItem* sel_item = GetSelectedMediaItem(0, 0);
- if (sel_item == nullptr) { msg("No selected item"); return; }
- active_take = GetActiveTake(sel_item);
- if (GetTakeNumStretchMarkers(active_take)) { msg("SM already exist"); return; }
- item_pos = GetMediaItemInfo_Value(sel_item, "D_POSITION");
- item_length = GetMediaItemInfo_Value(sel_item, "D_LENGTH");
- take_start_offset = GetMediaItemTakeInfo_Value(active_take, "D_STARTOFFS");
- take_playrate = GetMediaItemTakeInfo_Value(active_take, "D_PLAYRATE");
- //zero-anchor
- if (ts[1] <= 0) ts[0] = ts[1]-1; //zero-anchor SM to left of SM1
- else ts[0] = 0; // zero-anchor SM at 0 (source)
- tro[0] = tr[1]; //zero-anchor SM ro same rate as rate1(no slope)
- slope[0] = 0; //zero-anchor SM flat slope
- tp[0] = ts[0]; //zero-anchor SM P same as its S
- tdss[0] = ts[1]-ts[0]; //zero-anchor SM ΔSS(next S - this S)
- tdpp[0] = tdss[0]/tro[0]; //zero-anchor SM ΔPP = ΔSS/ro
- PreventUIRefresh(1); //prevent UI refresh(hold screen)
- // end-anchor
- ts.push_back(ts[num_ts]+1); //end-anchor SM S at last SM S +1sec
- tr.push_back(tr[num_ts]); //end-anchor SM tr at last SM rate(for array)
- //tro[num_ts+1] = tr[num_ts] //end-anchor SM ro at last SM rate
- slope[num_ts+1] = 0; //end-anchor SM flat slope
- create_sm(0); //create zero-anchor SM using ts, ts as tp, no slope
- for (size_t i = 1; i <= num_ts; ++i) { //loop through table positions and rates, using <= instead of < for 1-based array
- tro[i] = (tr[i]+tr[i+1])/2; //overall rate = mean of r1 and r2 rates for marker
- slope[i] = 1-((2*tr[i])/(tr[i]+tr[i+1])); //slope = function of r1 and r2
- tp[i] = tp[i-1]+tdpp[i-1]; // this P = last P + last ΔPP
- tdss[i] = ts[i+1]-ts[i]; // this ΔSS = next S - this S
- tdpp[i] = tdss[i]/tro[i]; // this ΔPP = ΔSS/ro
- create_sm(i); //create SM using ts, ts as tp, no slope
- }
- tp[num_ts+1] = tp[num_ts]+tdpp[num_ts]; //end-anchor SM P = last P + last ΔPP
- create_sm(num_ts+1); //create end-anchor SM using ts, ts as tp, no slope
- //modify all SM using ts, tp, slope
- for (size_t i = 0; i <= num_ts+1; ++i) {
- SetTakeStretchMarker(active_take, i, tp[i], nullptr);
- SetTakeStretchMarkerSlope(active_take, i, slope[i]);
- }
- PreventUIRefresh(-1); //restore UI refresh
- UpdateArrange(); //redraws the arrange window
- Undo_EndBlock("Create SMs from array", -1); //close undo block and give annotation to undo stack.
- }
Advertisement
Add Comment
Please, Sign In to add comment