Skip to content

Commit

Permalink
Updating launch sequence, log view refactor, main menu improvements, …
Browse files Browse the repository at this point in the history
…misc other fixes
  • Loading branch information
SteffeyDev committed Mar 27, 2021
1 parent df785d4 commit 03793ad
Show file tree
Hide file tree
Showing 11 changed files with 270 additions and 182 deletions.
3 changes: 3 additions & 0 deletions atemOSC/AppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@
@property (retain) NSMutableArray* switchers;

- (void)incomingPortChanged:(int)inPortValue;

- (IBAction)bugFeatureButtonPressed:(id)sender;
- (IBAction)githubPageButtonPressed:(id)sender;
- (IBAction)websiteButtonPressed:(id)sender;

- (void)logMessage:(NSString *)message;

Expand Down
51 changes: 19 additions & 32 deletions atemOSC/AppDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ @implementation AppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
[self setupMenu];

endpoints = [[NSMutableArray alloc] init];
mOscReceiver = [[OSCReceiver alloc] initWithDelegate:self];

Expand Down Expand Up @@ -91,43 +89,23 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
}

[self checkForUpdate];
}

- (void)applicationWillBecomeActive:(NSNotification *)notification
{

dispatch_async(dispatch_get_main_queue(), ^{
if (!self->window)
{
Window *window = (Window *) [[NSApplication sharedApplication] mainWindow];
self->window = window;
}
Window *window = (Window *) [[NSApplication sharedApplication] mainWindow];
self->window = window;

[self->window loadSettingsFromPreferences];

if ([[self->window connectionView] switcher] != nil)
{
[[self->window outlineView] refreshList];
[[self->window connectionView] loadFromSwitcher:[[self->window connectionView] switcher]];
}
else
{
[[self->window outlineView] reloadData];
NSIndexSet* indexes = [[NSIndexSet alloc] initWithIndex:1];
[[self->window outlineView] selectRowIndexes:indexes byExtendingSelection:NO];
}

[[self->window logView] flushMessages];
[[self->window outlineView] reloadData];
NSIndexSet* indexes = [[NSIndexSet alloc] initWithIndex:1];
[[self->window outlineView] selectRowIndexes:indexes byExtendingSelection:NO];
});
}

- (void)setupMenu
- (void)applicationWillBecomeActive:(NSNotification *)notification
{
NSMenu* edit = [[[[NSApplication sharedApplication] mainMenu] itemWithTitle: @"Edit"] submenu];
if ([[edit itemAtIndex: [edit numberOfItems] - 1] action] == NSSelectorFromString(@"orderFrontCharacterPalette:"))
[edit removeItemAtIndex: [edit numberOfItems] - 1];
if ([[edit itemAtIndex: [edit numberOfItems] - 1] action] == NSSelectorFromString(@"startDictation:"))
[edit removeItemAtIndex: [edit numberOfItems] - 1];
if ([[edit itemAtIndex: [edit numberOfItems] - 1] isSeparatorItem])
[edit removeItemAtIndex: [edit numberOfItems] - 1];
[[self->window outlineView] refreshList];
[[self->window connectionView] loadFromSwitcher:[[self->window connectionView] switcher]];
}

- (void)checkForUpdate
Expand Down Expand Up @@ -191,6 +169,15 @@ - (IBAction)githubPageButtonPressed:(id)sender
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"https://github.com/SteffeyDev/atemOSC/"]];
}

- (IBAction)bugFeatureButtonPressed:(id)sender;
{
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"https://github.com/SteffeyDev/atemOSC/issues/new"]];
}

- (IBAction)websiteButtonPressed:(id)sender;
{
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"http://www.atemosc.com"]];
}

- (void) addSwitcher
{
Expand Down
25 changes: 16 additions & 9 deletions atemOSC/ConnectionView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,16 @@ - (void)controlTextDidEndEditing:(NSNotification *)notification
NSTextField* textField = (NSTextField *)[notification object];
Window *window = (Window *) [[NSApplication sharedApplication] mainWindow];

if ((textField == feedbackIpAddressTextField || textField == ipAddressTextField) && ![self isValidIPAddress:[textField stringValue]])
if ([textField stringValue].length > 0 && (textField == feedbackIpAddressTextField || textField == ipAddressTextField) && ![self isValidIPAddress:[textField stringValue]])
{
NSAlert *alert = [[NSAlert alloc] init];
[alert setMessageText:@"Invalid IP Adress"];
[alert setInformativeText:@"Please enter a valid IPv4 Address"];
[alert beginSheetModalForWindow:[[NSApplication sharedApplication] mainWindow] completionHandler:nil];
if (textField == feedbackIpAddressTextField)
[feedbackIpAddressTextField setStringValue:switcher.feedbackIpAddress];
else
[ipAddressTextField setStringValue:switcher.ipAddress];
return;
}

Expand Down Expand Up @@ -186,16 +190,19 @@ - (void)controlTextDidEndEditing:(NSNotification *)notification
else if (textField == nicknameTextField)
{
AppDelegate* appDel = (AppDelegate *) [[NSApplication sharedApplication] delegate];
for (Switcher *s : [appDel switchers])
if ([textField stringValue].length > 0)
{
if (s.nickname != nil && [textField stringValue].length > 0 && [s.nickname isEqualToString: [textField stringValue]])
for (Switcher *s : [appDel switchers])
{
NSAlert *alert = [[NSAlert alloc] init];
[alert setMessageText:@"Duplicate Nickname"];
[alert setInformativeText:@"Please assign a unique nickname to each switcher"];
[alert beginSheetModalForWindow:[[NSApplication sharedApplication] mainWindow] completionHandler:nil];
[textField setStringValue:switcher.nickname];
return;
if (s.nickname != nil && ![s.uid isEqualToString: switcher.uid] && [s.nickname isEqualToString: [textField stringValue]])
{
NSAlert *alert = [[NSAlert alloc] init];
[alert setMessageText:@"Duplicate Nickname"];
[alert setInformativeText:@"Please assign a unique nickname to each switcher"];
[alert beginSheetModalForWindow:[[NSApplication sharedApplication] mainWindow] completionHandler:nil];
[textField setStringValue:switcher.nickname];
return;
}
}
}
[switcher setNickname: [textField stringValue]];
Expand Down
9 changes: 6 additions & 3 deletions atemOSC/FeedbackMonitors.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1090,7 +1090,9 @@
uint16_t hours;
uint8_t minutes, seconds, frames;
switcher.mHyperdecks[hyperdeckId_]->GetCurrentClipTime(&hours, &minutes, &seconds, &frames);
sendFeedbackMessage(switcher, [NSString stringWithFormat:@"/hyperdeck/%lld/clip-time", hyperdeckId_], [OSCValue createWithString:[NSString stringWithFormat:@"%d:%d:%d:%d", hours, minutes, seconds, frames]]);

// The clip-time message gets sent every 100ms, which is too frequent to show in log
sendFeedbackMessage(switcher, [NSString stringWithFormat:@"/hyperdeck/%lld/clip-time", hyperdeckId_], [OSCValue createWithString:[NSString stringWithFormat:@"%d:%d:%d:%d", hours, minutes, seconds, frames]], false);
}
}

Expand All @@ -1101,8 +1103,9 @@
uint16_t hours;
uint8_t minutes, seconds, frames;
switcher.mHyperdecks[hyperdeckId_]->GetCurrentTimelineTime(&hours, &minutes, &seconds, &frames);

sendFeedbackMessage(switcher, [NSString stringWithFormat:@"/hyperdeck/%lld/timeline-time", hyperdeckId_], [OSCValue createWithString:[NSString stringWithFormat:@"%d:%d:%d:%d", hours, minutes, seconds, frames]]);

// The timeline-time message gets sent every 100ms, which is too frequent to show in log
sendFeedbackMessage(switcher, [NSString stringWithFormat:@"/hyperdeck/%lld/timeline-time", hyperdeckId_], [OSCValue createWithString:[NSString stringWithFormat:@"%d:%d:%d:%d", hours, minutes, seconds, frames]], false);
}
}

Expand Down
16 changes: 9 additions & 7 deletions atemOSC/LogView.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,21 @@

NS_ASSUME_NONNULL_BEGIN

@interface LogView : NSVisualEffectView {
NSMutableString* basicLog; // no debug info
NSMutableString* fullLog; // normal and debug log
BOOL debugMode;
@interface LogView : NSView<NSTableViewDelegate, NSTableViewDataSource> {
NSMutableArray* basicLog; // no debug info
NSMutableArray* fullLog; // normal and debug log
BOOL debugMode;
BOOL live;
NSDateFormatter* formatter;
}

@property (assign) IBOutlet NSTextView *logTextView;
@property (assign) IBOutlet NSButton *debugCheckbox;
@property (assign) IBOutlet NSTableView *tableView;
@property (assign) IBOutlet NSTextField *pausedLabel;

- (IBAction)debugChanged:(id)sender;

- (IBAction)debugChanged:(id)sender;

- (void)flushMessages;
- (void)logMessage:(NSString *)message;

@end
Expand Down
121 changes: 83 additions & 38 deletions atemOSC/LogView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -20,66 +20,111 @@ - (instancetype)initWithCoder:(NSCoder *)coder
{
if (self = [super initWithCoder:coder])
{
[self setBlendingMode:NSVisualEffectBlendingModeBehindWindow];
[self setMaterial:NSVisualEffectMaterialDark];
[self setState:NSVisualEffectStateActive];
self->fullLog = [[NSMutableString alloc] init];
self->basicLog = [[NSMutableString alloc] init];
//[self setBlendingMode:NSVisualEffectBlendingModeBehindWindow];
//[self setMaterial:NSVisualEffectMaterialDark];
//[self setState:NSVisualEffectStateActive];
self->fullLog = [[NSMutableArray alloc] init];
self->basicLog = [[NSMutableArray alloc] init];
self->debugMode = false;
self->live = true;
self->formatter = [[NSDateFormatter alloc] init];
[self->formatter setDateFormat:@"HH:mm:ss"];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(userScolled) name:NSScrollViewDidLiveScrollNotification object:nil];

NSTimer* timer = [NSTimer timerWithTimeInterval:0.5
target:self
selector:@selector(reloadData)
userInfo:nil
repeats:YES];
[[NSRunLoop mainRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];

return self;
}
return nil;
}

- (void)logMessage:(NSString *)message
// This will be run twice a second
- (void)reloadData
{
if (message) {
NSLog(@"%@", message);

NSDate *now = [NSDate date];
NSDateFormatter *formatter = nil;
formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"HH:mm:ss"];

NSString *messageWithNewLine = [NSString stringWithFormat:@"[%@] %@\n", [formatter stringFromDate:now], message];
NSMutableAttributedString *attributedMessage = [[NSMutableAttributedString alloc]initWithString:messageWithNewLine];
if (self->live)
{
if (self->fullLog.count > 2000)
{
[self->fullLog removeObjectsInRange:NSMakeRange(0, fmax(self->fullLog.count - 2100, 100))];
}
if (self->basicLog.count > 2000)
{
[self->basicLog removeObjectsInRange:NSMakeRange(0, fmax(self->basicLog.count - 2100, 100))];
}
[[self tableView] reloadData];
[[self tableView] scrollToEndOfDocument:nil];
}
}

[fullLog appendString:messageWithNewLine];
if (![message containsString:@"[Debug]"])
[basicLog appendString:messageWithNewLine];
- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView
{
return debugMode ? fullLog.count : basicLog.count;
}

if (![message containsString:@"[Debug]"] || debugMode)
- (NSTableCellView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
{
NSTableCellView *cell = [tableView makeViewWithIdentifier:@"cell" owner:self];
[cell.textField setStringValue: debugMode ? [fullLog objectAtIndex:row] : [basicLog objectAtIndex:row]];
return cell;
}

- (BOOL)tableView:(NSTableView *)aTableView shouldSelectRow:(NSInteger)rowIndex
{
return NO;
}

// If the user scrolls up in the log, pause live updates so that they can inspect the log
// When they scroll back to the bottom, resume live updates
- (void)userScolled
{
BOOL scrollAtBottom = [[[[self tableView] enclosingScrollView] verticalScroller] floatValue] == 1.0;
BOOL scrollNeeded = [[[self tableView] enclosingScrollView] documentView].bounds.size.height > [[[self tableView] enclosingScrollView] contentView].bounds.size.height;
if (scrollAtBottom || !scrollNeeded)
{
if (self->live == NO)
{
[[self pausedLabel] setHidden:YES];
self->live = YES;
dispatch_async(dispatch_get_main_queue(), ^{
NSColor *color = [[self logTextView] textColor];
[[self logTextView].textStorage appendAttributedString:attributedMessage];
[[self logTextView] scrollRangeToVisible: NSMakeRange([self logTextView].string.length, 0)];

// Need to set color to original color, because adding attributed string resets the text color to black for some reason
[[self logTextView] setTextColor:color];
[[self tableView] reloadData];
[[self tableView] layout];
[[self tableView] scrollToEndOfDocument:nil];
});
}
}
else if (self->live == YES)
{
[[self pausedLabel] setHidden:NO];
self->live = NO;
}
}

- (void)flushMessages
- (void)logMessage:(NSString *)message
{
NSColor *color = [[self logTextView] textColor];
if ([[self debugCheckbox] state])
{
[[[self logTextView] textStorage] setAttributedString:[[NSAttributedString alloc] initWithString:fullLog]];
}
else
{
[[[self logTextView] textStorage] setAttributedString:[[NSAttributedString alloc] initWithString:basicLog]];
if (message) {
NSLog(@"%@", message);

NSDate *now = [NSDate date];
NSString *messageWithTime = [NSString stringWithFormat:@"[%@] %@", [self->formatter stringFromDate:now], message];
BOOL isDebugMessage = [message containsString:@"[Debug]"]; // calc here for performance

// Keep this update small and fast, do more heavy lifting on the task run once a second
dispatch_async(dispatch_get_main_queue(), ^{
[self->fullLog addObject:messageWithTime];
if (!isDebugMessage)
[self->basicLog addObject:messageWithTime];
});
}
[[self logTextView] scrollRangeToVisible: NSMakeRange([self logTextView].string.length, 0)];
[[self logTextView] setTextColor:color];
}

- (IBAction)debugChanged:(id)sender {
self->debugMode = [[self debugCheckbox] state];
[self flushMessages];
[[self tableView] reloadData];
}

@end
Loading

0 comments on commit 03793ad

Please sign in to comment.