forked from flit/MidiKeys
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAppController.h
146 lines (117 loc) · 3.77 KB
/
AppController.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
//
// AppController.h
// MidiKeys
//
// Created by Chris Reed on Tue Oct 15 2002.
// Copyright (c) 2002-2003 Chris Reed. All rights reserved.
//
#import <AppKit/AppKit.h>
#import <CoreMIDI/CoreMIDI.h>
#import <Carbon/Carbon.h>
@class MidiKeyView;
@class KeyMapManager;
@class MidiKeyMap;
@class OverlayIndicator;
//! The name we use for our CoreMIDI client and virtual source
#define kMyClientName CFSTR("MidiKeys")
//! Name of the octave up overlay image.
#define kOctaveUpOverlayImage @"OctaveUp"
//! Name of the octave down overlay image.
#define kOctaveDownOverlayImage @"OctaveDown"
//! \name Keycodes for arrow keys
//@{
#define kRightArrowKeycode 124
#define kLeftArrowKeycode 123
#define kUpArrowKeycode 126
#define kDownArrowKeycode 125
//@}
//! Direction of velocity adjustment.
enum _velocity_up_or_down
{
kVelocityUp,
kVelocityDown
};
/*!
* @brief Main controller class for Midi Keys.
*
* Manages the keyboard window, all MIDI events, hot keys, menu items, and pretty much every
* thing else except for preferences.
*/
@interface AppController : NSObject
{
IBOutlet NSPopUpButton *destinationPopup;
IBOutlet NSPopUpButton *sourcePopup;
IBOutlet MidiKeyView *midiKeys;
IBOutlet NSSlider *velocitySlider;
IBOutlet NSPopUpButton * channelPopup;
IBOutlet KeyMapManager *keyMapManager;
IBOutlet NSView *toggleView;
IBOutlet NSView *hiddenItemsView;
IBOutlet NSButton *midiThruCheckbox;
IBOutlet NSMenuItem * _toggleHotKeysMenuItem;
MIDIClientRef clientRef;
MIDIPortRef outputPort;
MIDIPortRef inputPort;
MIDIEndpointRef virtualSourceEndpoint;
MIDIUniqueID virtualSourceUID;
MIDIEndpointRef selectedSource;
BOOL isSourceConnected;
MIDIEndpointRef selectedDestination;
BOOL isDestinationConnected; // if YES, we're not using the virtual source
BOOL performMidiThru;
float currentVelocity;
float maxVelocity;
int currentChannel;
int octaveOffset;
MidiKeyMap *keyMap;
EventHotKeyRef _toggleHotKeyRef;
EventHotKeyRef octaveUpHotKeyRef;
EventHotKeyRef octaveDownHotKeyRef;
EventHotKeyRef velocityUpHotKeyRef;
EventHotKeyRef velocityDownHotKeyRef;
BOOL hotKeysAreRegistered;
BOOL makeWindowSolidWhenOnTop;
BOOL isWindowToggled;
float toggleDelta;
NSTimer *velocityHotKeyTimer;
OverlayIndicator *_indicator;
// NSStatusItem * _hotKeysStatusItem;
}
- (IBAction)destinationSelected:(id)sender;
- (IBAction)sourceSelected:(id)sender;
- (IBAction)velocitySliderChanged:(id)sender;
- (IBAction)channelDidChange:(id)sender;
- (IBAction)toggleMidiThru:(id)sender;
- (IBAction)toggleMidiControls:(id)sender;
- (IBAction)octaveUp:(id)sender;
- (IBAction)octaveDown:(id)sender;
@end
@interface AppController (HotKeys)
- (IBAction)toggleHotKeys:(id)sender;
- (void)enableHotKeys;
- (void)disableHotKeys;
- (void)registerOctaveHotKeysWithModifiers:(int)modifiers;
- (void)unregisterOctaveHotKeys;
- (void)handleVelocityKeyPressedUpOrDown:(int)upOrDown;
- (void)velocityHotKeyTimerFired:(NSTimer *)timer;
- (void)handleVelocityKeyReleased;
- (void)hotKeyPressed:(UInt32)identifier;
- (void)hotKeyReleased:(UInt32)identifier;
- (void)registerToggleHotKey;
- (void)unregisterToggleHotKey;
- (void)registerHotKeys;
- (void)unregisterHotKeys;
- (void)displayHotKeysOverlay;
@end
@interface AppController (MIDI)
- (NSString *)nameForMidiEndpoint:(MIDIEndpointRef)theEndpoint;
// use vel=0 for off
- (void)sendMidiNote:(int)midiNote channel:(int)channel velocity:(int)velocity;
- (void)handleMidiNotification:(const MIDINotification *)message;
- (void)receiveMidiPacketList:(const MIDIPacketList *)packetList;
- (void)adjustVelocity:(float)delta;
- (IBAction)sendAllNotesOff:(id)sender;
- (NSString *)characterForMidiNote:(int)note;
@end
void MyNotifyProc(const MIDINotification *message, void *refCon);
void MyMidiReadProc(const MIDIPacketList *pktlist, void *refCon, void *connRefCon);