3535#define kItemBright CFSTR("com.billthefarmer.toolbar.bright")
3636#define kItemSingle CFSTR("com.billthefarmer.toolbar.single")
3737#define kItemTrigger CFSTR("com.billthefarmer.toolbar.trigger")
38- #define kItemSync CFSTR("com.billthefarmer.toolbar.sync")
38+ // #define kItemSync CFSTR("com.billthefarmer.toolbar.sync")
3939#define kItemTimebase CFSTR("com.billthefarmer.toolbar.timebase")
4040#define kItemStorage CFSTR("com.billthefarmer.toolbar.storage")
4141#define kItemClear CFSTR("com.billthefarmer.toolbar.clear")
8080 {kCommandBright = 'Brgt' ,
8181 kCommandSingle = 'Sngl' ,
8282 kCommandTrigger = 'Trig' ,
83- kCommandSync = 'Sync' ,
83+ // kCommandSync = 'Sync',
8484 kCommandTimebase = 'Time' ,
8585 kCommandStorage = 'Stor' ,
8686 kCommandClear = 'Clr ' ,
@@ -111,10 +111,21 @@ enum
111111 NEXT ,
112112 LAST };
113113
114+ // View ids
115+
116+ enum
117+ {kScopeID = 1 ,
118+ kYScaleID };
119+
114120// Scope id
115121
116122HIViewID ScopeID =
117- {'Scop' , 1 };
123+ {'Scop' , kScopeID };
124+
125+ // YScale id
126+
127+ HIViewID YScaleID =
128+ {'YSca' , kYScaleID };
118129
119130// Global data
120131
@@ -123,13 +134,14 @@ typedef struct
123134 HIViewRef view ;
124135 float * data ;
125136 float scale ;
137+ float yscale ;
126138 int index ;
127139 int start ;
128140 int length ;
129141 Boolean bright ;
130142 Boolean single ;
131143 Boolean trigger ;
132- Boolean polarity ;
144+ // Boolean polarity;
133145 Boolean storage ;
134146 Boolean clear ;
135147} Scope ;
@@ -149,6 +161,7 @@ XScale xscale;
149161typedef struct
150162{
151163 HIViewRef view ;
164+ float index ;
152165} Tool ;
153166
154167Tool yscale ;
@@ -169,8 +182,8 @@ Item items[] =
169182 CFSTR ("Single shot, click to enable" ), kCommandSingle },
170183 {kItemTrigger , CFSTR ("trigger" ), CFSTR ("Trigger" ),
171184 CFSTR ("Trigger, click to trigger trace" ), kCommandTrigger },
172- {kItemSync , CFSTR ("positive" ), CFSTR ("Sync" ),
173- CFSTR ("Sync, click to change sync polarity" ), kCommandSync },
185+ // {kItemSync, CFSTR("positive"), CFSTR("Sync"),
186+ // CFSTR("Sync, click to change sync polarity"), kCommandSync},
174187 {kItemTimebase , CFSTR ("timebasedrop" ), CFSTR ("Timebase" ),
175188 CFSTR ("Timebase, click to pop up menu" ), kCommandTimebase },
176189 {kItemStorage , CFSTR ("storage" ), CFSTR ("Storage" ),
@@ -425,6 +438,10 @@ int main(int argc, char *argv[])
425438
426439 CreateUserPaneControl (window , & bounds , 0 , & yscale .view );
427440
441+ // Set id
442+
443+ HIViewSetID (yscale .view , YScaleID );
444+
428445 // Set help tag
429446
430447 help .content [kHMMinimumContentIndex ].u .tagCFString =
@@ -908,19 +925,23 @@ OSStatus AudioEventHandler(EventHandlerCallRef next,
908925 if (scope .single && !scope .trigger )
909926 break ;
910927
928+ // Calculate sync level
929+
930+ float level = - yscale .index * scope .yscale ;
931+
911932 // Initialise sync
912933
913934 float dx = 0.0 ;
914935
915936 // Sync polarity
916937
917- if (scope . polarity )
938+ if (level < 0.0 )
918939 {
919940 for (int i = 0 ; i < audio .frames ; i ++ )
920941 {
921942 dx = data [i ] - last ;
922943
923- if (dx < 0.0 && last > 0.0 && data [i ] < 0.0 )
944+ if (dx < 0.0 && last > level && data [i ] < level )
924945 {
925946 index = i ;
926947 state ++ ;
@@ -937,7 +958,7 @@ OSStatus AudioEventHandler(EventHandlerCallRef next,
937958 {
938959 dx = data [i ] - last ;
939960
940- if (dx > 0.0 && last < 0.0 && data [i ] > 0.0 )
961+ if (dx > 0.0 && last < level && data [i ] > level )
941962 {
942963 index = i ;
943964 state ++ ;
@@ -1295,6 +1316,20 @@ OSStatus YScaleDrawEventHandler(EventHandlerCallRef next,
12951316
12961317 CGContextStrokePath (context );
12971318
1319+ if (yscale .index != 0 )
1320+ {
1321+ CGContextTranslateCTM (context , - width / 8 , yscale .index );
1322+
1323+ CGContextBeginPath (context );
1324+ CGContextMoveToPoint (context , -4 , -4 );
1325+ CGContextAddLineToPoint (context , -4 , 4 );
1326+ CGContextAddLineToPoint (context , 4 , 4 );
1327+ CGContextAddLineToPoint (context , 8 , 0 );
1328+ CGContextAddLineToPoint (context , 4 , -4 );
1329+ CGContextClosePath (context );
1330+ CGContextFillPath (context );
1331+ }
1332+
12981333 return noErr ;
12991334}
13001335
@@ -1442,7 +1477,7 @@ OSStatus ScopeDrawEventHandler(EventHandlerCallRef next,
14421477 if (max < 0.125 )
14431478 max = 0.125 ;
14441479
1445- float yscale = max / ((float )height / 2.0 );
1480+ scope . yscale = max / ((float )height / 2.0 );
14461481
14471482 max = 0.0 ;
14481483
@@ -1469,7 +1504,7 @@ OSStatus ScopeDrawEventHandler(EventHandlerCallRef next,
14691504 max = fabs (scope .data [i + xstart ]);
14701505
14711506 float x = (float )i * xscale ;
1472- float y = - scope .data [i + xstart ] / yscale ;
1507+ float y = - scope .data [i + xstart ] / scope . yscale ;
14731508
14741509 CGContextAddLineToPoint (bitmap , x , y );
14751510 }
@@ -1485,7 +1520,7 @@ OSStatus ScopeDrawEventHandler(EventHandlerCallRef next,
14851520 max = fabs (scope .data [i + xstart ]);
14861521
14871522 float x = (float )i * xscale ;
1488- float y = - scope .data [i + xstart ] / yscale ;
1523+ float y = - scope .data [i + xstart ] / scope . yscale ;
14891524
14901525 CGContextAddLineToPoint (bitmap , x , y );
14911526 }
@@ -1499,7 +1534,7 @@ OSStatus ScopeDrawEventHandler(EventHandlerCallRef next,
14991534 for (int i = 0 ; i <= xstop - xstart ; i ++ )
15001535 {
15011536 float x = (float )i * xscale ;
1502- float y = - scope .data [i + xstart ] / yscale ;
1537+ float y = - scope .data [i + xstart ] / scope . yscale ;
15031538
15041539 CGContextStrokeRect (bitmap , CGRectMake (x - 2 , y - 2 , 4 , 4 ));
15051540 }
@@ -1535,7 +1570,7 @@ OSStatus ScopeDrawEventHandler(EventHandlerCallRef next,
15351570 CGContextSetShouldAntialias (bitmap , true);
15361571
15371572 int i = round ((float )scope .index / xscale );
1538- float y = - scope .data [i + xstart ] / yscale ;
1573+ float y = - scope .data [i + xstart ] / scope . yscale ;
15391574
15401575 sprintf (s , "%0.2f" , scope .data [i + xstart ]);
15411576 CGContextShowTextAtPoint (bitmap , scope .index , y , s , strlen (s ));
@@ -1566,40 +1601,6 @@ OSStatus ScopeDrawEventHandler(EventHandlerCallRef next,
15661601 return noErr ;
15671602}
15681603
1569- // Pane draw event handler
1570-
1571- // OSStatus PaneDrawEventHandler(EventHandlerCallRef next,
1572- // EventRef event, void *data)
1573- // {
1574- // CGContextRef context;
1575- // HIViewRef view;
1576- // HIRect bounds;
1577-
1578- // // Get context
1579-
1580- // GetEventParameter(event, kEventParamCGContextRef,
1581- // typeCGContextRef, NULL,
1582- // sizeof(context), NULL,
1583- // &context);
1584- // // Get view
1585-
1586- // GetEventParameter(event, kEventParamDirectObject,
1587- // typeControlRef, NULL,
1588- // sizeof(view), NULL,
1589- // &view);
1590- // // Get bounds
1591-
1592- // HIViewGetBounds(view, &bounds);
1593- // CGContextSetGrayFillColor(context, 1, 0.9);
1594- // CGContextFillRect(context, bounds);
1595-
1596- // CGContextSetGrayStrokeColor(context, 0.8, 0.9);
1597- // CGContextSetLineWidth(context, 3);
1598- // CGContextStrokeRect(context, bounds);
1599-
1600- // return noErr;
1601- // }
1602-
16031604// Command event handler
16041605
16051606OSStatus CommandEventHandler (EventHandlerCallRef next , EventRef event ,
@@ -1679,19 +1680,19 @@ OSStatus CommandEventHandler(EventHandlerCallRef next, EventRef event,
16791680
16801681 // Sync polarity
16811682
1682- case kCommandSync :
1683- scope .polarity = !scope .polarity ;
1683+ // case kCommandSync:
1684+ // scope.polarity = !scope.polarity;
16841685
1685- // Get image
1686+ // // Get image
16861687
1687- image =
1688- GetToolbarImage (scope .polarity ?
1689- CFSTR ("negative" ):
1690- CFSTR ("positive" ));
1688+ // image =
1689+ // GetToolbarImage(scope.polarity?
1690+ // CFSTR("negative"):
1691+ // CFSTR("positive"));
16911692
1692- HIToolbarItemSetImage (toolbar .items [3 ], image );
1693- CGImageRelease (image );
1694- break ;
1693+ // HIToolbarItemSetImage(toolbar.items[3], image);
1694+ // CGImageRelease(image);
1695+ // break;
16951696
16961697 // Timebase
16971698
@@ -1747,7 +1748,9 @@ OSStatus CommandEventHandler(EventHandlerCallRef next, EventRef event,
17471748 scope .start = 0 ;
17481749 scope .index = 0 ;
17491750 xscale .start = 0 ;
1751+ yscale .index = 0 ;
17501752 HIViewSetNeedsDisplay (xscale .view , true);
1753+ HIViewSetNeedsDisplay (yscale .view , true);
17511754 break ;
17521755
17531756 // End
@@ -1767,9 +1770,13 @@ OSStatus CommandEventHandler(EventHandlerCallRef next, EventRef event,
17671770 scope .start = 0 ;
17681771 scope .bright = false;
17691772 scope .single = false;
1770- scope .polarity = false;
1773+ // scope.polarity = false;
17711774 scope .storage = false;
17721775
1776+ xscale .start = 0 ;
1777+ yscale .index = 0 ;
1778+ HIViewSetNeedsDisplay (xscale .view , true);
1779+ HIViewSetNeedsDisplay (yscale .view , true);
17731780
17741781 // Get image
17751782
@@ -1893,21 +1900,32 @@ OSStatus MouseEventHandler(EventHandlerCallRef next,
18931900 NULL , & window );
18941901 HIPoint location ;
18951902 HIViewRef view ;
1903+ HIRect bounds ;
18961904 HIViewID id ;
18971905
18981906 HIViewGetViewForMouseEvent (HIViewGetRoot (window ), event , & view );
18991907 HIViewGetID (view , & id );
19001908
1909+ GetEventParameter (event , kEventParamWindowMouseLocation ,
1910+ typeHIPoint , NULL , sizeof (location ),
1911+ NULL , & location );
1912+ HIViewConvertPoint (& location , NULL , view );
1913+ HIViewGetBounds (scope .view , & bounds );
1914+
19011915 switch (id .id )
19021916 {
1903- case 1 :
1904- GetEventParameter (event , kEventParamWindowMouseLocation ,
1905- typeHIPoint , NULL , sizeof (location ),
1906- NULL , & location );
1907- HIViewConvertPoint (& location , NULL , view );
1917+ case kScopeID :
19081918 scope .index = location .x ;
19091919 break ;
19101920
1921+ case kYScaleID :
1922+ yscale .index = location .y - (bounds .size .height / 2 );
1923+
1924+ // Update display
1925+
1926+ HIViewSetNeedsDisplay (yscale .view , true);
1927+ break ;
1928+
19111929 default :
19121930 return eventNotHandledErr ;
19131931 }
@@ -1954,6 +1972,32 @@ OSStatus KeyboardEventHandler(EventHandlerCallRef next,
19541972 scope .index = 0 ;
19551973 break ;
19561974
1975+ // Up
1976+
1977+ case kKeyboardUpKey :
1978+ yscale .index -- ;
1979+
1980+ if (yscale .index <= - bounds .size .height / 2 )
1981+ yscale .index = 0 ;
1982+
1983+ // Update display
1984+
1985+ HIViewSetNeedsDisplay (yscale .view , true);
1986+ break ;
1987+
1988+ // Down
1989+
1990+ case kKeyboardDownKey :
1991+ yscale .index ++ ;
1992+
1993+ if (yscale .index >= bounds .size .height / 2 )
1994+ yscale .index = 0 ;
1995+
1996+ // Update display
1997+
1998+ HIViewSetNeedsDisplay (yscale .view , true);
1999+ break ;
2000+
19572001 default :
19582002 return eventNotHandledErr ;
19592003 }
0 commit comments