[vlc-commits] [Git][videolan/vlc][master] macosx: refactor synchronized lyrics handling
Felix Paul Kühne (@fkuehne)
gitlab at videolan.org
Sun Nov 15 16:56:24 UTC 2026
Felix Paul Kühne pushed to branch master at VideoLAN / VLC
Commits:
6bdf37de by Serhii Bykov at 2026-11-15T17:18:13+01:00
macosx: refactor synchronized lyrics handling
- - - - -
7 changed files:
- extras/package/macosx/VLC.xcodeproj/project.pbxproj
- modules/gui/macosx/Makefile.am
- modules/gui/macosx/tests/Makefile.am
- + modules/gui/macosx/tests/VLCLyricEntryTest.m
- + modules/gui/macosx/windows/video/VLCLyricEntry.h
- + modules/gui/macosx/windows/video/VLCLyricEntry.m
- modules/gui/macosx/windows/video/VLCMainVideoViewAudioMediaDecorativeView.m
Changes:
=====================================
extras/package/macosx/VLC.xcodeproj/project.pbxproj
=====================================
@@ -152,6 +152,7 @@
5397EE4E300150F400F2E3F1 /* VLCSpacingConstraint.m in Sources */ = {isa = PBXBuildFile; fileRef = 5397EE4A300150F400F2E3F1 /* VLCSpacingConstraint.m */; };
539BA79F298C726200918C36 /* VLCAspectRatioRetainingVideoWindow.m in Sources */ = {isa = PBXBuildFile; fileRef = 539BA79E298C726200918C36 /* VLCAspectRatioRetainingVideoWindow.m */; };
539F114B29E83A4200F13460 /* VLCLibraryTwoPaneSplitViewDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 539F114A29E83A4200F13460 /* VLCLibraryTwoPaneSplitViewDelegate.m */; };
+ A42F100129F9785C00F13460 /* VLCLyricEntry.m in Sources */ = {isa = PBXBuildFile; fileRef = A42F100329F9785C00F13460 /* VLCLyricEntry.m */; };
539F116D29F9785C00F13460 /* VLCMainVideoViewAudioMediaDecorativeView.m in Sources */ = {isa = PBXBuildFile; fileRef = 539F116C29F9785C00F13460 /* VLCMainVideoViewAudioMediaDecorativeView.m */; };
53A1F1172AB7168000686BAA /* VLCLibraryAllAudioGroupsMediaLibraryItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A1F1162AB7168000686BAA /* VLCLibraryAllAudioGroupsMediaLibraryItem.m */; };
53A5E83E2CFE16E9008B33C1 /* VLCLibraryCollectionView.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A5E83D2CFE16E9008B33C1 /* VLCLibraryCollectionView.m */; };
@@ -505,6 +506,8 @@
539F114929E83A4200F13460 /* VLCLibraryTwoPaneSplitViewDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VLCLibraryTwoPaneSplitViewDelegate.h; sourceTree = "<group>"; };
539F114A29E83A4200F13460 /* VLCLibraryTwoPaneSplitViewDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = VLCLibraryTwoPaneSplitViewDelegate.m; sourceTree = "<group>"; };
539F116A29F9756000F13460 /* VLCMainVideoViewAudioMediaDecorativeView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = VLCMainVideoViewAudioMediaDecorativeView.xib; sourceTree = "<group>"; };
+ A42F100229F9785C00F13460 /* VLCLyricEntry.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VLCLyricEntry.h; sourceTree = "<group>"; };
+ A42F100329F9785C00F13460 /* VLCLyricEntry.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = VLCLyricEntry.m; sourceTree = "<group>"; };
539F116B29F9785C00F13460 /* VLCMainVideoViewAudioMediaDecorativeView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VLCMainVideoViewAudioMediaDecorativeView.h; sourceTree = "<group>"; };
539F116C29F9785C00F13460 /* VLCMainVideoViewAudioMediaDecorativeView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = VLCMainVideoViewAudioMediaDecorativeView.m; sourceTree = "<group>"; };
53A1F1152AB7168000686BAA /* VLCLibraryAllAudioGroupsMediaLibraryItem.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VLCLibraryAllAudioGroupsMediaLibraryItem.h; sourceTree = "<group>"; };
@@ -1229,6 +1232,8 @@
children = (
534E8E3829A06325009503F8 /* VLCMainVideoViewController.h */,
534E8E3929A06325009503F8 /* VLCMainVideoViewController.m */,
+ A42F100229F9785C00F13460 /* VLCLyricEntry.h */,
+ A42F100329F9785C00F13460 /* VLCLyricEntry.m */,
539F116B29F9785C00F13460 /* VLCMainVideoViewAudioMediaDecorativeView.h */,
539F116C29F9785C00F13460 /* VLCMainVideoViewAudioMediaDecorativeView.m */,
536BFD1729B181E100BD0776 /* VLCMainVideoViewOverlayView.h */,
@@ -2548,6 +2553,7 @@
1C3113921E508C6900D4DD76 /* VLCAddonListItem.m in Sources */,
7DFBDCB7226CDFD600B700A5 /* VLCImageView.m in Sources */,
7D404ABF2281892C00B28EF4 /* NSView+VLCAdditions.m in Sources */,
+ A42F100129F9785C00F13460 /* VLCLyricEntry.m in Sources */,
539F116D29F9785C00F13460 /* VLCMainVideoViewAudioMediaDecorativeView.m in Sources */,
7DE9C7DD220728420089108F /* VLCPlayerController.m in Sources */,
53A9698A2CD5B9D400E6F66E /* VLCTimeFormatter.m in Sources */,
=====================================
modules/gui/macosx/Makefile.am
=====================================
@@ -587,6 +587,8 @@ libmacosx_plugin_la_SOURCES = \
gui/macosx/windows/video/VLCAspectRatioRetainingVideoWindow.m \
gui/macosx/windows/video/VLCFullVideoViewWindow.h \
gui/macosx/windows/video/VLCFullVideoViewWindow.m \
+ gui/macosx/windows/video/VLCLyricEntry.h \
+ gui/macosx/windows/video/VLCLyricEntry.m \
gui/macosx/windows/video/VLCMainVideoViewAudioMediaDecorativeView.h \
gui/macosx/windows/video/VLCMainVideoViewAudioMediaDecorativeView.m \
gui/macosx/windows/video/VLCMainVideoViewController.h \
=====================================
modules/gui/macosx/tests/Makefile.am
=====================================
@@ -34,6 +34,7 @@ VLCMacOSXTests_SOURCES = \
gui/macosx/tests/VLCLibraryHomeVideoDataSourceTest.m \
gui/macosx/tests/VLCLibraryHomeTestSupport.m \
gui/macosx/tests/VLCLogMessageTest.m \
+ gui/macosx/tests/VLCLyricEntryTest.m \
gui/macosx/tests/VLCMacOSXTestDefaults.m \
gui/macosx/tests/VLCPositionFormatterTest.m \
gui/macosx/tests/VLCTimeFormatterTest.m \
@@ -73,6 +74,7 @@ VLCMacOSXTests_SOURCES = \
gui/macosx/library/VLCLibraryModelChangeDelegate.m \
gui/macosx/library/VLCMediaLibraryFolderObserver.m \
gui/macosx/windows/logging/VLCLogMessage.m \
+ gui/macosx/windows/video/VLCLyricEntry.m \
gui/macosx/views/VLCCarouselView.m \
gui/macosx/views/VLCImageView.m \
gui/macosx/views/VLCSpacingConstraint.m \
=====================================
modules/gui/macosx/tests/VLCLyricEntryTest.m
=====================================
@@ -0,0 +1,78 @@
+/*****************************************************************************
+ * VLCLyricEntryTest.m: synchronized lyrics tests
+ *****************************************************************************
+ * Copyright (C) 2026 VLC authors and VideoLAN
+ *
+ * Authors: Serhii Bykov <esphynox at gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#import <XCTest/XCTest.h>
+
+#import "windows/video/VLCLyricEntry.h"
+
+ at interface VLCLyricEntryTest : XCTestCase
+ at end
+
+ at implementation VLCLyricEntryTest
+
+- (void)testParsesEntriesInOrder
+{
+ NSArray<VLCLyricEntry *> * const entries =
+ [VLCLyricEntry entriesFromSYLTData:@"1234\x1F" "First line\x1E" "5678\x1F" "Second line"];
+ XCTAssertEqual(entries.count, 2);
+ XCTAssertEqual(entries[0].timeMs, 1234);
+ XCTAssertEqualObjects(entries[0].text, @"First line");
+ XCTAssertEqual(entries[1].timeMs, 5678);
+ XCTAssertEqualObjects(entries[1].text, @"Second line");
+}
+
+- (void)testEmptyAndMalformedEntries
+{
+ XCTAssertEqual([VLCLyricEntry entriesFromSYLTData:nil].count, 0);
+ XCTAssertEqual([VLCLyricEntry entriesFromSYLTData:@""].count, 0);
+ NSArray<VLCLyricEntry *> * const entries =
+ [VLCLyricEntry entriesFromSYLTData:@"\x1E" "missing separator\x1E" "bad\x1F" "text\x1F" "ignored\x1E" "9\x1F"];
+ XCTAssertEqual(entries.count, 2);
+ XCTAssertEqual(entries[0].timeMs, 0);
+ XCTAssertEqualObjects(entries[0].text, @"text");
+ XCTAssertEqual(entries[1].timeMs, 9);
+ XCTAssertEqualObjects(entries[1].text, @"");
+}
+
+- (void)testInitWithParts
+{
+ XCTAssertNil([[VLCLyricEntry alloc] initWithParts:@[]]);
+ XCTAssertNil([[VLCLyricEntry alloc] initWithParts:@[@"12"]]);
+
+ VLCLyricEntry * const entry = [[VLCLyricEntry alloc] initWithParts:@[@"123", @"line", @"ignored"]];
+ XCTAssertEqual(entry.timeMs, 123);
+ XCTAssertEqualObjects(entry.text, @"line");
+
+ VLCLyricEntry * const invalidTime = [[VLCLyricEntry alloc] initWithParts:@[@"bad", @"line"]];
+ XCTAssertEqual(invalidTime.timeMs, 0);
+}
+
+- (void)testEntryCopiesText
+{
+ NSMutableString * const text = [NSMutableString stringWithString:@"line"];
+ VLCLyricEntry * const entry = [[VLCLyricEntry alloc] initWithTimeMs:42 text:text];
+ [text appendString:@" changed"];
+ XCTAssertEqual(entry.timeMs, 42);
+ XCTAssertEqualObjects(entry.text, @"line");
+}
+
+ at end
=====================================
modules/gui/macosx/windows/video/VLCLyricEntry.h
=====================================
@@ -0,0 +1,40 @@
+/*****************************************************************************
+ * VLCLyricEntry.h: synchronized lyric entry
+ *****************************************************************************
+ * Copyright (C) 2026 VLC authors and VideoLAN
+ *
+ * Authors: Serhii Bykov <esphynox at gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#import <Foundation/Foundation.h>
+
+NS_ASSUME_NONNULL_BEGIN
+
+ at interface VLCLyricEntry : NSObject
+
+ at property (nonatomic, readonly) long long timeMs;
+ at property (nonatomic, copy, readonly) NSString *text;
+
+- (nullable instancetype)initWithParts:(NSArray<NSString *> *)parts;
+- (instancetype)initWithTimeMs:(long long)timeMs text:(NSString *)text NS_DESIGNATED_INITIALIZER;
+- (instancetype)init NS_UNAVAILABLE;
+
++ (NSArray<VLCLyricEntry *> *)entriesFromSYLTData:(nullable NSString *)data;
+
+ at end
+
+NS_ASSUME_NONNULL_END
=====================================
modules/gui/macosx/windows/video/VLCLyricEntry.m
=====================================
@@ -0,0 +1,64 @@
+/*****************************************************************************
+ * VLCLyricEntry.m: synchronized lyric entry
+ *****************************************************************************
+ * Copyright (C) 2026 VLC authors and VideoLAN
+ *
+ * Authors: Serhii Bykov <esphynox at gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#import "VLCLyricEntry.h"
+
+static NSString * const VLCLyricEntrySeparator = @"\x1E";
+static NSString * const VLCLyricFieldSeparator = @"\x1F";
+
+ at implementation VLCLyricEntry
+
+- (instancetype)initWithParts:(NSArray<NSString *> *)parts
+{
+ if (parts.count < 2) {
+ return nil;
+ }
+ return [self initWithTimeMs:parts[0].longLongValue text:parts[1]];
+}
+
+- (instancetype)initWithTimeMs:(long long)timeMs text:(NSString *)text
+{
+ self = [super init];
+ if (self) {
+ _timeMs = timeMs;
+ _text = [text copy];
+ }
+ return self;
+}
+
++ (NSArray<VLCLyricEntry *> *)entriesFromSYLTData:(NSString *)data
+{
+ NSMutableArray<VLCLyricEntry *> * const entries = [NSMutableArray array];
+ for (NSString * const rawEntry in [data componentsSeparatedByString:VLCLyricEntrySeparator]) {
+ if (rawEntry.length == 0) {
+ continue;
+ }
+ NSArray<NSString *> * const parts = [rawEntry componentsSeparatedByString:VLCLyricFieldSeparator];
+ VLCLyricEntry * const entry = [[VLCLyricEntry alloc] initWithParts:parts];
+ if (entry) {
+ [entries addObject:entry];
+ }
+ }
+ return [entries copy];
+}
+
+ at end
=====================================
modules/gui/macosx/windows/video/VLCMainVideoViewAudioMediaDecorativeView.m
=====================================
@@ -4,6 +4,7 @@
* Copyright (C) 2023 VLC authors and VideoLAN
*
* Authors: Claudio Cambra <developer at claudiocambra.com>
+ * Serhii Bykov <esphynox at gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -21,6 +22,7 @@
*****************************************************************************/
#import "VLCMainVideoViewAudioMediaDecorativeView.h"
+#import "VLCLyricEntry.h"
#import "extensions/NSColor+VLCAdditions.h"
#import "extensions/NSFont+VLCAdditions.h"
@@ -37,7 +39,7 @@
@interface VLCMainVideoViewAudioMediaDecorativeView () <NSTableViewDataSource, NSTableViewDelegate>
- at property (readwrite) NSArray<NSDictionary<NSString *, id> *> *lyricsEntries;
+ at property (readwrite) NSArray<VLCLyricEntry *> *lyricsEntries;
@property (readwrite) NSInteger currentLyricIndex;
@end
@@ -145,23 +147,7 @@
return;
}
- NSMutableArray * const entries = [NSMutableArray array];
- NSArray<NSString *> * const rawEntries = [syltData componentsSeparatedByString:@"\x1E"];
- for (NSString * const rawEntry in rawEntries) {
- if (rawEntry.length == 0) {
- continue;
- }
- NSArray<NSString *> * const parts = [rawEntry componentsSeparatedByString:@"\x1F"];
- if (parts.count >= 2) {
- NSDictionary<NSString *, id> * const entry = @{
- @"time": @([parts[0] longLongValue]),
- @"text": parts[1]
- };
- [entries addObject:entry];
- }
- }
-
- self.lyricsEntries = [entries copy];
+ self.lyricsEntries = [VLCLyricEntry entriesFromSYLTData:syltData];
self.currentLyricIndex = -1;
[self.lyricsTableView reloadData];
@@ -187,11 +173,11 @@
// 1. Check if we are still on the same lyric (most frequent case)
if (self.currentLyricIndex >= 0 && self.currentLyricIndex < lyricCount) {
const long long startTime =
- [self.lyricsEntries[self.currentLyricIndex][@"time"] longLongValue];
+ self.lyricsEntries[self.currentLyricIndex].timeMs;
const BOOL isLast = (self.currentLyricIndex == lyricCount - 1);
const long long nextStartTime = isLast
? LLONG_MAX
- : [self.lyricsEntries[self.currentLyricIndex + 1][@"time"] longLongValue];
+ : self.lyricsEntries[self.currentLyricIndex + 1].timeMs;
if (currentTimeMs >= startTime && currentTimeMs < nextStartTime) {
return;
@@ -203,7 +189,7 @@
const BOOL isNextLast = (nextIndex == lyricCount - 1);
const long long nextNextStartTime = isNextLast
? LLONG_MAX
- : [self.lyricsEntries[nextIndex + 1][@"time"] longLongValue];
+ : self.lyricsEntries[nextIndex + 1].timeMs;
if (currentTimeMs < nextNextStartTime) {
[self updateToLyricIndex:nextIndex];
@@ -215,7 +201,7 @@
// 3. Fallback to search (for seeks, jumps, or initial playback)
NSInteger foundIndex = -1;
for (NSInteger i = 0; i < lyricCount; i++) {
- if ([self.lyricsEntries[i][@"time"] longLongValue] <= currentTimeMs) {
+ if (self.lyricsEntries[i].timeMs <= currentTimeMs) {
foundIndex = i;
} else {
break;
@@ -271,7 +257,7 @@
return cellView;
}
- NSString * const text = self.lyricsEntries[row][@"text"];
+ NSString * const text = self.lyricsEntries[row].text;
cellView.textField.stringValue = text;
if (row == self.currentLyricIndex) {
@@ -297,7 +283,7 @@
return;
}
- const long long lyricTimeMs = [self.lyricsEntries[clickedRow][@"time"] longLongValue];
+ const long long lyricTimeMs = self.lyricsEntries[clickedRow].timeMs;
const vlc_tick_t vlcTime = VLC_TICK_FROM_MS(lyricTimeMs);
VLCPlayerController * const playerController =
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/6bdf37de8e9399557883ec530f29c0b46c533c80
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/6bdf37de8e9399557883ec530f29c0b46c533c80
You're receiving this email because of your account on code.videolan.org. Manage all notifications: https://code.videolan.org/-/profile/notifications | Help: https://code.videolan.org/help
More information about the vlc-commits
mailing list