int GetFolderDepth(MediaTrack* tr, int* iType, MediaTrack** nextTr) // iType: 0=normal, 1=parent, < 0=last in folder { //static MediaTrack* nextTr = NULL; Let calling fcn keep track so state is reset appropriately static int iLastFolder = 0; int iFolder; if (tr == *nextTr) { *nextTr = CSurf_TrackFromID(CSurf_TrackToID(tr, false) + 1, false); if (CSurf_TrackToID(tr, false) == 0) // Special case for master { if (iType) *iType = 1; return -1; // Master is at '-1' depth } iFolder = *(int*)GetSetMediaTrackInfo(tr, "I_FOLDERDEPTH", NULL); if (iType) *iType = iFolder; if (iFolder == 0) return iLastFolder; else if (iFolder == 1) { iLastFolder++; return iLastFolder - 1; // Count parent as at the "previous" level } else if (iFolder < 0) { int iCur = iLastFolder; iLastFolder += iFolder; return iCur; } } else { // Must iterate until reaching the track passed in iLastFolder = 0; *nextTr = CSurf_TrackFromID(0, false); while (tr != *nextTr) GetFolderDepth(*nextTr, NULL, nextTr); return GetFolderDepth(tr, iType, nextTr); } return -1; }
void ColorChildren(COMMAND_T* = NULL) { int iParentDepth; COLORREF crParentColor; bool bSelected = false; MediaTrack* gfd = NULL; for (int i = 1; i <= GetNumTracks(); i++) { MediaTrack* tr = CSurf_TrackFromID(i, false); int iType; int iFolder = GetFolderDepth(tr, &iType, &gfd); if (bSelected) GetSetMediaTrackInfo(tr, "I_CUSTOMCOLOR", &crParentColor); if (iType == 1) { if (!bSelected && *(int*)GetSetMediaTrackInfo(tr, "I_SELECTED", NULL)) { iParentDepth = iFolder; bSelected = true; } crParentColor = *(COLORREF*)GetSetMediaTrackInfo(tr, "I_CUSTOMCOLOR", NULL); } if (iType + iFolder <= iParentDepth) bSelected = false; } Undo_OnStateChangeEx(__LOCALIZE("Set track(s) children to same color","sws_undo"), UNDO_STATE_TRACKCFG, -1); }