Implement framework for dynamic metadata updates

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
CQTexperiment
Christopher Snowhill 2022-02-08 19:56:39 -08:00
parent b927f4c02b
commit 7cea254f4c
30 changed files with 128 additions and 2 deletions

View File

@ -760,6 +760,14 @@ NSDictionary *makeRGInfo(PlaylistEntry *pe) {
[player play:[pe URL] withUserInfo:pe withRGInfo:makeRGInfo(pe) startPaused:paused andSeekTo:[pe currentPosition]];
}
- (void)audioPlayer:(AudioPlayer *)player pushInfo:(NSDictionary *)info toTrack:(id)userInfo {
PlaylistEntry *pe = (PlaylistEntry *)userInfo;
[pe setMetadata:info];
[playlistView refreshCurrentTrack:self];
[self sendMetaData];
[[NSNotificationCenter defaultCenter] postNotificationName:CogPlaybackDidBeginNotficiation object:pe];
}
- (void)removeHDCD:(id)sender {
MainWindow *mainWindow = (MainWindow *)appController.mainWindow;
[mainWindow showHDCDLogo:NO];

View File

@ -78,6 +78,8 @@
- (void)restartPlaybackAtCurrentPosition;
- (void)pushInfo:(NSDictionary *)info;
+ (NSArray *)fileTypes;
+ (NSArray *)schemes;
+ (NSArray *)containerTypes;
@ -124,4 +126,5 @@
- (void)audioPlayer:(AudioPlayer *)player removeEqualizer:(AudioUnit)eq;
- (void)audioPlayer:(AudioPlayer *)player sustainHDCD:(id)userInfo;
- (void)audioPlayer:(AudioPlayer *)player restartPlaybackAtCurrentPosition:(id)userInfo;
- (void)audioPlayer:(AudioPlayer *)player pushInfo:(NSDictionary *)info toTrack:(id)userInfo;
@end

View File

@ -224,6 +224,10 @@
[self sendDelegateMethod:@selector(audioPlayer:restartPlaybackAtCurrentPosition:) withObject:[bufferChain userInfo] waitUntilDone:NO];
}
- (void)pushInfo:(NSDictionary *)info {
[self sendDelegateMethod:@selector(audioPlayer:pushInfo:toTrack:) withObject:info withObject:[bufferChain userInfo] waitUntilDone:NO];
}
- (void)setShouldContinue:(BOOL)s {
shouldContinue = s;

View File

@ -77,4 +77,6 @@
- (void)restartPlaybackAtCurrentPosition;
- (void)pushInfo:(NSDictionary *)info;
@end

View File

@ -264,4 +264,8 @@
[controller restartPlaybackAtCurrentPosition];
}
- (void)pushInfo:(NSDictionary *)info {
[controller pushInfo:info];
}
@end

View File

@ -116,6 +116,18 @@
nodeLossless = [[properties valueForKey:@"encoding"] isEqualToString:@"lossless"];
} else if([keyPath isEqual:@"metadata"]) {
// Inform something of metadata change
NSMutableDictionary *entryInfo = [NSMutableDictionary dictionaryWithCapacity:32];
NSDictionary *entryProperties = [decoder properties];
if(entryProperties == nil)
return;
[entryInfo addEntriesFromDictionary:entryProperties];
[entryInfo addEntriesFromDictionary:[decoder metadata]];
NSDictionary * info = [NSDictionary dictionaryWithDictionary:entryInfo];
[controller pushInfo:info];
}
}

View File

@ -72,6 +72,11 @@ NSArray *sortClassesByPriority(NSArray *theClasses) {
return nil;
}
- (NSDictionary *)metadata {
if(theDecoder != nil) return [theDecoder metadata];
return @{};
}
- (int)readAudio:(void *)buffer frames:(UInt32)frames {
if(theDecoder != nil) return [theDecoder readAudio:buffer frames:frames];
return 0;

View File

@ -37,6 +37,7 @@
// For KVO
//- (void)setProperties:(NSDictionary *)p;
- (NSDictionary *)properties;
- (NSDictionary *)metadata; // Only to be implemented for dynamic metadata, send events on change
- (int)readAudio:(void *)buffer frames:(UInt32)frames;

View File

@ -24,4 +24,6 @@
- (IBAction)scrollToCurrentEntry:(id)sender;
- (IBAction)refreshCurrentTrack:(id)sender;
@end

View File

@ -405,6 +405,11 @@
return [super validateUserInterfaceItem:anItem];
}
- (IBAction)refreshCurrentTrack:(id)sender {
unsigned long columns = [[self tableColumns] count];
[self reloadDataForRowIndexes:[NSIndexSet indexSetWithIndex:[[playlistController currentEntry] index]] columnIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, columns)]];
}
#if 0
- (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)isLocal
{

View File

@ -28,7 +28,11 @@
// Need to alter length
[properties setObject:[NSNumber numberWithLong:trackLength] forKey:@"totalFrames"];
return properties;
return [NSDictionary dictionaryWithDictionary:properties];
}
- (NSDictionary *)metadata {
return @{};
}
- (BOOL)open:(id<CogSource>)s {

View File

@ -92,6 +92,10 @@ static CAdPlugDatabase *g_database = NULL;
@"endian": @"host"};
}
- (NSDictionary *)metadata {
return @{};
}
- (int)readAudio:(void *)buf frames:(UInt32)frames {
int total = 0;
bool dont_loop = !IsRepeatOneSet();

View File

@ -402,4 +402,8 @@ static SInt64 getSizeProc(void *clientData) {
@"encoding": _audioFile_is_lossy ? @"lossy" : @"lossless"};
}
- (NSDictionary *)metadata {
return @{};
}
@end

View File

@ -40,7 +40,11 @@
// Need to alter length
[properties setObject:[NSNumber numberWithLong:(trackEnd - trackStart)] forKey:@"totalFrames"];
return properties;
return [NSDictionary dictionaryWithDictionary:properties];
}
- (NSDictionary *)metadata {
return @{};
}
- (BOOL)open:(id<CogSource>)s {

View File

@ -647,6 +647,10 @@ int64_t ffmpeg_seek(void *opaque, int64_t offset, int whence) {
@"encoding": lossy ? @"lossy" : @"lossless"};
}
- (NSDictionary *)metadata {
return @{};
}
+ (NSArray *)fileTypes {
return @[@"wma", @"asf", @"tak", @"mp4", @"m4a", @"aac", @"mp3", @"mp2", @"m2a", @"mpa", @"ape", @"ac3", @"dts", @"dtshd", @"wav", @"tta", @"vqf", @"vqe", @"vql", @"ra", @"rm", @"rmj", @"mka", @"weba"];
}

View File

@ -366,6 +366,10 @@ void ErrorCallback(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorS
@"encoding": @"lossless"};
}
- (NSDictionary *)metadata {
return @{};
}
+ (NSArray *)fileTypes {
return @[@"flac"];
}

View File

@ -151,6 +151,10 @@ gme_err_t readCallback(void *data, void *out, int count) {
@"encoding": @"synthesized"};
}
- (NSDictionary *)metadata {
return @{};
}
- (int)readAudio:(void *)buf frames:(UInt32)frames {
int numSamples = frames * 2; // channels = 2

View File

@ -91,6 +91,10 @@ static void oneTimeInit(void) {
@"encoding": @"synthesized"};
}
- (NSDictionary *)metadata {
return @{};
}
- (int)readAudio:(void *)buf frames:(UInt32)frames {
BOOL repeatone = IsRepeatOneSet();

View File

@ -109,6 +109,10 @@ static OSType getOSType(const char *in_) {
@"encoding": @"synthesized"};
}
- (NSDictionary *)metadata {
return @{};
}
- (BOOL)initDecoder {
NSString *soundFontPath = @"";

View File

@ -191,6 +191,10 @@ mpc_bool_t CanSeekProc(mpc_reader *p_reader) {
@"encoding": @"lossy"};
}
- (NSDictionary *)metadata {
return @{};
}
+ (NSArray *)fileTypes {
return @[@"mpc"];
}

View File

@ -104,6 +104,10 @@ static void g_push_archive_extensions(std::vector<std::string> &list) {
@"encoding": @"synthesized"};
}
- (NSDictionary *)metadata {
return @{};
}
- (int)readAudio:(void *)buf frames:(UInt32)frames {
mod->set_repeat_count(IsRepeatOneSet() ? -1 : 0);

View File

@ -101,6 +101,10 @@ static void g_push_archive_extensions(std::vector<std::string> &list) {
@"encoding": @"synthesized"};
}
- (NSDictionary *)metadata {
return @{};
}
- (int)readAudio:(void *)buf frames:(UInt32)frames {
mod->set_repeat_count(IsRepeatOneSet() ? -1 : 0);

View File

@ -188,6 +188,10 @@ opus_int64 sourceTell(void *_stream) {
@"encoding": @"lossy"};
}
- (NSDictionary *)metadata {
return @{};
}
+ (NSArray *)fileTypes {
return @[@"opus", @"ogg"];
}

View File

@ -87,6 +87,10 @@
@"encoding": @"lossless"};
}
- (NSDictionary *)metadata {
return @{};
}
+ (NSArray *)fileTypes {
return @[@"shn"];
}

View File

@ -46,6 +46,10 @@ enum { channels = 2 };
@"encoding": @"synthesized"};
}
- (NSDictionary *)metadata {
return @{};
}
- (int)readAudio:(void *)buf frames:(UInt32)frames {
int total = frames;

View File

@ -171,6 +171,10 @@ long sourceTell(void *datasource) {
@"encoding": @"lossy"};
}
- (NSDictionary *)metadata {
return @{};
}
+ (NSArray *)fileTypes {
return @[@"ogg"];
}

View File

@ -294,6 +294,10 @@ int32_t WriteBytesProc(void *ds, void *data, int32_t bcount) {
@"encoding": isLossy ? @"lossy" : @"lossless"};
}
- (NSDictionary *)metadata {
return @{};
}
+ (NSArray *)fileTypes {
return @[@"wv", @"wvp"];
}

View File

@ -189,6 +189,10 @@ const int masterVol = 0x10000; // Fixed point 16.16
@"encoding": @"synthesized"};
}
- (NSDictionary *)metadata {
return @{};
}
- (int)readAudio:(void*)buf frames:(UInt32)frames {
if([self trackEnded])
return 0;

View File

@ -199,6 +199,10 @@ static void sidTuneLoader(const char *fileName, std::vector<uint8_t> &bufferRef)
@"encoding": @"synthesized"};
}
- (NSDictionary *)metadata {
return @{};
}
- (int)readAudio:(void *)buf frames:(UInt32)frames {
int total = 0;
int16_t *sampleBuffer = (int16_t *)buf;

View File

@ -295,6 +295,10 @@ static NSString *get_description_tag(const char *description, const char *tag, c
@"encoding": @"lossy/lossless"};
}
- (NSDictionary *)metadata {
return @{};
}
- (int)readAudio:(void *)buf frames:(UInt32)frames {
UInt32 framesMax = frames;
UInt32 framesDone = 0;