@@ -256,6 +256,31 @@ public static Dictionary<ShiftMethod, float> CalcChartPadding(List<MaiChart> cha
256256 }
257257
258258 private record AllChartsEntry ( string chartText , MaiChart simaiSharpChart ) ;
259+
260+ [ GeneratedRegex ( @"^(CLK_DEF\t)(\d+\s*)$" , RegexOptions . Multiline ) ]
261+ private static partial Regex ClockDefRegex ( ) ;
262+
263+ [ GeneratedRegex ( @"^(MET\t\d+\t\d+\t\d+\t)(\d+\s*)$" , RegexOptions . Multiline ) ]
264+ private static partial Regex FirstMetLineRegex ( ) ;
265+
266+ private static string replaceGroup2ByRegex ( string input , Match match , int value )
267+ {
268+ if ( ! match . Success ) return input ;
269+ return string . Concat (
270+ input . AsSpan ( 0 , match . Index ) ,
271+ match . Groups [ 1 ] . ValueSpan ,
272+ value . ToString ( CultureInfo . InvariantCulture ) ,
273+ input . AsSpan ( match . Index + match . Length ) ) ;
274+ }
275+
276+ private static string ApplyClockCountToFirstMetLine ( string ma2Content , int clockCount )
277+ {
278+ var clockdefMatch = ClockDefRegex ( ) . Match ( ma2Content ) ;
279+ ma2Content = replaceGroup2ByRegex ( ma2Content , clockdefMatch , 96 * clockCount ) ;
280+ var metMatch = FirstMetLineRegex ( ) . Match ( ma2Content ) ;
281+ ma2Content = replaceGroup2ByRegex ( ma2Content , metMatch , clockCount ) ;
282+ return ma2Content ;
283+ }
259284
260285 public ImportChartResult ImportMaidata (
261286 MusicXml music ,
@@ -410,6 +435,12 @@ public ImportChartResult ImportMaidata(
410435 errors . Add ( new ImportChartMessage ( Locale . ChartNotesMissing , MessageLevel . Warning ) ) ;
411436 logger . LogWarning ( "BUG! shiftedConverted: {shiftedLen}, originalConverted: {originalLen}" , shiftedConverted . Split ( '\n ' ) . Length , originalConverted . Split ( '\n ' ) . Length ) ;
412437 }
438+
439+ // 如果maidata中声明了clock_count,应用之,修改CLOCK_DEF和MET
440+ if ( int . TryParse ( maiData . GetValueOrDefault ( "clock_count" ) , out var clockCount ) )
441+ {
442+ shiftedConverted = ApplyClockCountToFirstMetLine ( shiftedConverted , clockCount ) ;
443+ }
413444
414445 // Just use T_NUM_ALL value in ma2 file
415446 targetChart . MaxNotes = ParseTNumAllFromMa2 ( shiftedConverted ) ;
0 commit comments