void NameTrackLikeFirstItem(COMMAND_T* ct) { // Get the first item's take MediaItem* item = GetSelectedMediaItem(NULL, 0); if (!item || !GetMediaItemNumTakes(item)) return; MediaItem_Take* take = GetMediaItemTake(item, -1); if (!take) return; // Get the first item's name const char* pName = (const char*)GetSetMediaItemTakeInfo(take, "P_NAME", NULL); if (!pName || !strlen(pName)) return; // Strip out extension char* pNameNoExt = new char[strlen(pName)+1]; strcpy(pNameNoExt, pName); char* pDot = strrchr(pNameNoExt, '.'); if (pDot && IsMediaExtension(pDot+1, false)) *pDot = 0; // Set all sel tracks to that name WDL_TypedBuf<MediaTrack*> tracks; SWS_GetSelectedTracks(&tracks); for (int i = 0; i < tracks.GetSize(); i++) GetSetMediaTrackInfo(tracks.Get()[i], "P_NAME", (void*)pNameNoExt); Undo_OnStateChangeEx(SWS_CMD_SHORTNAME(ct), UNDO_STATE_TRACKCFG, -1); delete [] pNameNoExt; }
void GetSelectedMediaItems(list<MediaItem*> &items) { items.clear(); int itemIdx = 0; while(MediaItem* item = GetSelectedMediaItem(0, itemIdx)) { items.push_back(item); itemIdx++; } }
bool AreThereItemsUnderCursor(bool bSel) { double dCursor = GetCursorPosition(); for (int i = 0; i < (bSel ? CountSelectedMediaItems(0) : CountMediaItems(0)); i++) { MediaItem* item = bSel ? GetSelectedMediaItem(0, i) : GetMediaItem(0, i); double dItemStart = *(double*)GetSetMediaItemInfo(item, "D_POSITION", NULL); double dItemEnd = *(double*)GetSetMediaItemInfo(item, "D_LENGTH", NULL) + dItemStart; if (dItemStart < dCursor && dItemEnd > dCursor) return true; } return false; }
bool AreThereSelItemsInTimeSel() { double t1, t2; GetSet_LoopTimeRange(false, false, &t1, &t2, false); if (t1 != t2) { // see if sel items are in the time selection for (int i = 0; i < CountSelectedMediaItems(0); i++) { MediaItem* item = GetSelectedMediaItem(0, i); double dItemPos = *(double*)GetSetMediaItemInfo(item, "D_POSITION", NULL); double dItemLen = *(double*)GetSetMediaItemInfo(item, "D_LENGTH", NULL); if ((dItemPos >= t1 && dItemPos < t2) || (dItemPos < t1 && dItemLen > t1 - dItemPos)) return true; } } return false; }
void FindItemPeak(COMMAND_T*) { // Just use the first item MediaItem* mi = GetSelectedMediaItem(NULL, 0); if (mi) { ANALYZE_PCM a; memset(&a, 0, sizeof(a)); if (AnalyzeItem(mi, &a)) { double dSrate = ((PCM_source*)mi)->GetSampleRate(); double dPos = *(double*)GetSetMediaItemInfo(mi, "D_POSITION", NULL); dPos += a.peakSample / dSrate; SetEditCurPos(dPos, true, false); } } else MessageBox(NULL, __LOCALIZE("No items selected to analyze.","sws_analysis"), __LOCALIZE("SWS - Error","sws_analysis"), MB_OK); }
SimpleExampleWindow::SimpleExampleWindow(HWND parent, std::string title) : MRPWindow(parent,title) { m_last_project_change_count = GetProjectStateChangeCount(nullptr); m_but1 = std::make_shared<WinButton>(this, "Get take name"); m_but1->GenericNotifyCallback = [this](GenericNotifications) { if (CountSelectedMediaItems(nullptr) > 0) { MediaItem* item = GetSelectedMediaItem(nullptr, 0); MediaItem_Take* take = GetActiveTake(item); if (take != nullptr) { char buf[2048]; GetSetMediaItemTakeInfo_String(take, "P_NAME", buf, false); m_edit1->setText(buf); } } }; add_control(m_but1); m_but2 = std::make_shared<WinButton>(this, "Set take name"); m_but2->GenericNotifyCallback = [this](GenericNotifications) { if (CountSelectedMediaItems(nullptr) > 0) { MediaItem* item = GetSelectedMediaItem(nullptr, 0); MediaItem_Take* take = GetActiveTake(item); if (take != nullptr) { GetSetMediaItemTakeInfo_String(take, "P_NAME", (char*)m_edit1->getText().c_str(), true); UpdateArrange(); } } }; add_control(m_but2); m_but3 = std::make_shared<WinButton>(this, "Refresh item list"); m_but3->GenericNotifyCallback = [this](GenericNotifications) { populate_listbox(); }; add_control(m_but3); m_but4 = std::make_shared<WinButton>(this, "Remove selected listbox item foffoffooo"); m_but4->GenericNotifyCallback = [this](GenericNotifications) { int selindex = m_listbox1->getSelectedIndex(); if (selindex >= 0) { m_listbox1->removeItem(selindex); m_itemmap.erase(m_listbox1->userIDfromIndex(selindex)); } }; add_control(m_but4); m_edit1 = std::make_shared<WinLineEdit>(this, "No take name yet"); add_control(m_edit1); m_listbox1 = std::make_shared<WinListBox>(this); m_listbox1->SelectedChangedCallback = [this](int index) mutable { if (index >= 0) { std::string temp = m_listbox1->getItemText(index); readbg() << "you chose " << temp << " from the listbox\n"; int user_id = m_listbox1->userIDfromIndex(index); MediaItem* itemfromlist = m_itemmap[user_id]; if (ValidatePtr((void*)itemfromlist, "MediaItem*") == true) { m_edit1->setText(std::string("You chose item with mem address " + std::to_string((uint64_t)itemfromlist) + " from the listbox")); } else m_edit1->setText(("You chose an item from listbox that's no longer valid!")); } else readbg() << "you managed to choose no item from the listbox\n"; }; add_control(m_listbox1); add_control(m_listbox1); m_checkbox1 = std::make_shared<WinCheckBox>(this,"The check box"); add_control(m_checkbox1); m_checkbox1->GenericNotifyCallback = [this](GenericNotifications reason) { if (reason == GenericNotifications::Checked) readbg() << "check box was checked\n"; else readbg() << "check box was unchecked\n"; }; m_label1 = std::make_shared<WinLabel>(this, "Ok, will all this text be shown by default...? I wonder..."); add_control(m_label1); m_label1->setTopLeftPosition(150, 60); m_rectcontrol1 = std::make_shared<RectangleTestControl>(this); add_control(m_rectcontrol1); setSize(900, 650); }
void DeleteTempoPreserveItems (COMMAND_T* ct) { BR_Envelope tempoMap(GetTempoEnv()); if (!tempoMap.CountSelected()) return; // Get items' position info and set their timebase to time vector<BR_MidiItemTimePos> items; double firstMarker; tempoMap.GetPoint(tempoMap.GetSelected(0), &firstMarker, NULL, NULL, NULL); int itemCount = ((int)ct->user) ? CountSelectedMediaItems(NULL) : CountMediaItems(NULL); items.reserve(itemCount); for (int i = 0; i < itemCount; ++i) { MediaItem* item = ((int)ct->user) ? GetSelectedMediaItem(NULL, i) : GetMediaItem(NULL, i); double itemEnd = GetMediaItemInfo_Value(item, "D_POSITION") + GetMediaItemInfo_Value(item, "D_LENGTH"); if (itemEnd >= firstMarker) { items.push_back(BR_MidiItemTimePos(item)); SetMediaItemInfo_Value(item, "C_BEATATTACHMODE", 0); } } // Readjust unselected tempo markers double offset = 0; for (int i = 0; i < tempoMap.CountConseq(); ++i) { int startId, endId; tempoMap.GetConseq (i, &startId, &endId); if (endId == tempoMap.Count()-1) continue; // no points after selection, nothing to adjust if (startId == 0 && (++startId > endId)) continue; // skip first point // Get musical length of selection double musicalLen = 0; for (int i = startId - 1; i <= endId; ++i ) { double t0, t1, b0, b1; int s0; tempoMap.GetPoint(i, &t0, &b0, &s0, NULL); tempoMap.GetPoint(i+1, &t1, &b1, NULL, NULL); if (i == startId-1) t0 -= offset; // readjust position to original (earlier iterations moved it) if (s0 == SQUARE) musicalLen += (t1-t0) * b0 / 240; else musicalLen += (t1-t0) * (b0+b1) / 480; } // Readjust points after selection double t0, t1, b0, b1; int s0; tempoMap.GetPoint(startId - 1, &t0, &b0, &s0, NULL); tempoMap.GetPoint(endId + 1, &t1, &b1, NULL, NULL); if (s0 == SQUARE) offset = (t0 + (240*musicalLen) / b0) - t1; else offset = (t0 + (480*musicalLen) / (b0 + b1)) - t1; while (!tempoMap.GetSelection(++endId) && endId < tempoMap.Count()) { double t; tempoMap.GetPoint(endId, &t, NULL, NULL, NULL); t += offset; tempoMap.SetPoint (endId, &t, NULL, NULL, NULL); } } // Delete selected tempo markers int idOffset = 0; for (int i = 0; i < tempoMap.CountSelected(); ++i) { int id = tempoMap.GetSelected(i) - idOffset; if (id != 0) // skip first point { tempoMap.DeletePoint(id); ++idOffset; } } // Commit tempo map and restore position info PreventUIRefresh(1); if (tempoMap.Commit(false)) { for (size_t i = 0; i < items.size(); ++i) items[i].Restore(); Undo_OnStateChangeEx2(NULL, SWS_CMD_SHORTNAME(ct), UNDO_STATE_ALL, -1); } PreventUIRefresh(-1); }
return_null; } return_null; }, "Add a custom (LiceControl) control to window" ); #endif function_entry MRP_ReturnMediaItem("MediaItem*", "", "", [](params) { return_obj(GetSelectedMediaItem(0, 0)); }, "return media item" ); function_entry MRP_DoNothing("void", "", "", [](params) { return_null; }, "do nothing, return null" ); function_entry MRP_DoublePointerAsInt("int", "double,double", "n1,n2", [](params) { double* n1 = (in)arg[0]; double* n2 = (in)arg[1]; return_double(*n1 + *n2);