Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dedicated message type for MIDI Show Control messages #67

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Applications/MIDIMonitor/SMMMonitorWindowController.m
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,8 @@ - (void)trivialWindowSettingsDidChange

- (void)displayPreferencesDidChange:(NSNotification *)notification
{
[self.displayedMessages makeObjectsPerformSelector:@selector(invalidateDisplayCache)];

[self.messagesTableView reloadData];
}

Expand Down
2 changes: 2 additions & 0 deletions Frameworks/SnoizeMIDI/SMMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,6 @@ extern NSString *SMProgramChangeBaseIndexPreferenceKey;
- (NSString *)expertDataForDisplay;
- (NSString *)originatingEndpointForDisplay;

- (void)invalidateDisplayCache;

@end
5 changes: 5 additions & 0 deletions Frameworks/SnoizeMIDI/SMMessage.m
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,11 @@ - (NSString *)originatingEndpointForDisplay
}
}

- (void)invalidateDisplayCache
{
// Do nothing by default. Subclasses that cache results that depend on display preferences should override to invalidate their cache.
}

@end


Expand Down
51 changes: 51 additions & 0 deletions Frameworks/SnoizeMIDI/SMShowControlUtilities.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//
// SMShowControlUtilities.h
// SnoizeMIDI
//
// Created by Hugo Trippaers on 22/12/2018.
//

#import <Foundation/Foundation.h>

// Based on the structure described in
// MIDI Show Control 1.1 pg 6
typedef struct {
int timecodeType;
int hours;
int minutes;
int seconds;
int frames;
int subframes;
int colorFrameBit;
int form; // 0 = fractional frames, 1 = status
int sign; // 0 = positive, 1 = negative
int statusEstimatedCodeFlag;
int statusInvalidCode;
int statusVideoFieldIndentification;
} SMTimecode;

/*
* Parses the provided bytes into a timecode structure
* according to the Timecode format in the MIDI Show
* Control 1.1 specification
*
* Parameters
* NSData *timecodeBytes, object with 5 bytes of timecode data
*
* Returns
* Timecode, struct with all components contains in the timecode data
*/
extern SMTimecode parseTimecodeData(NSData *timecodeData);

/*
* Parses the provided bytes into an array with one
* string per cue item in the list
*
* Parameters
* NSData *cueItemsData, object with a variable number of bytes terminated by 0xF7
*
* Returns
* NSArray *, array containing an NSString * for every cueitem found in the data
*/
extern NSArray *parseCueItemsData(NSData *cueItemsData);

52 changes: 52 additions & 0 deletions Frameworks/SnoizeMIDI/SMShowControlUtilities.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//
// SMShowControlUtilities.m
// SnoizeMIDI
//
// Created by Hugo Trippaers on 22/12/2018.
//

#import <Foundation/Foundation.h>

#import "SMShowControlUtilities.h"

#define BIT(n) ( 1<<(n) )
#define BIT_MASK(len) ( BIT(len)-1 )
#define BITFIELD_MASK(start, len) ( BIT_MASK(len)<<(start) )
#define BITFIELD_GET(y, start, len) ( ((y)>>(start)) & BIT_MASK(len) )

SMTimecode parseTimecodeData(NSData *timecodeData) {
SMTimecode timecode;
const Byte *byte = timecodeData.bytes;
// Hours and type: 0 tt hhhhh
timecode.timecodeType = BITFIELD_GET(*byte, 5, 2);
timecode.hours = BITFIELD_GET(*byte++, 0, 5);

// Minutes and color frame bit: 0 c mmmmmm
timecode.colorFrameBit = BITFIELD_GET(*byte, 6, 1);
timecode.minutes = BITFIELD_GET(*byte++, 0, 5);

// Seconds: 0 k ssssss
timecode.seconds = BITFIELD_GET(*byte++, 0, 5);

// Frames, byte 5 ident and sign: 0 g i fffff
timecode.sign = BITFIELD_GET(*byte, 6, 1);
timecode.form = BITFIELD_GET(*byte, 5, 1);
timecode.frames = BITFIELD_GET(*byte++, 0, 5);

if (timecode.form) {
// code status bit map:0 e v d xxxx
timecode.statusEstimatedCodeFlag = BITFIELD_GET(*byte, 6, 1);
timecode.statusInvalidCode = BITFIELD_GET(*byte, 5, 1);
timecode.statusVideoFieldIndentification = BITFIELD_GET(*byte, 4, 1);
} else {
// fractional frames: 0 bbbbbbb
timecode.subframes = BITFIELD_GET(*byte, 0, 7);
}

return timecode;
}

NSArray *parseCueItemsData(NSData *cueItemsData) {
NSString *cueItemString = [[NSString alloc] initWithData:cueItemsData encoding:NSASCIIStringEncoding];
return cueItemString.length > 0 ? [cueItemString componentsSeparatedByString:@"\0"] : @[];
}
10 changes: 0 additions & 10 deletions Frameworks/SnoizeMIDI/SMSystemExclusiveMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,6 @@

@interface SMSystemExclusiveMessage : SMMessage
// TODO Should this be a SMSystemCommonMessage too? Would we gain anything from that?
{
NSData *data;
// data does not include the starting 0xF0 or the ending 0xF7 (EOX)

struct {
unsigned int wasReceivedWithEOX:1;
} flags;

NSMutableData *cachedDataWithEOX;
}

+ (SMSystemExclusiveMessage *)systemExclusiveMessageWithTimeStamp:(MIDITimeStamp)aTimeStamp data:(NSData *)aData;
// data should NOT include the starting 0xF0 or the ending 0xF7 (EOX)
Expand Down
Loading