bool FindWnd::FindTrack(int _dir, bool (*job)(MediaTrack*,const char*)) { bool update = false, found = false; if (g_searchStr && *g_searchStr) { int startTrIdx = -1; bool clearCurrentSelection = false; if (_dir) { if (int selTracksCount = SNM_CountSelectedTracks(NULL, true)) { if (MediaTrack* startTr = SNM_GetSelectedTrack(NULL, _dir > 0 ? 0 : selTracksCount-1, true)) { int id = CSurf_TrackToID(startTr, false); if ((_dir > 0 && id < CountTracks(NULL)) || (_dir < 0 && id >0)) { startTrIdx = id + _dir; clearCurrentSelection = true; } } } else startTrIdx = (_dir > 0 ? 0 : CountTracks(NULL)); } else { startTrIdx = 0; clearCurrentSelection = true; } if (clearCurrentSelection) { Undo_BeginBlock2(NULL); Main_OnCommand(40297,0); // unselect all tracks update = true; } if (startTrIdx >= 0) { for (int i = startTrIdx; i <= CountTracks(NULL) && i>=0; i += (!_dir ? 1 : _dir)) { MediaTrack* tr = CSurf_TrackFromID(i, false); if (tr && job(tr, g_searchStr)) { if (!update) Undo_BeginBlock2(NULL); update = found = true; GetSetMediaTrackInfo(tr, "I_SELECTED", &g_i1); if (_dir) break; } } } UpdateNotFoundMsg(found); if (found) ScrollSelTrack(true, true); } if (update) Undo_EndBlock2(NULL, __LOCALIZE("Find: change track selection","sws_undo"), UNDO_STATE_ALL); return update; }
// _type: 0=Post-Fader (Post-Pan), 1=Pre-FX, 2=deprecated, 3=Pre-Fader (Post-FX) // _undoMsg: NULL=no undo bool CueBuss(const char* _undoMsg, const char* _busName, int _type, bool _showRouting, int _soloDefeat, char* _trTemplatePath, bool _sendToMaster, int* _hwOuts) { if (!SNM_CountSelectedTracks(NULL, false)) return false; WDL_FastString tmplt; if (_trTemplatePath && (!FileOrDirExists(_trTemplatePath) || !LoadChunk(_trTemplatePath, &tmplt) || !tmplt.GetLength())) { char msg[SNM_MAX_PATH] = ""; lstrcpyn(msg, __LOCALIZE("Cue buss not created!\nNo track template file defined","sws_DLG_149"), sizeof(msg)); if (*_trTemplatePath) _snprintfSafe(msg, sizeof(msg), __LOCALIZE_VERFMT("Cue buss not created!\nTrack template not found (or empty): %s","sws_DLG_149"), _trTemplatePath); MessageBox(GetMainHwnd(), msg, __LOCALIZE("S&M - Error","sws_DLG_149"), MB_OK); return false; } bool updated = false; MediaTrack * cueTr = NULL; SNM_SendPatcher* p = NULL; for (int i=1; i <= GetNumTracks(); i++) // skip master { MediaTrack* tr = CSurf_TrackFromID(i, false); if (tr && *(int*)GetSetMediaTrackInfo(tr, "I_SELECTED", NULL)) { GetSetMediaTrackInfo(tr, "I_SELECTED", &g_i0); // add the buss track, done once! if (!cueTr) { InsertTrackAtIndex(GetNumTracks(), false); TrackList_AdjustWindows(false); cueTr = CSurf_TrackFromID(GetNumTracks(), false); GetSetMediaTrackInfo(cueTr, "P_NAME", (void*)_busName); p = new SNM_SendPatcher(cueTr); if (tmplt.GetLength()) { WDL_FastString chunk; MakeSingleTrackTemplateChunk(&tmplt, &chunk, true, true, false); ApplyTrackTemplate(cueTr, &chunk, false, false, p); } updated = true; } // add a send if (cueTr && p && tr != cueTr) AddReceiveWithVolPan(tr, cueTr, _type, p); } } if (cueTr && p) { // send to master/parent init if (!tmplt.GetLength()) { // solo defeat if (_soloDefeat) { char one[2] = "1"; updated |= (p->ParsePatch(SNM_SET_CHUNK_CHAR, 1, "TRACK", "MUTESOLO", 0, 3, one) > 0); } // master/parend send WDL_FastString mainSend; mainSend.SetFormatted(SNM_MAX_CHUNK_LINE_LENGTH, "MAINSEND %d 0", _sendToMaster?1:0); // adds hw outputs if (_hwOuts) { int monoHWCount=0; while (GetOutputChannelName(monoHWCount)) monoHWCount++; bool cr = false; for(int i=0; i<SNM_MAX_HW_OUTS; i++) { if (_hwOuts[i]) { if (!cr) { mainSend.Append("\n"); cr = true; } if (_hwOuts[i] >= monoHWCount) mainSend.AppendFormatted(32, "HWOUT %d ", (_hwOuts[i]-monoHWCount) | 1024); else mainSend.AppendFormatted(32, "HWOUT %d ", _hwOuts[i]-1); mainSend.Append("0 "); mainSend.AppendFormatted(20, "%.14f ", *(double*)GetConfigVar("defhwvol")); mainSend.Append("0.00000000000000 0 0 0 -1.00000000000000 -1\n"); } } if (!cr) mainSend.Append("\n"); // hot } // patch both updates (no break keyword here: new empty track) updated |= p->ReplaceLine("TRACK", "MAINSEND", 1, 0, mainSend.Get()); } p->Commit(); delete p; if (updated) { GetSetMediaTrackInfo(cueTr, "I_SELECTED", &g_i1); UpdateTimeline(); ScrollSelTrack(true, true); if (_showRouting) Main_OnCommand(40293, 0); if (_undoMsg) Undo_OnStateChangeEx2(NULL, _undoMsg, UNDO_STATE_ALL, -1); } } return updated; }