SHOW:
|
|
- or go back to the newest paste.
| 1 | void msg(string m) { //debug console
| |
| 2 | ShowConsoleMsg(m.c_str()); //string | |
| 3 | ShowConsoleMsg("\n"); //newline
| |
| 4 | } | |
| 5 | ||
| 6 | void main() {
| |
| 7 | - | // define stuff at the top to make it easier for lambda functions |
| 7 | + | |
| 8 | MediaItem_Take* active_take; | |
| 9 | int total_sm; | |
| 10 | double take_start_offset, take_playrate, item_pos, item_length; | |
| 11 | ||
| 12 | auto create_sm = [&](size_t idx) {
| |
| 13 | - | // lambda functions |
| 13 | + | |
| 14 | - | function<void(size_t)> create_sm = [&](size_t idx) { //use item_pos, item_playrate, item length, source_pos to get ruler positions of SM
|
| 14 | + | double stored_ecp = GetCursorPosition(); |
| 15 | SetEditCurPos(ruler_pos, 0, 0); | |
| 16 | - | double stored_ecp = GetCursorPosition(); //store cursor |
| 16 | + | |
| 17 | - | SetEditCurPos(ruler_pos, 0, 0); //move cursor to ruler-time S-pos |
| 17 | + | Main_OnCommandEx(41842, 0, 0); |
| 18 | - | // create SM(blank default, using S, S for P and no slope) |
| 18 | + | SetEditCurPos(stored_ecp, 0, 0); |
| 19 | - | Main_OnCommandEx(41842, 0, 0); //create SM at edit cursor |
| 19 | + | |
| 20 | - | SetEditCurPos(stored_ecp, 0, 0); //restore cursor |
| 20 | + | |
| 21 | ts ={ 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9 };
| |
| 22 | tr ={ 0.97, 1.0, 0.99, 0.98, 1.0, 1.03, 1.07, 1.05, 0.98 };
| |
| 23 | - | function<void(size_t)> modify_sm = [&](size_t idx) {
|
| 23 | + | |
| 24 | - | //write to SM(idx) calculated P |
| 24 | + | size_t num_ts = ts.size(); |
| 25 | - | int retval = SetTakeStretchMarker(active_take, idx, tp[idx], nullptr); //sets P point, no slope yet |
| 25 | + | |
| 26 | - | // write slope to SM slope |
| 26 | + | tro.resize(num_ts+2); |
| 27 | - | retval = SetTakeStretchMarkerSlope(active_take, idx, slope[idx]); //write corrected slopes |
| 27 | + | slope.resize(num_ts+2); |
| 28 | tp.resize(num_ts+2); | |
| 29 | tdss.resize(num_ts+2); | |
| 30 | - | ts ={ 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9 }; // 1-based, SM S-pos table
|
| 30 | + | tdpp.resize(num_ts+2); |
| 31 | - | tr ={ 0.97, 1.0, 0.99, 0.98, 1.0, 1.03, 1.07, 1.05, 0.98 }; // 1-based, SM rate table
|
| 31 | + | |
| 32 | - | size_t num_ts = ts.size(); // length of array as input above, +1 to handle 1-based table, +1 for end anchor |
| 32 | + | ts.insert(ts.begin(), 0.0); |
| 33 | - | // check #ts == #tp at this point? |
| 33 | + | tr.insert(tr.begin(), 0.0); |
| 34 | - | tro.resize(num_ts+2); //SM ro table |
| 34 | + | |
| 35 | - | slope.resize(num_ts+2); //SM slope table |
| 35 | + | Undo_BeginBlock(); |
| 36 | - | tp.resize(num_ts+2); //SM P-pos table |
| 36 | + | |
| 37 | - | tdss.resize(num_ts+2); //SM ΔSS table |
| 37 | + | MediaItem* sel_item = GetSelectedMediaItem(0, 0); |
| 38 | - | tdpp.resize(num_ts+2); //SM ΔPP table |
| 38 | + | |
| 39 | - | |
| 39 | + | if (sel_item == nullptr) { msg("No selected item"); return; }
|
| 40 | - | ts.insert(ts.begin(), 0); // make one more index to deal with 1-based arrays |
| 40 | + | |
| 41 | - | tr.insert(tr.begin(), 0); |
| 41 | + | active_take = GetActiveTake(sel_item); |
| 42 | - | ts.push_back(0.0); // add one more index to hold the end anchor |
| 42 | + | |
| 43 | - | tr.push_back(0.0); |
| 43 | + | if (GetTakeNumStretchMarkers(active_take)) { msg("SM already exist"); return; }
|
| 44 | ||
| 45 | - | Undo_BeginBlock(); //Hold undo block to all of proj altering code... |
| 45 | + | item_pos = GetMediaItemInfo_Value(sel_item, "D_POSITION"); |
| 46 | - | MediaItem* sel_item = GetSelectedMediaItem(0, 0); //selected item |
| 46 | + | item_length = GetMediaItemInfo_Value(sel_item, "D_LENGTH"); |
| 47 | - | if (( (sel_item != nullptr) & CountSelectedMediaItems(0) ) == 1) {
|
| 47 | + | take_start_offset = GetMediaItemTakeInfo_Value(active_take, "D_STARTOFFS"); |
| 48 | - | // collect parameter on sel item and active take for SM decisions and S-pos to ruler-time conversion |
| 48 | + | take_playrate = GetMediaItemTakeInfo_Value(active_take, "D_PLAYRATE"); |
| 49 | - | active_take = GetActiveTake(sel_item); //active take in item |
| 49 | + | |
| 50 | - | total_sm = GetTakeNumStretchMarkers(active_take); //count SM in take |
| 50 | + | //zero-anchor |
| 51 | - | item_pos = GetMediaItemInfo_Value(sel_item, "D_POSITION"); //item pos in timeline |
| 51 | + | if (ts[1] <= 0) ts[0] = ts[1]-1; //zero-anchor SM to left of SM1 |
| 52 | - | item_length = GetMediaItemInfo_Value(sel_item, "D_LENGTH"); //item length |
| 52 | + | else ts[0] = 0; // zero-anchor SM at 0 (source) |
| 53 | - | take_start_offset = GetMediaItemTakeInfo_Value(active_take, "D_STARTOFFS"); //take start offset |
| 53 | + | tro[0] = tr[1]; //zero-anchor SM ro same rate as rate1(no slope) |
| 54 | - | take_playrate = GetMediaItemTakeInfo_Value(active_take, "D_PLAYRATE"); //take playrate(will combine with SM warping) |
| 54 | + | slope[0] = 0; //zero-anchor SM flat slope |
| 55 | - | if (total_sm == 0) {
|
| 55 | + | tp[0] = ts[0]; //zero-anchor SM P same as its S |
| 56 | - | PreventUIRefresh(1); //prevent UI refresh(hold screen) |
| 56 | + | tdss[0] = ts[1]-ts[0]; //zero-anchor SM ΔSS(next S - this S) |
| 57 | - | //zero-anchor |
| 57 | + | tdpp[0] = tdss[0]/tro[0]; //zero-anchor SM ΔPP = ΔSS/ro |
| 58 | - | if (ts[1] <= 0) ts[0] = ts[1]-1; //zero-anchor SM to left of SM1 |
| 58 | + | |
| 59 | - | else ts[0] = 0; // zero-anchor SM at 0 (source) |
| 59 | + | PreventUIRefresh(1); //prevent UI refresh(hold screen) |
| 60 | ||
| 61 | - | tro[0] = tr[1]; //zero-anchor SM ro same rate as rate1(no slope) |
| 61 | + | // end-anchor |
| 62 | - | slope[0] = 0; //zero-anchor SM flat slope |
| 62 | + | ts.push_back(ts[num_ts]+1); //end-anchor SM S at last SM S +1sec |
| 63 | - | tp[0] = ts[0]; //zero-anchor SM P same as its S |
| 63 | + | tr.push_back(tr[num_ts]); //end-anchor SM tr at last SM rate(for array) |
| 64 | - | tdss[0] = ts[1]-ts[0]; //zero-anchor SM ΔSS(next S - this S) |
| 64 | + | //tro[num_ts+1] = tr[num_ts] //end-anchor SM ro at last SM rate |
| 65 | - | tdpp[0] = tdss[0]/tro[0]; //zero-anchor SM ΔPP = ΔSS/ro |
| 65 | + | slope[num_ts+1] = 0; //end-anchor SM flat slope |
| 66 | - | // end-anchor |
| 66 | + | create_sm(0); //create zero-anchor SM using ts, ts as tp, no slope |
| 67 | - | ts[num_ts+1] = ts[num_ts]+1; //end-anchor SM S at last SM S +1sec |
| 67 | + | |
| 68 | - | tr[num_ts+1] = tr[num_ts]; //end-anchor SM tr at last SM rate(for array) |
| 68 | + | for (size_t i = 1; i <= num_ts; ++i) { //loop through table positions and rates, using <= instead of < for 1-based array
|
| 69 | - | //tro[num_ts+1] = tr[num_ts] //end-anchor SM ro at last SM rate |
| 69 | + | tro[i] = (tr[i]+tr[i+1])/2; //overall rate = mean of r1 and r2 rates for marker |
| 70 | - | slope[num_ts+1] = 0; //end-anchor SM flat slope |
| 70 | + | slope[i] = 1-((2*tr[i])/(tr[i]+tr[i+1])); //slope = function of r1 and r2 |
| 71 | tp[i] = tp[i-1]+tdpp[i-1]; // this P = last P + last ΔPP | |
| 72 | - | create_sm(0); //create zero-anchor SM using ts, ts as tp, no slope |
| 72 | + | tdss[i] = ts[i+1]-ts[i]; // this ΔSS = next S - this S |
| 73 | tdpp[i] = tdss[i]/tro[i]; // this ΔPP = ΔSS/ro | |
| 74 | - | for (size_t i = 1; i <= num_ts; ++i) { //loop through table positions and rates, using <= instead of < for 1-based array
|
| 74 | + | create_sm(i); //create SM using ts, ts as tp, no slope |
| 75 | - | tro[i] = (tr[i]+tr[i+1])/2; //overall rate = mean of r1 and r2 rates for marker |
| 75 | + | |
| 76 | - | slope[i] = 1-((2*tr[i])/(tr[i]+tr[i+1])); //slope = function of r1 and r2 |
| 76 | + | |
| 77 | - | tp[i] = tp[i-1]+tdpp[i-1]; // this P = last P + last ΔPP |
| 77 | + | tp[num_ts+1] = tp[num_ts]+tdpp[num_ts]; //end-anchor SM P = last P + last ΔPP |
| 78 | - | tdss[i] = ts[i+1]-ts[i]; // this ΔSS = next S - this S |
| 78 | + | create_sm(num_ts+1); //create end-anchor SM using ts, ts as tp, no slope |
| 79 | - | tdpp[i] = tdss[i]/tro[i]; // this ΔPP = ΔSS/ro |
| 79 | + | |
| 80 | - | create_sm(i); //create SM using ts, ts as tp, no slope |
| 80 | + | //modify all SM using ts, tp, slope |
| 81 | - | } |
| 81 | + | for (size_t i = 0; i <= num_ts+1; ++i) {
|
| 82 | SetTakeStretchMarker(active_take, i, tp[i], nullptr); | |
| 83 | - | tp[num_ts+1] = tp[num_ts]+tdpp[num_ts]; //end-anchor SM P = last P + last ΔPP |
| 83 | + | SetTakeStretchMarkerSlope(active_take, i, slope[i]); |
| 84 | - | create_sm(num_ts+1); //create end-anchor SM using ts, ts as tp, no slope |
| 84 | + | |
| 85 | ||
| 86 | - | for (size_t i = 0; i <= num_ts+1; ++i) { //using <= instead of < for 1-based array
|
| 86 | + | PreventUIRefresh(-1); //restore UI refresh |
| 87 | - | modify_sm(i); //modify all SM using ts, tp, slope |
| 87 | + | UpdateArrange(); //redraws the arrange window |
| 88 | - | } |
| 88 | + | |
| 89 | - | PreventUIRefresh(-1); //restore UI refresh |
| 89 | + |