From 4d45391b870ad2c9454ad8fc304de133f18a67eb Mon Sep 17 00:00:00 2001 From: brunzelchen Date: Wed, 9 Dec 2009 21:43:28 +0000 Subject: - estimated (calculated) refrains are shown with an [C] at the end of the title in the song screen - with LSHIFT+S a calculated refrain can be played - with LSHIFT+D a mixed medley (tagged+calculated) can be played - the keys S (play single medley of chosen song) and D (play 5 random tagged songs in a medley) are untouched git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/branches/experimental@2014 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Medley/src/base/USong.pas | 67 ++++++++++++++++++++++++++++++++++---- Medley/src/screens/UScreenSong.pas | 42 ++++++++++++++---------- 2 files changed, 85 insertions(+), 24 deletions(-) diff --git a/Medley/src/base/USong.pas b/Medley/src/base/USong.pas index d4eb714d..8721cffb 100644 --- a/Medley/src/base/USong.pas +++ b/Medley/src/base/USong.pas @@ -62,6 +62,10 @@ uses UFilesystem, UPath; +Const + DEFAULT_FADE_IN_TIME = 10; + DEFAULT_FADE_OUT_TIME = 4; + type TSingMode = ( smNormal, smPartyMode, smPlaylistRandom, smMedley ); @@ -608,6 +612,7 @@ begin Lines[Count].Line[High(Lines[Count].Line)].LastLine := true; end; Result := true; + FindRefrainStart; end; //Load XML Song @@ -1358,8 +1363,12 @@ end; {* new procedure for preview - tries find out the beginning of a refrain *} + tries find out the beginning of a refrain + and the end... *} procedure TSong.FindRefrainStart(); +Const + MEDLEY_MIN_DURATION = 25; //minimum duration of a medley in seconds + Type TSeries = record start: integer; //Start sentence of series @@ -1373,7 +1382,8 @@ var series: array of TSeries; temp_series: TSeries; max: integer; - + len_lines, len_notes: integer; + found_end: boolean; begin if Medley.Source = msTag then Exit; @@ -1435,8 +1445,56 @@ begin if (Length(series)>0) and (series[max].len > 3) then begin - Medley.Source := msCalculated; Medley.StartBeat := Lines[0].Line[series[max].start].Note[0].Start; + Medley.EndBeat := Lines[0].Line[series[max].end_].Note[0].Start + + Lines[0].Line[series[max].end_].Note[0].Length; + + CurrentSong := self; + found_end := false; + + //set end if duration > MEDLEY_MIN_DURATION + if GetTimeFromBeat(Medley.StartBeat)+ MEDLEY_MIN_DURATION > + GetTimeFromBeat(Medley.EndBeat) then + begin + found_end := true; + end; + + //estimate the end: just go MEDLEY_MIN_DURATION + //ahead an set to a line end (if possible) + if not found_end then + begin + len_lines := length(Lines[0].Line); + for I := series[max].start+1 to len_lines-1 do + begin + len_notes := length(Lines[0].Line[I].Note); + for J := 0 to len_notes - 1 do + begin + if GetTimeFromBeat(Medley.StartBeat)+ MEDLEY_MIN_DURATION > + GetTimeFromBeat(Lines[0].Line[I].Note[J].Start+ + Lines[0].Line[I].Note[J].Length) then + begin + found_end := true; + Medley.EndBeat := Lines[0].Line[I].Note[len_notes-1].Start+ + Lines[0].Line[I].Note[len_notes-1].Length; + break; + end; + end; + end; + end; + + + if found_end then + begin + Medley.Source := msCalculated; + Medley.FadeIn := Medley.StartBeat - round(GetMidBeat(DEFAULT_FADE_IN_TIME)); + Medley.FadeOut := Medley.EndBeat + round(GetMidBeat(DEFAULT_FADE_OUT_TIME)); + + //calculate fade time + + Medley.FadeIn_time := GetTimeFromBeat(Medley.StartBeat) - GetTimeFromBeat(Medley.FadeIn); + Medley.FadeOut_time := GetTimeFromBeat(Medley.FadeOut) - GetTimeFromBeat(Medley.EndBeat); + end else + Medley.Source := msNone; end else Medley.Source := msNone; end; @@ -1487,9 +1545,6 @@ end; // FADE_OUT-> MEDLEY_FADE_OUT //TODO: write a tool to convert existing txtm function TSong.ReadMedleyFile(MedleyFilePath: IPath): boolean; -const - DEFAULT_FADE_IN_TIME = 10; - DEFAULT_FADE_OUT_TIME = 4; var Line, Identifier: string; Value: string; diff --git a/Medley/src/screens/UScreenSong.pas b/Medley/src/screens/UScreenSong.pas index bab2ef51..c89193a8 100644 --- a/Medley/src/screens/UScreenSong.pas +++ b/Medley/src/screens/UScreenSong.pas @@ -141,8 +141,8 @@ type procedure Refresh; //Refresh Song Sorting procedure ChangeMusic; - function getVisibleMedleyArr(): TVisArr; - procedure StartMedley(num: integer); + function getVisibleMedleyArr(MinSource: TMedleySource): TVisArr; + procedure StartMedley(num: integer; MinSource: TMedleySource); //Party Mode procedure SelectRandomSong; procedure SetJoker; @@ -291,7 +291,7 @@ begin I2 := Length(CatSongs.Song); //Jump To Titel - if (SDL_ModState = (KMOD_LALT or KMOD_LSHIFT)) then + if (SDL_ModState = KMOD_LALT) then begin for I := 1 to High(CatSongs.Song) do begin @@ -352,18 +352,21 @@ begin Ord('S'): begin - if (Length(getVisibleMedleyArr()) > 0) and (Mode = smNormal) and - (CatSongs.Song[Interaction].Medley.Source = msTag) then - begin - StartMedley(0); - end; + if (SDL_ModState = KMOD_LSHIFT) and + (CatSongs.Song[Interaction].Medley.Source>=msCalculated) and + (Mode = smNormal)then + StartMedley(0, msCalculated) + else if (CatSongs.Song[Interaction].Medley.Source>=msTag) and + (Mode = smNormal) then + StartMedley(0, msTag); end; Ord('D'): begin - if (Length(getVisibleMedleyArr()) > 0) and (Mode = smNormal) then - begin - StartMedley(5); - end; + if (SDL_ModState = KMOD_LSHIFT) and + (Length(getVisibleMedleyArr(msCalculated)) > 0) and (Mode = smNormal)then + StartMedley(5, msCalculated) + else if (Length(getVisibleMedleyArr(msTag)) > 0) and (Mode = smNormal) then + StartMedley(5, msTag); end; Ord('M'): //Show SongMenu begin @@ -1025,7 +1028,10 @@ begin //medley mod if CatSongs.Song[Interaction].Medley.Source = msTag then - Text[TextTitle].Text := Text[TextTitle].Text + '[M]'; + Text[TextTitle].Text := Text[TextTitle].Text + ' [M]'; + + if CatSongs.Song[Interaction].Medley.Source = msCalculated then + Text[TextTitle].Text := Text[TextTitle].Text + ' [C]'; if (Ini.TabsAtStartup = 1) and (CatSongs.CatNumShow = -1) then begin @@ -1838,7 +1844,7 @@ begin end; end; -function TScreenSong.getVisibleMedleyArr(): TVisArr; +function TScreenSong.getVisibleMedleyArr(MinSource: TMedleySource): TVisArr; var I: integer; res: TVisArr; @@ -1846,7 +1852,7 @@ begin SetLength(res, 0); for I := 0 to Length(CatSongs.Song) - 1 do begin - if CatSongs.Song[I].Visible and (CatSongs.Song[I].Medley.Source = msTag) then + if CatSongs.Song[I].Visible and (CatSongs.Song[I].Medley.Source >= MinSource) then begin SetLength(res, Length(res)+1); res[Length(res)-1] := I; @@ -1856,7 +1862,7 @@ begin end; //start Medley round -procedure TScreenSong.StartMedley(num: integer); +procedure TScreenSong.StartMedley(num: integer; MinSource: TMedleySource); procedure AddSong(SongNr: integer); begin SetLength(PlaylistMedley.Song, Length(PlaylistMedley.Song)+1); @@ -1892,7 +1898,7 @@ procedure TScreenSong.StartMedley(num: integer); visible_arr: TVisArr; begin SetLength(unused_arr, 0); - visible_arr := getVisibleMedleyArr(); + visible_arr := getVisibleMedleyArr(MinSource); for I := 0 to Length(visible_arr) - 1 do begin if (not SongAdded(visible_arr[I])) then @@ -1916,7 +1922,7 @@ begin if num>0 then begin - VS := Length(getVisibleMedleyArr()); + VS := Length(getVisibleMedleyArr(MinSource)); if VS < num then PlaylistMedley.NumMedleySongs := VS else -- cgit v1.2.3