From 601f15cb9895272ff41d02419b28c19584642f83 Mon Sep 17 00:00:00 2001 From: Matthias Neeracher Date: Mon, 16 Oct 2006 09:01:25 +0000 Subject: [PATCH] Introduce rest cursor, improve cursor tracking --- Resources/Music/restcursor.eps | 129 +++++++++++++++++++++++++++++ Sources/VLSheetView.h | 3 +- Sources/VLSheetView.mm | 71 ++++++++++++---- Sources/VLSheetViewNotes.h | 1 + Sources/VLSheetViewNotes.mm | 37 ++++++--- Vocalese.xcodeproj/project.pbxproj | 12 +-- 6 files changed, 218 insertions(+), 35 deletions(-) create mode 100644 Resources/Music/restcursor.eps diff --git a/Resources/Music/restcursor.eps b/Resources/Music/restcursor.eps new file mode 100644 index 0000000..8ddaa43 --- /dev/null +++ b/Resources/Music/restcursor.eps @@ -0,0 +1,129 @@ +%!PS-Adobe-3.0 EPSF-3.0 +%%BoundingBox: -22.2715 -318.973 241.368 395.851 +%%Pages: 0 +%%Title: Quarter-rest from feta +%%Creator: FontForge +%%Author: Matthias Neeracher +%%CreationDate: 14:59 27-12-2005 +%%EndComments +%%BeginPreview: 27 73 4 73 +%0000000012000000000000000000 +%00000001DF500000000000000000 +%00000002FFE30000000000000000 +%000000007FFE2000000000000000 +%000000000AFFC100000000000000 +%0000000001CFFB00000000000000 +%00000000002DFF90000000000000 +%000000000003FFF6000000000000 +%0000000000006FFF400000000000 +%0000000000000CFFE20000000000 +%00000000000005FFFD1000000000 +%00000000000000EFFFB000000000 +%00000000000000BFFFF900000000 +%000000000000009FFFFF70000000 +%000000000000008FFFFFF5000000 +%000000000000009FFFFFFE300000 +%00000000000000BFFFFFFFD10000 +%00000000000000EFFFFFFFFC0000 +%00000000000004FFFFFFFFFFA000 +%0000000000000BFFFFFFFFFFF700 +%0000000000004FFFFFFFFFFFFF30 +%000000000001DFFFFFFFFFFFFF80 +%00000000001CFFFFFFFFFFFFFF90 +%0000000002DFFFFFFFFFFFFFFF50 +%000000004EFFFFFFFFFFFFFFFC00 +%00000007FFFFFFFFFFFFFFFFE300 +%0000009FFFFFFFFFFFFFFFFE4000 +%00001BFFFFFFFFFFFFFFFFE40000 +%0001CFFFFFFFFFFFFFFFFD200000 +%000BFFFFFFFFFFFFFFFFB1000000 +%007FFFFFFFFFFFFFFFF800000000 +%00EFFFFFFFFFFFFFFF6000000000 +%03FFFFFFFFFFFFFFF40000000000 +%02FFFFFFFFFFFFFF600000000000 +%00BFFFFFFFFFFFFA000000000000 +%002EFFFFFFFFFFF2000000000000 +%0004FFFFFFFFFFA0000000000000 +%00006FFFFFFFFF50000000000000 +%000008FFFFFFFF20000000000000 +%000000BFFFFFFF00000000000000 +%0000001CFFFFFE00000000000000 +%00000002EFFFFF00000000000000 +%000000003FFFFF20000000000000 +%0000000005FFFF60000000000000 +%00000000008FFFB0000000000000 +%00000000000AFFF3000000000000 +%000000000000CFFC000000000000 +%0000000000001DFF900000000000 +%06BDCB85200003EFF60000000000 +%6FFFFFFFFD94004FFF4000000000 +%DFFFFFFFFFFFD827FFE300000000 +%FFFFFFFFFFFFFFFACFFD10000000 +%FFFFFFFFFFFFFFFFFFFFC0000000 +%FFFFFFFFFFFFFFFFFFFFFA000000 +%CFFFFFFFFFFFFFFFFFFFFF700000 +%9FFFFFFFFE843358BFFFFFF50000 +%5FFFFFFFE2000000017DFFFE3000 +%1FFFFFFF6000000000007EFFD100 +%0BFFFFFE00000000000002CFF700 +%05FFFFFB000000000000001BC200 +%00EFFFF800000000000000000000 +%008FFFF700000000000000000000 +%002FFFF700000000000000000000 +%0009FFF800000000000000000000 +%0002FFFA00000000000000000000 +%00008FFC00000000000000000000 +%00001EFE00000000000000000000 +%000006FF40000000000000000000 +%000000CF80000000000000000000 +%0000002FE0000000000000000000 +%00000007F6000000000000000000 +%00000000BE200000000000000000 +%000000001C600000000000000000 +%%EndPreview +%%EndProlog +%%Page "Quarter-rest" 1 +gsave newpath + 64.7188 395.023 moveto + 68.3018 396.294 71.0898 396.115 74.4766 394.398 curveto + 77.2422 392.996 82.7334 386.604 151.792 304.41 curveto + 230.796 210.144 lineto + 238.839 200.165 241.913 192.106 241.29 182.635 curveto + 240.211 166.262 228.06 149.227 200.938 126.066 curveto + 179.438 108.445 lineto + 151.488 85.8242 146.6 81.292 138.629 70.6172 curveto + 113.487 36.9473 108.746 -6.28418 126.21 -42.6133 curveto + 129.625 -49.7168 135.246 -58.2139 141.345 -65.4902 curveto + 186.797 -119.35 lineto + 209.146 -145.811 228.081 -168.709 228.918 -170.287 curveto + 230.902 -174.03 230.926 -177.288 228.997 -181.146 curveto + 226.542 -186.057 221.224 -189.526 216.152 -189.526 curveto + 213.085 -189.526 208.965 -187.211 205.36 -183.462 curveto + 195.787 -173.506 182.084 -164.249 166.759 -157.385 curveto + 130.815 -141.286 94.4062 -137.67 75.5234 -148.323 curveto + 71.7686 -150.441 65.3467 -156.891 62.9307 -160.971 curveto + 55.0303 -174.309 51.2588 -193.439 51.9766 -216.538 curveto + 53.0391 -250.717 63.5635 -286.143 78.2617 -305.017 curveto + 82.4688 -310.419 82.9355 -312.01 81.2695 -315.271 curveto + 79.5781 -318.578 75.4639 -319.932 72.2158 -318.248 curveto + 69.1846 -316.677 54.4639 -297.299 42.7764 -279.493 curveto + 10.3896 -230.154 -13.5127 -175.243 -20.7412 -133.572 curveto + -22.0645 -125.942 -22.2715 -123.264 -22.2715 -113.727 curveto + -22.2715 -101.213 -21.376 -96.1064 -17.9316 -88.9746 curveto + -12.7539 -78.2549 -4.2998 -73.3965 10.1982 -72.8066 curveto + 40.3965 -71.5791 90.6836 -85.0605 138.037 -107.08 curveto + 143.439 -109.592 lineto + 139.044 -104.465 lineto + 20.625 36.2188 lineto + 2.20703 58.1592 1.8916 58.5664 -0.588867 63.6719 curveto + -10.957 85.0088 -0.275391 106.545 36.1084 137.654 curveto + 57.6074 155.281 lineto + 85.6123 177.947 90.4434 182.433 98.5352 193.274 curveto + 126.678 230.981 128.839 281.014 103.933 318.191 curveto + 101.799 321.377 90.6338 335.198 79.1074 348.925 curveto + 67.5801 362.651 57.4766 375.134 56.6426 376.682 curveto + 55.6025 378.61 55.127 380.306 55.127 382.084 curveto + 55.127 387.236 59.5371 393.186 64.7188 395.023 curveto + closepath +1 0 0 setrgbcolor fill grestore +%%EOF diff --git a/Sources/VLSheetView.h b/Sources/VLSheetView.h index 29639d6..a551925 100644 --- a/Sources/VLSheetView.h +++ b/Sources/VLSheetView.h @@ -30,6 +30,7 @@ enum VLMusicElement { kMusicSixteenthFlag, kMusicThirtysecondthFlag, kMusicNoteCursor, + kMusicRestCursor, kMusicElements }; @@ -48,7 +49,7 @@ enum VLRecalc { @interface VLSheetView : NSView { VLRecalc fNeedsRecalc; - BOOL fIsRest; + char fClickMode; float fClefKeyW; float fMeasureW; int fGroups; diff --git a/Sources/VLSheetView.mm b/Sources/VLSheetView.mm index 73ed4d0..268dd29 100644 --- a/Sources/VLSheetView.mm +++ b/Sources/VLSheetView.mm @@ -37,7 +37,8 @@ static NSString * sElementNames[kMusicElements] = { @"eighth-flag", @"sixteenth-flag", @"thirtysecondth-flag", - @"notecursor" + @"notecursor", + @"restcursor" }; static float sSharpPos[] = { @@ -80,7 +81,7 @@ static float sFlatPos[] = { } } fNeedsRecalc = kFirstRecalc; - fIsRest = NO; + fClickMode = ' '; fDisplayScale = 1.0f; fCursorPitch = VLNote::kNoPitch; } @@ -176,6 +177,46 @@ static float sFlatPos[] = { [self scrollRectToVisible:r]; } +- (void) setTrackingRect +{ + NSRect r = [self bounds]; + NSPoint mouse = + [self convertPoint:[[self window] mouseLocationOutsideOfEventStream] + fromView: nil]; + BOOL within = [self mouse:mouse inRect:r]; + + fCursorTracking = [self addTrackingRect:r owner:self + userData:nil assumeInside:within]; + [[self window] setAcceptsMouseMovedEvents:within]; + if (within && ![[self document] valueForKey: @"editTarget"]) + [[self window] makeFirstResponder:self]; +} + +- (void) clearTrackingRect +{ + [self removeTrackingRect:fCursorTracking]; +} + +-(void)resetCursorRects +{ + [super resetCursorRects]; + [self clearTrackingRect]; + [self setTrackingRect]; +} + +-(void)viewWillMoveToWindow:(NSWindow *)win +{ + if (!win && [self window]) [self clearTrackingRect]; +} + +-(void)viewDidMoveToWindow +{ + if ([self window]) { + [self setTrackingRect]; + [[self window] makeFirstResponder:self]; + } +} + - (void) recalculateDimensions { NSScrollView * scroll = [self enclosingScrollView]; @@ -196,18 +237,6 @@ static float sFlatPos[] = { fNumSystems = (song->CountMeasures()+fMeasPerSystem-1)/fMeasPerSystem; sz.height = fNumSystems*kSystemH; - NSRect r = [scroll bounds]; - NSPoint mouse = - [scroll convertPoint:[[self window] mouseLocationOutsideOfEventStream] - fromView: nil]; - BOOL within = [scroll mouse:mouse inRect:r]; - - [self removeTrackingRect:fCursorTracking]; - fCursorTracking = [self addTrackingRect:r owner:self - userData:nil assumeInside:within]; - [[self window] setAcceptsMouseMovedEvents:within]; - [[self window] makeFirstResponder:self]; - NSSize frameSz = {sz.width * fDisplayScale, sz.height * fDisplayScale}; [self setFrameSize:frameSz]; @@ -505,14 +534,24 @@ static int sSemiToPitch[] = { VLSoundOut::Instance()->PlayNote(VLNote(1, fCursorPitch)); break; case 'r': - fIsRest = !fIsRest; + if (fClickMode == 'r') + fClickMode = ' '; + else + fClickMode = 'r'; + [self setNeedsDisplay:YES]; break; + case 'k': + if (fClickMode == 'k') + fClickMode = ' '; + else + fClickMode = 'k'; + break; + [self setNeedsDisplay:YES]; } } - (BOOL)control:(NSControl *)control textShouldEndEditing:(NSText *)fieldEditor { - VLDocument * doc = [self document]; VLEditable * editable = [[self document] valueForKey: @"editTarget"]; return [editable validValue:[fFieldEditor stringValue]]; } diff --git a/Sources/VLSheetViewNotes.h b/Sources/VLSheetViewNotes.h index 3aa40f9..ad09c44 100644 --- a/Sources/VLSheetViewNotes.h +++ b/Sources/VLSheetViewNotes.h @@ -12,6 +12,7 @@ - (void) drawNotesForSystem:(int)system; - (void) addNoteAtCursor; +- (void) startKeyboardCursor; @end diff --git a/Sources/VLSheetViewNotes.mm b/Sources/VLSheetViewNotes.mm index 2b72703..2181a66 100644 --- a/Sources/VLSheetViewNotes.mm +++ b/Sources/VLSheetViewNotes.mm @@ -18,16 +18,20 @@ - (void) addNoteAtCursor { if (fCursorMeasure > -1) { - VLNote newNote(1, !fIsRest ? fCursorPitch : VLNote::kNoPitch); + VLNote newNote(1, fClickMode==' ' ? fCursorPitch : VLNote::kNoPitch); - [self song]->AddNote(newNote, fCursorMeasure, fCursorAt); + if (fClickMode == 'k') + [self song]->DelNote(fCursorMeasure, fCursorAt); + else + [self song]->AddNote(newNote, fCursorMeasure, fCursorAt); [self setNeedsDisplay:YES]; [[self document] updateChangeCount:NSChangeDone]; - VLSoundOut::Instance()->PlayNote(newNote); - - fIsRest = NO; + if (fClickMode == ' ') + VLSoundOut::Instance()->PlayNote(newNote); + else + fClickMode = ' '; } } @@ -42,13 +46,22 @@ - (void) drawNoteCursor { - NSPoint note = - NSMakePoint([self noteXInMeasure:fCursorMeasure at:fCursorAt], - [self noteYInMeasure:fCursorMeasure withPitch:fCursorPitch]); - NSRect noteCursorRect = - NSMakeRect(note.x-kNoteX, note.y-kNoteY, 2.0f*kNoteX, 2.0f*kNoteY); - [[self musicElement:kMusicNoteCursor] - compositeToPoint:NSMakePoint(note.x-kNoteX, note.y-kNoteY) + int cursorX; + int cursorY; + VLMusicElement cursorElt; + + cursorX = [self noteXInMeasure:fCursorMeasure at:fCursorAt]-kNoteX; + if (fClickMode == ' ') { + cursorY = + [self noteYInMeasure:fCursorMeasure withPitch:fCursorPitch]-kNoteY; + cursorElt = kMusicNoteCursor; + } else { + cursorY = [self noteYInMeasure:fCursorMeasure withPitch:65]; + cursorElt = kMusicRestCursor; + } + + [[self musicElement:cursorElt] + compositeToPoint:NSMakePoint(cursorX, cursorY) operation: NSCompositeSourceOver]; } diff --git a/Vocalese.xcodeproj/project.pbxproj b/Vocalese.xcodeproj/project.pbxproj index 1784a27..49571b4 100644 --- a/Vocalese.xcodeproj/project.pbxproj +++ b/Vocalese.xcodeproj/project.pbxproj @@ -21,6 +21,7 @@ 952CBBB5095FD34F00434E43 /* AudioUnit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 952CBBB3095FD34F00434E43 /* AudioUnit.framework */; }; 952CBBB6095FD37300434E43 /* VLModel.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 955E58E4095658AB0045FDA5 /* VLModel.cpp */; }; 952DCD78096BBB11001C2316 /* VLSheetViewChords.mm in Sources */ = {isa = PBXBuildFile; fileRef = 952DCD77096BBB11001C2316 /* VLSheetViewChords.mm */; }; + 95498DBD0AE3812F006B5F81 /* VLSoundSched.mm in Sources */ = {isa = PBXBuildFile; fileRef = 95498DBC0AE3812F006B5F81 /* VLSoundSched.mm */; }; 955E58E5095658AB0045FDA5 /* VLModel.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 955E58E4095658AB0045FDA5 /* VLModel.cpp */; }; 955E59610957C1400045FDA5 /* TVLChord.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 955E59600957C1400045FDA5 /* TVLChord.cpp */; }; 955E59640957C15A0045FDA5 /* VLModel.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 955E58E4095658AB0045FDA5 /* VLModel.cpp */; }; @@ -33,7 +34,6 @@ 95B3E1A70960E58B000E9C0D /* Music in Resources */ = {isa = PBXBuildFile; fileRef = 95B3E1980960E58B000E9C0D /* Music */; }; 95B66658096BCA1F00FE18C9 /* VLSheetViewNotes.mm in Sources */ = {isa = PBXBuildFile; fileRef = 95B66657096BCA1F00FE18C9 /* VLSheetViewNotes.mm */; }; 95BDA15909540BF1009F9D65 /* VLSheetView.mm in Sources */ = {isa = PBXBuildFile; fileRef = 95BDA15809540BF1009F9D65 /* VLSheetView.mm */; }; - 95D44D1F0AD8BFEF00384FE5 /* VLSoundSched.mm in Sources */ = {isa = PBXBuildFile; fileRef = 95D44D1E0AD8BFEF00384FE5 /* VLSoundSched.mm */; }; 95F5F50F0ADCC433003980B2 /* VLXMLDocument.mm in Sources */ = {isa = PBXBuildFile; fileRef = 95F5F50E0ADCC433003980B2 /* VLXMLDocument.mm */; }; 95F5F5340ADCCFBB003980B2 /* DTD in Resources */ = {isa = PBXBuildFile; fileRef = 95F5F51E0ADCCFBB003980B2 /* DTD */; }; /* End PBXBuildFile section */ @@ -61,6 +61,8 @@ 952CBBB3095FD34F00434E43 /* AudioUnit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioUnit.framework; path = /System/Library/Frameworks/AudioUnit.framework; sourceTree = ""; }; 952DCD76096BBB11001C2316 /* VLSheetViewChords.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = VLSheetViewChords.h; path = Sources/VLSheetViewChords.h; sourceTree = ""; }; 952DCD77096BBB11001C2316 /* VLSheetViewChords.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = VLSheetViewChords.mm; path = Sources/VLSheetViewChords.mm; sourceTree = ""; }; + 95498DBB0AE3812F006B5F81 /* VLSoundSched.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = VLSoundSched.h; path = Sources/VLSoundSched.h; sourceTree = ""; }; + 95498DBC0AE3812F006B5F81 /* VLSoundSched.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; name = VLSoundSched.mm; path = Sources/VLSoundSched.mm; sourceTree = ""; }; 955E58E3095658AB0045FDA5 /* VLModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = VLModel.h; path = Sources/VLModel.h; sourceTree = ""; }; 955E58E4095658AB0045FDA5 /* VLModel.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = VLModel.cpp; path = Sources/VLModel.cpp; sourceTree = ""; }; 955E595C0957C0FC0045FDA5 /* TVLChord */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = TVLChord; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -75,8 +77,6 @@ 95B66657096BCA1F00FE18C9 /* VLSheetViewNotes.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = VLSheetViewNotes.mm; path = Sources/VLSheetViewNotes.mm; sourceTree = ""; }; 95BDA15709540BF1009F9D65 /* VLSheetView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = VLSheetView.h; path = Sources/VLSheetView.h; sourceTree = ""; }; 95BDA15809540BF1009F9D65 /* VLSheetView.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = VLSheetView.mm; path = Sources/VLSheetView.mm; sourceTree = ""; }; - 95D44D1D0AD8BFEF00384FE5 /* VLSoundSched.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = VLSoundSched.h; path = Sources/VLSoundSched.h; sourceTree = ""; }; - 95D44D1E0AD8BFEF00384FE5 /* VLSoundSched.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = VLSoundSched.mm; path = Sources/VLSoundSched.mm; sourceTree = ""; }; 95F5F50D0ADCC433003980B2 /* VLXMLDocument.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = VLXMLDocument.h; path = Sources/VLXMLDocument.h; sourceTree = ""; }; 95F5F50E0ADCC433003980B2 /* VLXMLDocument.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = VLXMLDocument.mm; path = Sources/VLXMLDocument.mm; sourceTree = ""; }; 95F5F51E0ADCCFBB003980B2 /* DTD */ = {isa = PBXFileReference; lastKnownFileType = folder; name = DTD; path = Resources/DTD; sourceTree = ""; }; @@ -166,6 +166,8 @@ 2A37F4ABFDCFA73011CA2CEA /* Classes */ = { isa = PBXGroup; children = ( + 95498DBB0AE3812F006B5F81 /* VLSoundSched.h */, + 95498DBC0AE3812F006B5F81 /* VLSoundSched.mm */, 952CBB9A095FD1CA00434E43 /* VLSoundOut.cpp */, 952CBB9B095FD1CA00434E43 /* VLSoundOut.h */, 2A37F4AEFDCFA73011CA2CEA /* VLDocument.h */, @@ -179,8 +181,6 @@ 952DCD77096BBB11001C2316 /* VLSheetViewChords.mm */, 95B66656096BCA1F00FE18C9 /* VLSheetViewNotes.h */, 95B66657096BCA1F00FE18C9 /* VLSheetViewNotes.mm */, - 95D44D1D0AD8BFEF00384FE5 /* VLSoundSched.h */, - 95D44D1E0AD8BFEF00384FE5 /* VLSoundSched.mm */, 95F5F50D0ADCC433003980B2 /* VLXMLDocument.h */, 95F5F50E0ADCC433003980B2 /* VLXMLDocument.mm */, ); @@ -351,8 +351,8 @@ 952CBB9D095FD1CA00434E43 /* VLSoundOut.cpp in Sources */, 952DCD78096BBB11001C2316 /* VLSheetViewChords.mm in Sources */, 95B66658096BCA1F00FE18C9 /* VLSheetViewNotes.mm in Sources */, - 95D44D1F0AD8BFEF00384FE5 /* VLSoundSched.mm in Sources */, 95F5F50F0ADCC433003980B2 /* VLXMLDocument.mm in Sources */, + 95498DBD0AE3812F006B5F81 /* VLSoundSched.mm in Sources */, ); runOnlyForDeploymentPostprocessing = 0; };