• R/O
  • SSH
  • HTTPS

alchemusica: 提交


Commit MetaInfo

修订版199 (tree)
时间2022-04-04 23:50:52
作者toshinagata1964

Log Message

Vertical grids are shown in strip chart view

更改概述

差异

--- trunk/Classes/GraphicClientView.h (revision 198)
+++ trunk/Classes/GraphicClientView.h (revision 199)
@@ -23,6 +23,10 @@
2323 kGraphicStripChartViewType = 3
2424 };
2525
26+extern CGFloat gLineDash1[];
27+extern CGFloat gLineDash2[];
28+extern CGFloat gDashWidth;
29+
2630 @interface GraphicClientView : NSView {
2731 id dataSource; // The data source
2832 float minValue, maxValue;
@@ -78,6 +82,8 @@
7882
7983 // Drawing
8084 - (void)drawContentsInRect:(NSRect)aRect;
85+- (void)drawVerticalLinesInRect: (NSRect)aRect;
86+- (NSColor *)verticalLineColor: (BOOL)beforeEndOfSequence;
8187
8288 //- (int)selectMode;
8389 - (BOOL)isDragging;
--- trunk/Classes/GraphicClientView.m (revision 198)
+++ trunk/Classes/GraphicClientView.m (revision 199)
@@ -96,6 +96,99 @@
9696 {
9797 }
9898
99+CGFloat gLineDash1[] = {6.0f, 2.0f};
100+CGFloat gLineDash2[] = {2.0f, 6.0f};
101+CGFloat gDashWidth = 8.0f;
102+
103+- (NSColor *)verticalLineColor: (BOOL)beforeEndOfSequence;
104+{
105+ if (beforeEndOfSequence)
106+ return [NSColor blackColor];
107+ else
108+ return [NSColor grayColor];
109+}
110+
111+- (void)drawVerticalLinesInRect: (NSRect)aRect
112+{
113+ float ppt;
114+ MDTickType beginTick, endTick, duration;
115+ float originx, limitx;
116+ NSPoint pt1, pt2;
117+ int i, numLines;
118+ NSBezierPath *lines, *subLines;
119+ ppt = [dataSource pixelsPerTick];
120+ beginTick = aRect.origin.x / ppt;
121+ endTick = (aRect.origin.x + aRect.size.width) / ppt + 1;
122+ duration = [dataSource sequenceDuration];
123+ limitx = duration * ppt;
124+ pt1.y = (CGFloat)(floor(aRect.origin.y / gDashWidth) * gDashWidth);
125+ pt2.y = (CGFloat)(ceil((aRect.origin.y + aRect.size.height) / gDashWidth) * gDashWidth);
126+ lines = [[NSBezierPath allocWithZone: [self zone]] init];
127+ subLines = [[NSBezierPath allocWithZone: [self zone]] init];
128+ originx = aRect.origin.x;
129+ if (originx == 0.0f)
130+ originx = 1.0f; /* Avoid drawing line at tick = 0 */
131+ pt2.x = 0.0f;
132+ while (beginTick < endTick) {
133+ int mediumCount, majorCount;
134+ MDEvent *sig1, *sig2;
135+ MDTickType sigTick, nextSigTick;
136+ float interval, startx;
137+ [dataSource verticalLinesFromTick: beginTick timeSignature: &sig1 nextTimeSignature: &sig2 lineIntervalInPixels: &interval mediumCount: &mediumCount majorCount: &majorCount];
138+ sigTick = (sig1 == NULL ? 0 : MDGetTick(sig1));
139+ nextSigTick = (sig2 == NULL ? kMDMaxTick : MDGetTick(sig2));
140+ if (nextSigTick > endTick)
141+ nextSigTick = endTick;
142+ startx = sigTick * ppt;
143+ numLines = (int)floor((nextSigTick - sigTick) * ppt / interval) + 1;
144+ i = (startx >= originx ? 0 : (int)floor((originx - startx) / interval));
145+ [[self verticalLineColor:true] set];
146+ for ( ; i < numLines; i++) {
147+ pt1.x = (CGFloat)(floor(startx + i * interval) + 0.5);
148+ if (pt1.x >= originx && pt1.x <= aRect.origin.x + aRect.size.width) {
149+ if (pt1.x > limitx && pt2.x <= limitx) {
150+ /* Draw the lines and set the color to gray */
151+ [lines setLineDash: gLineDash1 count: 2 phase: 0.0f];
152+ [subLines setLineDash: gLineDash2 count: 2 phase: 0.0f];
153+ [lines stroke];
154+ [subLines stroke];
155+ [lines removeAllPoints];
156+ [subLines removeAllPoints];
157+ [[self verticalLineColor:false] set];
158+ }
159+ pt2.x = pt1.x;
160+ if (i % majorCount == 0) {
161+ [lines moveToPoint: pt1];
162+ [lines lineToPoint: pt2];
163+ } else {
164+ [subLines moveToPoint: pt1];
165+ [subLines lineToPoint: pt2];
166+ }
167+ }
168+ }
169+ beginTick = nextSigTick;
170+ }
171+ [lines setLineDash: gLineDash1 count: 2 phase: 0.0f];
172+ [subLines setLineDash: gLineDash2 count: 2 phase: 0.0f];
173+ [lines stroke];
174+ [subLines stroke];
175+ [lines release];
176+ [subLines release];
177+
178+ [[NSColor blackColor] set];
179+ if (limitx < aRect.origin.x + aRect.size.width) {
180+ /* Draw the "end of sequence" line */
181+ float width = [NSBezierPath defaultLineWidth];
182+ pt1.x = pt2.x = limitx;
183+ [NSBezierPath strokeLineFromPoint: pt1 toPoint: pt2];
184+ [NSBezierPath setDefaultLineWidth: 2.0f];
185+ pt1.x = pt2.x += 3.0f;
186+ [NSBezierPath strokeLineFromPoint: pt1 toPoint: pt2];
187+ [NSBezierPath setDefaultLineWidth: width];
188+ }
189+}
190+
191+
99192 // Should be overridden in subclasses
100193 - (void)drawContentsInRect: (NSRect)aRect
101194 {
--- trunk/Classes/PianoRollView.m (revision 198)
+++ trunk/Classes/PianoRollView.m (revision 199)
@@ -27,10 +27,6 @@
2727
2828 @implementation PianoRollView
2929
30-static CGFloat sLineDash1[] = {6.0f, 2.0f};
31-static CGFloat sLineDash2[] = {2.0f, 6.0f};
32-static CGFloat sDashWidth = 8.0f;
33-
3430 - (id)initWithFrame: (NSRect)rect
3531 {
3632 self = [super initWithFrame: rect];
@@ -50,85 +46,6 @@
5046 return kGraphicPianoRollViewType;
5147 }
5248
53-- (void)drawVerticalLinesInRect: (NSRect)aRect
54-{
55- float ppt;
56- MDTickType beginTick, endTick, duration;
57- float originx, limitx;
58- NSPoint pt1, pt2;
59- int i, numLines;
60- NSBezierPath *lines, *subLines;
61- ppt = [dataSource pixelsPerTick];
62- beginTick = aRect.origin.x / ppt;
63- endTick = (aRect.origin.x + aRect.size.width) / ppt + 1;
64- duration = [dataSource sequenceDuration];
65- limitx = duration * ppt;
66- pt1.y = (CGFloat)(floor(aRect.origin.y / sDashWidth) * sDashWidth);
67- pt2.y = (CGFloat)(ceil((aRect.origin.y + aRect.size.height) / sDashWidth) * sDashWidth);
68- lines = [[NSBezierPath allocWithZone: [self zone]] init];
69- subLines = [[NSBezierPath allocWithZone: [self zone]] init];
70- originx = aRect.origin.x;
71- if (originx == 0.0f)
72- originx = 1.0f; /* Avoid drawing line at tick = 0 */
73- pt2.x = 0.0f;
74- while (beginTick < endTick) {
75- int mediumCount, majorCount;
76- MDEvent *sig1, *sig2;
77- MDTickType sigTick, nextSigTick;
78- float interval, startx;
79- [dataSource verticalLinesFromTick: beginTick timeSignature: &sig1 nextTimeSignature: &sig2 lineIntervalInPixels: &interval mediumCount: &mediumCount majorCount: &majorCount];
80- sigTick = (sig1 == NULL ? 0 : MDGetTick(sig1));
81- nextSigTick = (sig2 == NULL ? kMDMaxTick : MDGetTick(sig2));
82- if (nextSigTick > endTick)
83- nextSigTick = endTick;
84- startx = sigTick * ppt;
85- numLines = (int)floor((nextSigTick - sigTick) * ppt / interval) + 1;
86- i = (startx >= originx ? 0 : (int)floor((originx - startx) / interval));
87- for ( ; i < numLines; i++) {
88- pt1.x = (CGFloat)(floor(startx + i * interval) + 0.5);
89- if (pt1.x >= originx && pt1.x <= aRect.origin.x + aRect.size.width) {
90- if (pt1.x > limitx && pt2.x <= limitx) {
91- /* Draw the lines and set the color to gray */
92- [lines setLineDash: sLineDash1 count: 2 phase: 0.0f];
93- [subLines setLineDash: sLineDash2 count: 2 phase: 0.0f];
94- [lines stroke];
95- [subLines stroke];
96- [lines removeAllPoints];
97- [subLines removeAllPoints];
98- [[NSColor grayColor] set];
99- }
100- pt2.x = pt1.x;
101- if (i % majorCount == 0) {
102- [lines moveToPoint: pt1];
103- [lines lineToPoint: pt2];
104- } else {
105- [subLines moveToPoint: pt1];
106- [subLines lineToPoint: pt2];
107- }
108- }
109- }
110- beginTick = nextSigTick;
111- }
112- [lines setLineDash: sLineDash1 count: 2 phase: 0.0f];
113- [subLines setLineDash: sLineDash2 count: 2 phase: 0.0f];
114- [lines stroke];
115- [subLines stroke];
116- [lines release];
117- [subLines release];
118-
119- [[NSColor blackColor] set];
120- if (limitx < aRect.origin.x + aRect.size.width) {
121- /* Draw the "end of sequence" line */
122- float width = [NSBezierPath defaultLineWidth];
123- pt1.x = pt2.x = limitx;
124- [NSBezierPath strokeLineFromPoint: pt1 toPoint: pt2];
125- [NSBezierPath setDefaultLineWidth: 2.0f];
126- pt1.x = pt2.x += 3.0f;
127- [NSBezierPath strokeLineFromPoint: pt1 toPoint: pt2];
128- [NSBezierPath setDefaultLineWidth: width];
129- }
130-}
131-
13249 - (void)drawStavesInRect: (NSRect)aRect
13350 {
13451 int index, n, i;
@@ -141,8 +58,8 @@
14158 limitx = [dataSource sequenceDuration] * [dataSource pixelsPerTick];
14259 index = 0;
14360 /* Line start/end points are set to multiples of sDashWidth to avoid complication of calculating appropriate phase for setLineDash: */
144- startx = (float)(sDashWidth * floor(aRect.origin.x / sDashWidth));
145- endx = (float)(sDashWidth * ceil((aRect.origin.x + aRect.size.width) / sDashWidth + 1.0));
61+ startx = (float)(gDashWidth * floor(aRect.origin.x / gDashWidth));
62+ endx = (float)(gDashWidth * ceil((aRect.origin.x + aRect.size.width) / gDashWidth + 1.0));
14663 ys = [self yScale];
14764 for (i = 0; i < 2; i++) {
14865 if (i == 0) {
@@ -149,7 +66,7 @@
14966 if (limitx >= aRect.origin.x + aRect.size.width)
15067 continue;
15168 [[NSColor grayColor] set];
152- pt1.x = sDashWidth * (float)floor(limitx / sDashWidth);
69+ pt1.x = gDashWidth * (float)floor(limitx / gDashWidth);
15370 pt2.x = endx;
15471 } else {
15572 [staves removeAllPoints];
@@ -170,8 +87,8 @@
17087 [path moveToPoint: pt1];
17188 [path lineToPoint: pt2];
17289 }
173- [staves setLineDash: sLineDash1 count: 2 phase: 0.0f];
174- [subStaves setLineDash: sLineDash2 count: 2 phase: 0.0f];
90+ [staves setLineDash: gLineDash1 count: 2 phase: 0.0f];
91+ [subStaves setLineDash: gLineDash2 count: 2 phase: 0.0f];
17592 [staves stroke];
17693 [subStaves stroke];
17794 }
--- trunk/Classes/StripChartView.m (revision 198)
+++ trunk/Classes/StripChartView.m (revision 199)
@@ -301,6 +301,14 @@
301301 return aRange;
302302 }
303303
304+- (NSColor *)verticalLineColor: (BOOL)beforeEndOfSequence;
305+{
306+ if (beforeEndOfSequence)
307+ return [NSColor lightGrayColor];
308+ else
309+ return [NSColor grayColor];
310+}
311+
304312 - (void)drawContentsInRect: (NSRect)aRect
305313 {
306314 NSPoint pt;
@@ -308,6 +316,7 @@
308316 float y, grid;
309317 NSEraseRect(aRect);
310318 [self paintEditingRange: aRect startX: NULL endX: NULL];
319+ [self drawVerticalLinesInRect: aRect];
311320 if (eventKind == kMDEventNote || eventKind == kMDEventInternalNoteOff)
312321 [self drawVelocityInRect: aRect];
313322 else
Show on old repository browser