| 1 |
/* GraphicWindowController.h */ |
| 2 |
/* |
| 3 |
Copyright (c) 2000-2017 Toshi Nagata. All rights reserved. |
| 4 |
|
| 5 |
This program is free software; you can redistribute it and/or modify |
| 6 |
it under the terms of the GNU General Public License as published by |
| 7 |
the Free Software Foundation version 2 of the License. |
| 8 |
|
| 9 |
This program is distributed in the hope that it will be useful, |
| 10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
GNU General Public License for more details. |
| 13 |
*/ |
| 14 |
|
| 15 |
#import <Cocoa/Cocoa.h> |
| 16 |
#import "MDHeaders.h" |
| 17 |
|
| 18 |
#define kGraphicWindowControllerMaxNumberOfClientViews 8 |
| 19 |
|
| 20 |
@class GraphicClientView; |
| 21 |
@class GraphicRulerView; |
| 22 |
@class GraphicSplitterView; |
| 23 |
@class PlayingViewController; |
| 24 |
@class GraphicBackgroundView; |
| 25 |
|
| 26 |
typedef struct ClientRecord { |
| 27 |
GraphicBackgroundView *container; |
| 28 |
GraphicClientView *client; |
| 29 |
GraphicRulerView *ruler; |
| 30 |
GraphicSplitterView *splitter; |
| 31 |
} ClientRecord; |
| 32 |
|
| 33 |
typedef struct TrackInfo { |
| 34 |
int trackNum; |
| 35 |
char focusFlag; |
| 36 |
} TrackInfo; |
| 37 |
|
| 38 |
// Associated operations for each track |
| 39 |
enum { |
| 40 |
kGraphicShow = 1, // show the events |
| 41 |
kGraphicEdit = 2, // allow editing existing events |
| 42 |
kGraphicDraw = 4 // allow inserting new events (with pencil tools) |
| 43 |
}; |
| 44 |
|
| 45 |
// Graphic Tool (returned by graphicTool) |
| 46 |
enum { |
| 47 |
kGraphicRectangleSelectTool = 1, |
| 48 |
kGraphicIbeamSelectTool, |
| 49 |
kGraphicPencilTool |
| 50 |
}; |
| 51 |
|
| 52 |
// Line shape (returned by graphicLineShape) |
| 53 |
enum { |
| 54 |
kGraphicLinearShape = 1, |
| 55 |
kGraphicParabolaShape, |
| 56 |
kGraphicArcShape, |
| 57 |
kGraphicSigmoidShape, |
| 58 |
kGraphicRandomShape |
| 59 |
}; |
| 60 |
|
| 61 |
/* |
| 62 |
// Selection mode (returned by graphicSelectionMode) |
| 63 |
enum { |
| 64 |
kGraphicRectangleSelectionMode = 0, |
| 65 |
kGraphicIbeamSelectionMode, |
| 66 |
kGraphicMarqueeSelectionMode |
| 67 |
}; |
| 68 |
*/ |
| 69 |
|
| 70 |
// Editing mode for strip chart (returned by graphicEditingMode) |
| 71 |
enum { |
| 72 |
kGraphicSetMode = 1, |
| 73 |
kGraphicAddMode, |
| 74 |
kGraphicScaleMode, |
| 75 |
kGraphicLimitMaxMode, |
| 76 |
kGraphicLimitMinMode |
| 77 |
}; |
| 78 |
|
| 79 |
enum { |
| 80 |
kRecButtonTag = 0, |
| 81 |
kStopButtonTag, |
| 82 |
kForwardButtonTag, |
| 83 |
kRewindButtonTag, |
| 84 |
kPauseButtonTag, |
| 85 |
kPlayButtonTag |
| 86 |
}; |
| 87 |
|
| 88 |
@interface GraphicWindowController : NSWindowController |
| 89 |
{ |
| 90 |
IBOutlet GraphicBackgroundView *myMainView; // Main graphic view (containing piano roll, etc.) |
| 91 |
IBOutlet NSTableView *myTableView; // Track table |
| 92 |
IBOutlet NSView *myFloatingView; // View to draw playing cursor etc. |
| 93 |
IBOutlet NSView *myToolbarView; // The view containing tools for graphic editing |
| 94 |
IBOutlet NSScroller *myScroller; // The common scroller for all graphic client views |
| 95 |
|
| 96 |
IBOutlet NSView *myPlayerView; // The view containing player controls |
| 97 |
IBOutlet PlayingViewController *playingViewController; // The playing view controller |
| 98 |
|
| 99 |
// 0: TimeChartView, 1: PianoRollView, 2 and after: StripChartView |
| 100 |
int myClientViewsCount; |
| 101 |
ClientRecord records[kGraphicWindowControllerMaxNumberOfClientViews]; |
| 102 |
|
| 103 |
MDCalibrator *calib; // calibrator for tick conversion |
| 104 |
|
| 105 |
/* The visible and editable track numbers are cached in this array */ |
| 106 |
int *sortedTrackNumbers; // If NULL, then needs update |
| 107 |
int visibleTrackCount; // If negative, then sortedTrackNumbers needs update |
| 108 |
|
| 109 |
float beginTick; // The tick of the left origin |
| 110 |
float pixelsPerQuarter; // Pixels per a quarter note |
| 111 |
float quantize; // Mouse position quantize (unit = quarter note; 0: no quantize) |
| 112 |
|
| 113 |
// Note on/off are cached here too |
| 114 |
NSArray *noteCache; |
| 115 |
float noteCacheBeginBeat, noteCacheEndBeat; |
| 116 |
|
| 117 |
// The position of the time indicator during playing |
| 118 |
MDTickType timeIndicatorPos; // In tick |
| 119 |
NSRect timeIndicatorRect; // In MyFloatingView coordinates |
| 120 |
// NSBitmapImageRep *cachedImage; // Image |
| 121 |
MDTickType endOfSequencePos; // In tick |
| 122 |
|
| 123 |
// Tracking rect |
| 124 |
NSTrackingRectTag trackingRectTag; |
| 125 |
|
| 126 |
// Graphic Tool/LineShape/Mode |
| 127 |
int graphicTool; |
| 128 |
int graphicLineShape; |
| 129 |
int graphicEditingMode; |
| 130 |
// int graphicSelectionMode; |
| 131 |
|
| 132 |
float lastTimeIndicator; |
| 133 |
|
| 134 |
// Client view that received the last mouse event |
| 135 |
int lastMouseClientViewIndex; |
| 136 |
|
| 137 |
// Zoom/unzoom buffer and current position |
| 138 |
NSMutableArray *zoomUndoBuffer; |
| 139 |
int zoomUndoIndex; |
| 140 |
|
| 141 |
// Selected tracks when the selection changed last |
| 142 |
NSIndexSet *lastSelectedTracks; |
| 143 |
|
| 144 |
// This flag is asserted in windowDidLoad and negated on first call to windowDidResize. |
| 145 |
// On newer version of Mac OS X, the document window may be silently resized by system |
| 146 |
// during startup, which may causes inconsistency of the layout of the subviews. This |
| 147 |
// flag avoid such inconsistency. |
| 148 |
BOOL waitingForFirstWindowResize; |
| 149 |
|
| 150 |
// This flag is asserted on invocation of [tryTrackColor:], and negated on first |
| 151 |
// idle event. While this flag is asserted, changeColor undo events are not registered. |
| 152 |
BOOL changingTrackColor; |
| 153 |
} |
| 154 |
|
| 155 |
//+ (NSCursor *)horizontalMoveCursor; |
| 156 |
//+ (NSCursor *)verticalMoveCursor; |
| 157 |
//+ (NSCursor *)stretchCursor; |
| 158 |
//+ (NSCursor *)moveAroundCursor; |
| 159 |
|
| 160 |
- (float)rulerWidth; |
| 161 |
|
| 162 |
- (id)init; |
| 163 |
|
| 164 |
// NSWindowControllerAdditions overrides |
| 165 |
+ (BOOL)canContainMultipleTracks; |
| 166 |
|
| 167 |
- (void)setFocusFlag: (BOOL) flag onTrack: (int)trackNum extending: (BOOL)extendFlag; |
| 168 |
- (BOOL)isFocusTrack: (int)trackNum; |
| 169 |
- (BOOL)isTrackSelected: (int32_t)trackNo; |
| 170 |
- (void)setIsTrackSelected: (int32_t)trackNo flag: (BOOL)flag; |
| 171 |
|
| 172 |
- (int32_t)trackCount; |
| 173 |
- (int32_t)visibleTrackCount; |
| 174 |
- (int)sortedTrackNumberAtIndex: (int)index; // For clientViews; focus track comes first |
| 175 |
|
| 176 |
- (float)pixelsPerQuarter; |
| 177 |
- (void)setPixelsPerQuarter: (float)newPixelsPerQuarter; |
| 178 |
- (float)pixelsPerTick; |
| 179 |
- (MDTickType)quantizedTickFromPixel: (float)pixel; |
| 180 |
- (float)quantizedPixelFromPixel: (float)pixel; |
| 181 |
- (float)pixelQuantum; |
| 182 |
|
| 183 |
- (void)showPlayPosition: (NSNotification *)notification; |
| 184 |
- (void)editingRangeChanged: (NSNotification *)notification; |
| 185 |
|
| 186 |
- (float)scrollPositionOfClientViews; |
| 187 |
- (void)scrollClientViewsToPosition: (float)pos; |
| 188 |
- (void)scrollClientViewsToTick: (MDTickType)tick; |
| 189 |
|
| 190 |
- (void)needsReloadClientViews: (NSNotification *)aNotification; |
| 191 |
|
| 192 |
- (void)verticalLinesFromTick: (MDTickType)fromTick timeSignature: (MDEvent **)timeSignature nextTimeSignature: (MDEvent **)nextTimeSignature lineIntervalInPixels: (float *)lineIntervalInPixels mediumCount: (int *)mediumCount majorCount: (int *)majorCount; |
| 193 |
|
| 194 |
- (MDTickType)sequenceDuration; |
| 195 |
- (float)sequenceDurationInQuarter; |
| 196 |
- (void)setInfoText: (NSString *)string; |
| 197 |
- (void)setCursorInfoPosition: (NSPoint)position; |
| 198 |
- (void)setCursorInfoText: (NSString *)string; |
| 199 |
- (void)updateCursorInfoForView: (NSView *)view atPosition: (NSPoint)pos; |
| 200 |
|
| 201 |
- (void)midiSetupDidChange: (NSNotification *)aNotification; |
| 202 |
- (void)windowDidResize:(NSNotification *)aNotification; |
| 203 |
|
| 204 |
- (void)setStripChartAtIndex: (int)index kind: (int)kind code: (int)code; |
| 205 |
- (IBAction)kindPopUpPressed: (id)sender; |
| 206 |
- (void)codeMenuItemSelected: (NSMenuItem *)item inSplitterView: (GraphicSplitterView *)view; |
| 207 |
- (void)setResolution: (float)resolution inSplitterView: (GraphicSplitterView *)view; |
| 208 |
- (IBAction)trackPopUpPressedInSplitterView: (id)sender; |
| 209 |
|
| 210 |
- (IBAction)expandHorizontally: (id)sender; |
| 211 |
- (IBAction)shrinkHorizontally: (id)sender; |
| 212 |
|
| 213 |
- (IBAction)toolButton: (id)sender; |
| 214 |
- (IBAction)shapeSelected: (id)sender; |
| 215 |
- (IBAction)modeSelected: (id)sender; |
| 216 |
|
| 217 |
- (IBAction)scrollerMoved: (id)sender; |
| 218 |
|
| 219 |
- (IBAction)quantizeSelected: (id)sender; |
| 220 |
|
| 221 |
- (IBAction)showEditingRange:(id)sender; |
| 222 |
|
| 223 |
- (void)zoomClientViewsWithPixelsPerQuarter:(float)ppq startingPos:(float)pos; |
| 224 |
- (void)unzoomClientViews; |
| 225 |
- (void)rezoomClientViews; |
| 226 |
|
| 227 |
- (void)setNeedsReloadClientViews; |
| 228 |
- (void)reloadClientViews; |
| 229 |
- (void)reflectClientViews; |
| 230 |
- (float)clientViewWidth; |
| 231 |
|
| 232 |
- (void)mouseEvent:(NSEvent *)theEvent receivedByClientView:(GraphicClientView *)cView; |
| 233 |
- (GraphicClientView *)lastMouseClientView; |
| 234 |
|
| 235 |
- (void)convertTick: (MDTickType)aTick toMeasure: (int32_t *)measure beat: (int32_t *)beat andTick: (int32_t *)tick; |
| 236 |
|
| 237 |
// Action method for GraphicSplitterView |
| 238 |
- (void)splitterViewStartedDragging: (GraphicSplitterView *)theView; |
| 239 |
- (void)splitterView: (GraphicSplitterView *)theView isDraggedTo: (float)y confirm: (BOOL)confirm; |
| 240 |
|
| 241 |
// Customized autoresizing for client views |
| 242 |
//- (void)resizeClientViewsWithOldMainViewSize: (NSSize)oldSize; |
| 243 |
- (BOOL)backgroundView:(NSView *)aView resizedWithOldSize:(NSSize)oldSize; |
| 244 |
|
| 245 |
// Modify data according to mouse events in the GraphicClientViews |
| 246 |
- (void)dragNotesByTick: (MDTickType)deltaTick andNote: (int)deltaNote sender: (GraphicClientView *)sender optionFlag: (BOOL)optionFlag; |
| 247 |
- (void)dragDurationByTick: (MDTickType)deltaTick sender: (GraphicClientView *)sender; |
| 248 |
- (void)dragEventsOfKind: (int)kind andCode: (int)code byTick: (MDTickType)deltaTick andValue: (float)deltaValue sender: (GraphicClientView *)sender optionFlag: (BOOL)optionFlag; |
| 249 |
|
| 250 |
- (NSColor *)colorForTrack: (int)track enabled: (BOOL)flag; |
| 251 |
|
| 252 |
// Accessor for current tool/lineshape/mode |
| 253 |
- (int)graphicTool; |
| 254 |
- (int)graphicLineShape; |
| 255 |
- (int)graphicEditingMode; |
| 256 |
//- (int)graphicSelectionMode; |
| 257 |
- (GraphicClientView *)clientViewAtIndex: (int)index; |
| 258 |
- (GraphicSplitterView *)splitterViewAtIndex: (int)index; |
| 259 |
- (GraphicRulerView *)rulerViewAtIndex: (int)index; |
| 260 |
- (GraphicBackgroundView *)enclosingContainerForClientView:(id)view; |
| 261 |
|
| 262 |
// Action methods for track table |
| 263 |
- (IBAction)openEventListWindow: (id)sender; |
| 264 |
- (IBAction)createNewTrack: (id)sender; |
| 265 |
- (IBAction)deleteSelectedTracks:(id)sender; |
| 266 |
- (IBAction)remapDevice: (id)sender; |
| 267 |
- (IBAction)changeTrackColor: (id)sender; |
| 268 |
- (IBAction)tryTrackColor: (id)sender; |
| 269 |
- (void)clearChangingColorFlag: (NSNotification *)aNotification; |
| 270 |
|
| 271 |
- (void)trackTableAction:(id)sender; |
| 272 |
- (void)trackTableDoubleAction:(id)sender; |
| 273 |
- (void)tableViewSelectionDidChange: (NSNotification *)aNotification; |
| 274 |
|
| 275 |
- (void)trackModified: (NSNotification *)notification; |
| 276 |
- (void)trackInserted: (NSNotification *)notification; |
| 277 |
- (void)trackDeleted: (NSNotification *)notification; |
| 278 |
|
| 279 |
// Action methods for graphic views |
| 280 |
//- (IBAction)changeControlNumber:(id)sender; |
| 281 |
//- (IBAction)shiftSelectedEvents:(id)sender; |
| 282 |
|
| 283 |
// Accessor for the subview controller |
| 284 |
- (id)playingViewController; |
| 285 |
|
| 286 |
// Show/hide time indicator |
| 287 |
- (void)showTimeIndicatorAtBeat: (float)beat; |
| 288 |
- (void)hideTimeIndicator; |
| 289 |
|
| 290 |
@end |