Skip to content

Commit

Permalink
Now combining lighting information to increase joy.
Browse files Browse the repository at this point in the history
NOTE: Follow updated SETUP.md.
  • Loading branch information
tillt committed Jan 14, 2023
1 parent e482471 commit ec64abe
Show file tree
Hide file tree
Showing 20 changed files with 560 additions and 168 deletions.
18 changes: 16 additions & 2 deletions KompleteSynthesia.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
BB49B3B9295CC8AF00D18605 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = BB49B3B8295CC8AF00D18605 /* main.m */; };
BB49B3C3295CC91000D18605 /* LogViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = BB49B3C1295CC91000D18605 /* LogViewController.m */; };
BB49B3C4295CC91000D18605 /* LogViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = BB49B3C2295CC91000D18605 /* LogViewController.xib */; };
BB8570FA2971935B0004218B /* SynthesiaController.m in Sources */ = {isa = PBXBuildFile; fileRef = BB8570F92971935B0004218B /* SynthesiaController.m */; };
BB8570FC2971AD980004218B /* README.md in Resources */ = {isa = PBXBuildFile; fileRef = BB8570FB2971AD980004218B /* README.md */; };
BB8570FE2971ED4B0004218B /* SETUP.md in Resources */ = {isa = PBXBuildFile; fileRef = BB8570FD2971ED4A0004218B /* SETUP.md */; };
BBA0166929611D1D0018B2DB /* MIDI2HIDController.m in Sources */ = {isa = PBXBuildFile; fileRef = BBA0166829611D1D0018B2DB /* MIDI2HIDController.m */; };
/* End PBXBuildFile section */

Expand All @@ -34,6 +37,10 @@
BB49B3C0295CC91000D18605 /* LogViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LogViewController.h; sourceTree = "<group>"; };
BB49B3C1295CC91000D18605 /* LogViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LogViewController.m; sourceTree = "<group>"; };
BB49B3C2295CC91000D18605 /* LogViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = LogViewController.xib; sourceTree = "<group>"; };
BB8570F82971935B0004218B /* SynthesiaController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SynthesiaController.h; sourceTree = "<group>"; };
BB8570F92971935B0004218B /* SynthesiaController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SynthesiaController.m; sourceTree = "<group>"; };
BB8570FB2971AD980004218B /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = SOURCE_ROOT; };
BB8570FD2971ED4A0004218B /* SETUP.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = SETUP.md; sourceTree = SOURCE_ROOT; };
BBA0166729611D1D0018B2DB /* MIDI2HIDController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MIDI2HIDController.h; sourceTree = "<group>"; };
BBA0166829611D1D0018B2DB /* MIDI2HIDController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MIDI2HIDController.m; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -79,11 +86,15 @@
BB3182182967A037005EB410 /* HIDController.m */,
BB31821429679983005EB410 /* MIDIController.h */,
BB31821529679983005EB410 /* MIDIController.m */,
BB8570F82971935B0004218B /* SynthesiaController.h */,
BB8570F92971935B0004218B /* SynthesiaController.m */,
BB49B3C2295CC91000D18605 /* LogViewController.xib */,
BB49B3B3295CC8AF00D18605 /* Assets.xcassets */,
BB49B3B5295CC8AF00D18605 /* MainMenu.xib */,
BB49B3B8295CC8AF00D18605 /* main.m */,
BB49B3BA295CC8AF00D18605 /* KompleteSynthesia.entitlements */,
BB8570FB2971AD980004218B /* README.md */,
BB8570FD2971ED4A0004218B /* SETUP.md */,
);
path = KompleteSynthesia;
sourceTree = "<group>";
Expand Down Expand Up @@ -147,6 +158,8 @@
files = (
BB49B3C4295CC91000D18605 /* LogViewController.xib in Resources */,
BB49B3B4295CC8AF00D18605 /* Assets.xcassets in Resources */,
BB8570FC2971AD980004218B /* README.md in Resources */,
BB8570FE2971ED4B0004218B /* SETUP.md in Resources */,
BB49B3B7295CC8AF00D18605 /* MainMenu.xib in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -158,6 +171,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
BB8570FA2971935B0004218B /* SynthesiaController.m in Sources */,
BB49B3B9295CC8AF00D18605 /* main.m in Sources */,
BB3182192967A037005EB410 /* HIDController.m in Sources */,
BB31821629679983005EB410 /* MIDIController.m in Sources */,
Expand Down Expand Up @@ -315,7 +329,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 11.0;
MARKETING_VERSION = 0.11;
MARKETING_VERSION = 0.20;
PRODUCT_BUNDLE_IDENTIFIER = tillt.KompleteSynthesia;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down Expand Up @@ -348,7 +362,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 11.0;
MARKETING_VERSION = 0.11;
MARKETING_VERSION = 0.20;
PRODUCT_BUNDLE_IDENTIFIER = tillt.KompleteSynthesia;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down
4 changes: 3 additions & 1 deletion KompleteSynthesia/AppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

#import <Cocoa/Cocoa.h>

@interface AppDelegate : NSObject <NSApplicationDelegate, NSMenuDelegate>
@protocol SynthesiaControllerDelegate;

@interface AppDelegate : NSObject <NSApplicationDelegate, NSMenuDelegate, SynthesiaControllerDelegate>


@end
Expand Down
44 changes: 35 additions & 9 deletions KompleteSynthesia/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
#import "AppDelegate.h"
#import "MIDI2HIDController.h"
#import "LogViewController.h"
#import "SynthesiaController.h"

@interface AppDelegate ()

@property (nonatomic, strong) IBOutlet NSWindow *window;
@property (nonatomic, strong) MIDI2HIDController* midi2hidController;
@property (nonatomic, strong) LogViewController* logViewController;
@property (nonatomic, strong) SynthesiaController* synthesia;

@property (nonatomic, strong) NSPopover *popover;
@property (nonatomic, strong) NSMenu *statusMenu;
Expand All @@ -25,19 +27,19 @@ @implementation AppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Hide application icon.
[[NSApplication sharedApplication] setActivationPolicy:NSApplicationActivationPolicyAccessory];

_logViewController = [[LogViewController alloc] initWithNibName:@"LogViewController" bundle:NULL];

NSError* error = nil;
_midi2hidController = [[MIDI2HIDController alloc] initWithLogController:_logViewController error:&error];
if (_midi2hidController == nil) {
[[NSAlert alertWithError:error] runModal];
[NSApp performSelector:@selector(terminate:) withObject:nil afterDelay:0.0];
return;
}


// Hide application icon.
[[NSApplication sharedApplication] setActivationPolicy:NSApplicationActivationPolicyAccessory];

self.statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];

self.statusItem.button.action = @selector(showStatusMenu:);
Expand All @@ -46,15 +48,20 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
NSImage *image = [NSImage imageNamed:@"StatusIcon"];
[image setTemplate:true];
self.statusItem.button.image = image;

NSMenu *menu = [[NSMenu alloc] init];
[menu addItemWithTitle:_midi2hidController.hidStatus action:nil keyEquivalent:@""];
[menu addItemWithTitle:[SynthesiaController status] action:nil keyEquivalent:@""];
[menu addItem:[NSMenuItem separatorItem]];
[menu addItemWithTitle:@"Reset" action:@selector(reset:) keyEquivalent:@""];
[menu addItemWithTitle:@"Show Log" action:@selector(showLog:) keyEquivalent:@""];
[menu addItem:[NSMenuItem separatorItem]];
[menu addItemWithTitle:@"Quit" action:@selector(terminate:) keyEquivalent:@"q"];

menu.delegate = self;
self.statusMenu = menu;

_synthesia = [[SynthesiaController alloc] initWithDelegate:self];
}

- (void)showStatusMenu:(id)sender
Expand All @@ -63,6 +70,16 @@ - (void)showStatusMenu:(id)sender
[self.statusItem.button performClick:nil];
}

- (void)reset:(id)sender
{
NSError* error = nil;
if ([_midi2hidController reset:&error] == NO) {
[[NSAlert alertWithError:error] runModal];
[NSApp performSelector:@selector(terminate:) withObject:nil afterDelay:0.0];
return;
}
}

- (void)showLog:(id)sender
{
if (self.popover == nil) {
Expand All @@ -77,8 +94,8 @@ - (void)showLog:(id)sender
[self.popover performClose:sender];
} else {
[self.popover showRelativeToRect:self.statusItem.button.bounds ofView:self.statusItem.button preferredEdge:NSRectEdgeMinY];
__block AppDelegate *blocksafeSelf = self;
[NSEvent addGlobalMonitorForEventsMatchingMask:NSEventTypeLeftMouseDown | NSEventTypeRightMouseDown handler:^(NSEvent *event) {
__block AppDelegate* blocksafeSelf = self;
[NSEvent addGlobalMonitorForEventsMatchingMask:NSEventTypeLeftMouseDown | NSEventTypeRightMouseDown handler:^(NSEvent* event) {
[blocksafeSelf.popover performClose:nil];
}];
}
Expand All @@ -93,4 +110,13 @@ - (BOOL)applicationSupportsSecureRestorableState:(NSApplication *)app
return YES;
}

#pragma mark SynthesiaControllerDelegate

- (void)synthesiaStateUpdate:(NSString*)status
{
assert(self.statusMenu.itemArray.count > 1);
NSMenuItem* item = self.statusMenu.itemArray[1];
item.title = status;
}

@end
5 changes: 5 additions & 0 deletions KompleteSynthesia/HIDController.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ NS_ASSUME_NONNULL_BEGIN

extern const unsigned char kKompleteKontrolColorBlue;
extern const unsigned char kKompleteKontrolColorLightBlue;
extern const unsigned char kKompleteKontrolColorBrightBlue;
extern const unsigned char kKompleteKontrolColorGreen;
extern const unsigned char kKompleteKontrolColorLightGreen;
extern const unsigned char kKompleteKontrolColorBrightGreen;
extern const unsigned char kKompleteKontrolColorBrightWhite;
extern const unsigned char kKompleteKontrolColorRed;

enum {
KKBUTTON_PLAY,
Expand Down Expand Up @@ -42,6 +46,7 @@ enum {
- (void)lightsSwoosh;
- (BOOL)drawImage:(NSImage*)image screen:(uint8_t)screen x:(unsigned int)x y:(unsigned int)y error:(NSError**)error;
- (void)receivedReport:(unsigned char*)report;
- (unsigned char)keyColor:(int)note;

@end

Expand Down
19 changes: 15 additions & 4 deletions KompleteSynthesia/HIDController.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
#import <CoreGraphics/CoreGraphics.h>
#import <CoreImage/CoreImage.h>

/// Detects a Komplete Kontrol S-series controller. Listens for any incoming button presses and forwards them
/// to the delegate.

const uint32_t kVendorID = 0x17CC;

// MK1 controllers.
Expand All @@ -32,9 +35,11 @@
const uint32_t kPID_S88MK2 = 0x1630;

const uint8_t kKompleteKontrolColorBlue = 0x2d; // 011101
const uint8_t kKompleteKontrolColorLightBlue = 0x2f; // 101111
const uint8_t kKompleteKontrolColorLightBlue = 0x2e;
const uint8_t kKompleteKontrolColorBrightBlue = 0x2f; // 101111
const uint8_t kKompleteKontrolColorGreen = 0x1d; // 011101
const uint8_t kKompleteKontrolColorLightGreen = 0x1f; // 011111
const uint8_t kKompleteKontrolColorLightGreen = 0x1e;
const uint8_t kKompleteKontrolColorBrightGreen = 0x1f; // 011111

const uint8_t kKompleteKontrolColorRed = 0x04; // 000100
const uint8_t kKompleteKontrolColorOrange = 0x08; // 001000
Expand All @@ -55,7 +60,7 @@

const uint8_t kCommandLightGuideUpdateMK1 = 0x82;
const uint8_t kCommandLightGuideUpdateMK2 = 0x81;
const size_t kKompleteKontrolLightGuideMessageSize = 80;
const size_t kKompleteKontrolLightGuideMessageSize = 250;
const size_t kKompleteKontrolLightGuideKeyMapSize = kKompleteKontrolLightGuideMessageSize - 1;

// This buttons lighting message likely is MK2 specific.
Expand Down Expand Up @@ -140,6 +145,12 @@ @implementation HIDController {
IOHIDDeviceRef device;
}

- (unsigned char)keyColor:(int)note
{
assert(note < kKompleteKontrolLightGuideKeyMapSize);
return _keys[note];
}

- (void)receivedReport:(unsigned char*)report
{
if (report[2] == 0x10) {
Expand Down Expand Up @@ -340,7 +351,7 @@ - (IOHIDDeviceRef)detectKeyboardController:(NSError**)error
NSLog(@"No Native Instruments keyboard controller detected");
if (error != nil) {
NSDictionary *userInfo = @{
NSLocalizedDescriptionKey : @"Keyboard Error: No Native Instruments controller detected",
NSLocalizedDescriptionKey : @"No Native Instruments controller detected",
NSLocalizedRecoverySuggestionErrorKey : @"Make sure the keyboard is connected and powered on."
};
*error = [NSError errorWithDomain:[[NSBundle bundleForClass:[self class]] bundleIdentifier] code:-1 userInfo:userInfo];
Expand Down
4 changes: 3 additions & 1 deletion KompleteSynthesia/LogViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ - (void)dealloc

- (void)logLine:(NSString*)l
{
NSLog(l);

// Assert the view is loaded.
NSView* view = self.view;
// Avoid unused variable.
Expand All @@ -42,7 +44,7 @@ - (void)logLine:(NSString*)l
NSFontAttributeName: [NSFont monospacedSystemFontOfSize:11 weight:NSFontWeightLight],
NSForegroundColorAttributeName: NSColor.textColor
};
NSAttributedString *attrstr = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@: %@", t, l] attributes:attributes];
NSAttributedString *attrstr = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@: %@\n", t, l] attributes:attributes];
[self.textView.textStorage appendAttributedString:attrstr];
[self.textView scrollRangeToVisible: NSMakeRange(self.textView.string.length, 0)];
}
Expand Down
1 change: 1 addition & 0 deletions KompleteSynthesia/MIDI2HIDController.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (copy, nonatomic) NSString* midiStatus;

- (id)initWithLogController:(LogViewController*)lc error:(NSError**)error;
- (BOOL)reset:(NSError**)error;

@end

Expand Down
Loading

0 comments on commit ec64abe

Please sign in to comment.