-
Notifications
You must be signed in to change notification settings - Fork 1
/
note.cpp
973 lines (831 loc) · 29.5 KB
/
note.cpp
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
/////////////////////////////////////////////////////////////////////////////
// Name: note.cpp
// Purpose: Stores and renders a note
// Author: Brad Larsen
// Modified by:
// Created: Dec 17, 2004
// RCS-ID:
// Copyright: (c) Brad Larsen
// License: wxWindows license
/////////////////////////////////////////////////////////////////////////////
#include "stdwx.h"
#include "note.h"
#include "powertabfileheader.h" // Needed for file version constants
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// Default Constants
const wxByte Note::DEFAULT_STRING_DATA = 0;
const wxWord Note::DEFAULT_SIMPLE_DATA = 0;
// String Constants
const wxByte Note::MIN_STRING = 0;
const wxByte Note::MAX_STRING = 6;
// Fret Number Constants
const wxByte Note::MIN_FRET_NUMBER = 0;
const wxByte Note::MAX_FRET_NUMBER = 29;
// Bend Constants
const wxByte Note::MAX_BEND_PITCH = 12;
const wxByte Note::MAX_BEND_DURATION = 9;
// Constructor/Destructor
/// Default Constructor
Note::Note() :
m_stringData(DEFAULT_STRING_DATA), m_simpleData(DEFAULT_SIMPLE_DATA)
{
//------Last Checked------//
// - Jan 17, 2005
ClearComplexSymbolArrayContents();
}
/// Primary Constructor
/// @param string Zero-based number of the string the note is played on
/// @param fretNumber Fret number used to play the note
Note::Note(wxUint32 string, wxByte fretNumber) :
m_stringData(DEFAULT_STRING_DATA), m_simpleData(DEFAULT_SIMPLE_DATA)
{
//------Last Checked------//
// - Jan 17, 2005
wxASSERT(IsValidString(string));
wxASSERT(IsValidFretNumber(fretNumber));
SetString(string);
SetFretNumber(fretNumber);
ClearComplexSymbolArrayContents();
}
/// Copy Constructor
Note::Note(const Note& note) :
m_stringData(DEFAULT_STRING_DATA), m_simpleData(DEFAULT_SIMPLE_DATA)
{
//------Last Checked------//
// - Dec 17, 2004
*this = note;
}
/// Destructor
Note::~Note()
{
//------Last Checked------//
// - Jan 17, 2005
}
/// Assignment Operator
const Note& Note::operator=(const Note& note)
{
//------Last Checked------//
// - Dec 17, 2004
// Check for assignment to self
if (this != ¬e)
{
m_stringData = note.m_stringData;
m_simpleData = note.m_simpleData;
ClearComplexSymbolArrayContents();
size_t count = note.GetComplexSymbolCount();
size_t i = 0;
for (; i < count; i++)
m_complexSymbolArray[i] = note.m_complexSymbolArray[i];
}
return (*this);
}
/// Equality Operator
bool Note::operator==(const Note& note) const
{
//------Last Checked------//
// - Jan 24, 2005
// Note: Complex symbols aren't necessarily in the same slot in the array
wxArrayInt thisComplexSymbolArray;
wxArrayInt thatComplexSymbolArray;
wxUint32 i = 0;
for (; i < MAX_NOTE_COMPLEX_SYMBOLS; i++)
{
thisComplexSymbolArray.Add(m_complexSymbolArray[i]);
thatComplexSymbolArray.Add(note.m_complexSymbolArray[i]);
}
thisComplexSymbolArray.Sort(wxCompareIntegers);
thatComplexSymbolArray.Sort(wxCompareIntegers);
i = 0;
for (; i < MAX_NOTE_COMPLEX_SYMBOLS; i++)
{
if (thisComplexSymbolArray[i] != thatComplexSymbolArray[i])
return (false);
}
return (
(m_stringData == note.m_stringData) &&
(m_simpleData == note.m_simpleData)
);
}
/// Inequality Operator
bool Note::operator!=(const Note& note) const
{
//------Last Checked------//
// - Dec 17, 2004
return (!operator==(note));
}
// Serialization Functions
/// Performs serialization for the class
/// @param stream Power Tab output stream to serialize to
/// @return True if the object was serialized, false if not
bool Note::DoSerialize(PowerTabOutputStream& stream)
{
//------Last Checked------//
// - Dec 17, 2004
stream << m_stringData << m_simpleData;
wxCHECK(stream.CheckState(), false);
wxByte symbolCount = (wxByte)GetComplexSymbolCount();
stream << symbolCount;
wxCHECK(stream.CheckState(), false);
size_t i = 0;
for (; i < symbolCount; i++)
{
stream << m_complexSymbolArray[i];
wxCHECK(stream.CheckState(), false);
}
return (stream.CheckState());
}
/// Performs deserialization for the class
/// @param stream Power Tab input stream to load from
/// @param version File version
/// @return True if the object was deserialized, false if not
bool Note::DoDeserialize(PowerTabInputStream& stream, wxWord version)
{
//------Last Checked------//
// - Dec 17, 2004
// Version 1.0/1.0.2 artificial harm updated
if (version == PowerTabFileHeader::FILEVERSION_1_0 ||
version == PowerTabFileHeader::FILEVERSION_1_0_2)
{
wxByte simple;
stream >> m_stringData >> simple;
wxCHECK(stream.CheckState(), false);
// Simple is now stored as wxWord
m_simpleData = simple;
ClearComplexSymbolArrayContents();
wxByte symbolCount;
stream >> symbolCount;
wxCHECK(stream.CheckState(), false);
size_t i = 0;
for (; i < symbolCount; i++)
{
stream >> m_complexSymbolArray[i];
wxCHECK(stream.CheckState(), false);
wxByte symbolType = HIBYTE(HIWORD(m_complexSymbolArray[i]));
if (symbolType == artificialHarmonic)
{
wxByte keyVariation = 1;
wxByte usesFlats = HIBYTE(LOWORD(m_complexSymbolArray[i]));
wxByte key = LOBYTE(LOWORD(m_complexSymbolArray[i]));
// CASE: Using flats
if (usesFlats == 1 && (key == 1 || key == 6))
keyVariation = 2;
// CASE: Using sharps
else if (usesFlats == 0 && (key == 3 || key == 8 || key == 10))
keyVariation = 0;
wxUint32 symbolData = artificialHarmonic;
symbolData = (symbolData << 8) + 1;
symbolData = (symbolData << 8) + keyVariation;
symbolData = (symbolData << 8) + key;
m_complexSymbolArray[i] = symbolData;
}
else if (symbolType == bend)
{
wxByte type = LOBYTE(HIWORD(m_complexSymbolArray[i]));
wxByte bentPitch = LOBYTE(LOWORD(m_complexSymbolArray[i]));
wxByte releasePitch = 0;
wxByte duration = HIBYTE(LOWORD(m_complexSymbolArray[i]));
wxByte drawStart = (wxByte)((type < 6) ? 0 : 1);
wxByte drawEnd = (wxByte)((type == 0 || type == 2 ||
type == 3 || type == 5 || type == 7) ? 1 : 0);
SetBend(type, bentPitch, releasePitch, duration, drawStart,
drawEnd);
}
}
}
// CASE: Latest version
else
{
stream >> m_stringData >> m_simpleData;
wxCHECK(stream.CheckState(), false);
wxByte symbolCount = 0;
stream >> symbolCount;
wxCHECK(stream.CheckState(), false);
size_t i = 0;
for (; i < symbolCount; i++)
{
stream >> m_complexSymbolArray[i];
wxCHECK(stream.CheckState(), false);
}
}
return (stream.CheckState());
}
// String Functions
/// Sets the string for the note
/// @param string String to set (zero-based)
/// @return True if the string was set, false if not
bool Note::SetString(wxUint32 string)
{
//------Last Checked------//
// - Jan 17, 2005
wxCHECK(IsValidString(string), false);
m_stringData &= ~stringMask;
m_stringData |= (wxByte)(string << 5);
return (true);
}
/// Gets the string for the note
/// @return The string for the note
wxUint32 Note::GetString() const
{
//------Last Checked------//
// - Jan 17, 2005
return (wxByte)((m_stringData & stringMask) >> 5);
}
// Fret Number Functions
/// Sets the fret number for the note
/// @param fretNumber Fret number to set
/// @return True if the fret number was set, false if not
bool Note::SetFretNumber(wxByte fretNumber)
{
//------Last Checked------//
// - Jan 17, 2005
wxCHECK(IsValidFretNumber(fretNumber), false);
m_stringData &= ~fretNumberMask;
m_stringData |= fretNumber;
return (true);
}
/// Gets the fret number on a given string
/// @return The fret number on the string
wxByte Note::GetFretNumber() const
{
//------Last Checked------//
// - Jan 17, 2005
return ((wxByte)(m_stringData & fretNumberMask));
}
// Simple Flag Functions
/// Sets a simple flag
/// @param flag Flag to set
/// @return True if the flag was set, false if not
bool Note::SetSimpleFlag(wxWord flag)
{
//------Last Checked------//
// - Jan 24, 2005
wxCHECK(IsValidSimpleFlag(flag), false);
// Mutually exclusive operations
if ((flag & hammerPullMask) != 0)
ClearSimpleFlag(hammerPullMask);
if ((flag & octaveMask) != 0)
ClearSimpleFlag(octaveMask);
m_simpleData |= flag;
return (true);
}
// Slide Into Functions
/// Sets (adds or updates) a slide into marker
/// @param type Slide into type to set (see slideIntoTypes enum for values)
/// @return True if the slide into marker was added or updated
bool Note::SetSlideInto(wxByte type)
{
//------Last Checked------//
// - Jan 21, 2005
wxCHECK(IsValidSlideInto(type), false);
if (type == slideIntoNone)
return (ClearSlideInto());
// Look for an existing slide first
wxUint32 index = FindComplexSymbol(slide);
// Slide exists; update its slide into data
if (index != (wxUint32)-1)
{
m_complexSymbolArray[index] &= ~slideIntoTypeMask;
m_complexSymbolArray[index] |= (wxUint32)(type << 16);
return (true);
}
// Construct the symbol data, then add it to the array
wxUint32 symbolData = MAKELONG(MAKEWORD(0, 0), MAKEWORD(type, slide));
return (AddComplexSymbol(symbolData));
}
/// Gets the slide into data (if any)
/// @param type Holds the slide into type return value
/// @return True if the data was returned, false if not
bool Note::GetSlideInto(wxByte& type) const
{
//------Last Checked------//
// - Jan 21, 2005
type = slideIntoNone;
// Get the index of the slide
wxUint32 index = FindComplexSymbol(slide);
if (index == (wxUint32)-1)
return (false);
// Get the individual pieces that make up the slide into
wxUint32 symbolData = m_complexSymbolArray[index];
type = LOBYTE(HIWORD(symbolData));
return (true);
}
/// Determines if the note has a slide into
/// @return True if the note has a slide into, false if not
bool Note::HasSlideInto() const
{
//------Last Checked------//
// - Jan 21, 2005
wxByte type = slideIntoNone;
if (!GetSlideInto(type))
return (false);
return (type != slideIntoNone);
}
/// Removes a slide into from the note
/// @return True if the slide into was removed, false if not
bool Note::ClearSlideInto()
{
//------Last Checked------//
// - Jan 21, 2005
// Get the index of the slide
wxUint32 index = FindComplexSymbol(slide);
if (index == (wxUint32)-1)
return (false);
m_complexSymbolArray[index] &= ~slideIntoTypeMask;
// Return if there is a slide out, otherwise remove the slide symbol
if (HasSlideOutOf())
return (true);
return (RemoveComplexSymbol(slide));
}
// Slide Out Of Functions
/// Sets (adds or updates) a slide out of marker
/// @param type Slide out of type to set (see slideOutOf enum for values)
/// @param steps Number of steps to slide, in half tones
/// @return True if the slide out of marker was added or updated
bool Note::SetSlideOutOf(wxByte type, wxInt8 steps)
{
//------Last Checked------//
// - Jan 21, 2005
wxCHECK(IsValidSlideOutOf(type), false);
if (type == slideOutOfNone)
return (ClearSlideOutOf());
// Look for an existing slide first
wxUint32 index = FindComplexSymbol(slide);
// Slide exists; update its slide out of data
if (index != (wxUint32)-1)
{
m_complexSymbolArray[index] &= ~(slideOutOfTypeMask |
slideOutOfStepsMask);
m_complexSymbolArray[index] |= (wxUint32)(type << 8);
m_complexSymbolArray[index] |= (wxUint32)(steps);
return (true);
}
// Construct the symbol data, then add it to the array
wxUint32 symbolData = MAKELONG(MAKEWORD(steps, type), MAKEWORD(0, slide));
return (AddComplexSymbol(symbolData));
}
/// Gets the slide out of data (if any)
/// @param type Holds the slide out of type return value
/// @param steps Holds the steps return value
/// @return True if the data was returned, false if not
bool Note::GetSlideOutOf(wxByte& type, wxInt8& steps) const
{
//------Last Checked------//
// - Jan 21, 2005
type = slideIntoNone;
steps = 0;
// Get the index of the slide
wxUint32 index = FindComplexSymbol(slide);
if (index == (wxUint32)-1)
return (false);
// Get the individual pieces that make up the slide out of
wxUint32 symbolData = m_complexSymbolArray[index];
type = HIBYTE(LOWORD(symbolData));
steps = LOBYTE(LOWORD(symbolData));
return (true);
}
/// Determines if the note has a slide out of
/// @return True if the note has a slide out of, false if not
bool Note::HasSlideOutOf() const
{
//------Last Checked------//
// - Jan 21, 2005
wxByte type = slideOutOfNone;
wxInt8 steps = 0;
if (!GetSlideOutOf(type, steps))
return (false);
return (type != slideOutOfNone);
}
/// Removes a slide out of from the note
/// @return True if the slide out of was removed, false if not
bool Note::ClearSlideOutOf()
{
//------Last Checked------//
// - Jan 21, 2005
// Get the index of the slide
wxUint32 index = FindComplexSymbol(slide);
if (index == (wxUint32)-1)
return (false);
m_complexSymbolArray[index] &= ~(slideOutOfTypeMask | slideOutOfStepsMask);
// Return if there is a slide in, otherwise remove the slide symbol
if (HasSlideInto())
return (true);
return (RemoveComplexSymbol(slide));
}
// Bend Functions
/// Determines if bend data is valid
/// @param type Type to validate
/// @param bentPitch Bent pitch to validate
/// @param releasePitch Release pitch to validate
/// @param duration Duration to validate
/// @param drawStartPoint Draw start point to validate
/// @param drawEndPoint Draw end point to validate
/// @return True if the bend data is valid, false if not
bool Note::IsValidBend(wxByte type, wxByte bentPitch, wxByte releasePitch,
wxByte duration, wxByte drawStartPoint, wxByte drawEndPoint)
{
//------Last Checked------//
// - Jan 24, 2005
// 1st validate the individual pieces
if (!IsValidBendType(type) || !IsValidBentPitch(bentPitch) ||
!IsValidReleasePitch(releasePitch) || !IsValidBendDuration(duration) ||
!IsValidDrawStartPoint(drawStartPoint) ||
!IsValidDrawEndPoint(drawEndPoint))
{
return (false);
}
bool returnValue = false;
if ((type == normalBend) || (type == bendAndHold))
{
// a) Bent pitch must be greater than zero
// b) Release pitch must be zero
// c) Duration may be any value
// d) Draw start must be low or mid and end must be higher
returnValue = ((bentPitch > 0) && (releasePitch == 0) &&
(drawStartPoint <= midPoint) && (drawEndPoint > drawStartPoint));
}
else if (type == bendAndRelease)
{
// a) Bent pitch must be greater than zero
// b) Release pitch must be less than bent pitch
// c) Duration must be zero
// d) Draw start must be low or mid and drawEndPoint must be low or mid
returnValue = ((bentPitch > 0) && (releasePitch < bentPitch) &&
(duration == 0) && (drawStartPoint <= midPoint) &&
(drawEndPoint <= midPoint));
}
else if ((type == preBend) || (type == preBendAndHold))
{
// a) Bent pitch must be greater than zero
// b) Release pitch must be zero
// c) Duration must be zero
// d) Draw start must be low, and end must be higher
returnValue = ((bentPitch > 0) && (releasePitch == 0) &&
(duration == 0) && (drawStartPoint == lowPoint) &&
(drawEndPoint > drawStartPoint));
}
else if (type == preBendAndRelease)
{
// a) Bent pitch must be greater than zero
// b) Release pitch must be less than bent pitch
// c) Duration must be zero
// d) Draw start and end must be low
returnValue = ((bentPitch > 0) && (releasePitch < bentPitch) &&
(duration == 0) && (drawStartPoint == lowPoint) &&
(drawEndPoint == lowPoint));
}
else if (type == gradualRelease)
{
// a) Bent pitch must be zero
// b) Release pitch must be standard to 2 3/4
// c) Duration must be > 0
// d) Draw start must be high or mid point, draw end must be lower
returnValue = ((bentPitch == 0) && (releasePitch <= 11) &&
(duration > 0) && (drawStartPoint >= midPoint) &&
(drawEndPoint < drawStartPoint));
}
else if (type == immediateRelease)
{
// a) Bent pitch must be zero
// b) Release pitch must be zero
// c) Duration must be zero
// d) Draw start must be high or mid, and match draw end
returnValue = ((bentPitch == 0) && (releasePitch == 0) &&
(duration == 0) && (drawStartPoint >= midPoint) &&
(drawStartPoint == drawEndPoint));
}
return (returnValue);
}
/// Sets (adds or updates) a bend
/// @param type Type of bend to set (see bendTypes enum for values)
/// @param bentPitch Amount of pitch to bend, in quarter steps
/// @param releasePitch Pitch to release to, in quarter steps
/// @param duration The duration of the bend (0 = default, occurs over 32nd
/// note, 1 = occurs over duration of note, 2 = occurs over duration of note +
/// next note, etc.)
/// @param drawStartPoint Vertical draw start point for the bend (see
/// bendDrawingPoints enum for values)
/// @param drawEndPoint Vertical draw end point for the bend (see
/// bendDrawingPoints enum for values)
/// @return True if the bend was added or updated
bool Note::SetBend(wxByte type, wxByte bentPitch, wxByte releasePitch,
wxByte duration, wxByte drawStartPoint, wxByte drawEndPoint)
{
//------Last Checked------//
// - Jan 23, 2005
wxCHECK(IsValidBend(type, bentPitch, releasePitch, duration, drawStartPoint,
drawEndPoint), false);
// Construct the symbol data, then add it to the array
wxUint32 symbolData = MAKELONG(0, MAKEWORD(0, bend));
symbolData |= (wxUint32)(type << 20);
symbolData |= (wxUint32)(drawStartPoint << 18);
symbolData |= (wxUint32)(drawEndPoint << 16);
symbolData |= (wxUint32)(duration << 8);
symbolData |= (wxUint32)(bentPitch << 4);
symbolData |= (wxUint32)(releasePitch);
return (AddComplexSymbol(symbolData));
}
/// Gets the bend data (if any)
/// @param type Holds the bend type return value
/// @param bentPitch Holds the bent pitch return value
/// @param releasePitch Holds the release pitch return value
/// @param duration Holds the duration return value
/// @param drawStartPoint Holds the draw start point return value
/// @param drawEndPoint Holds the draw end point return value
/// @return True if the data was returned, false if not
bool Note::GetBend(wxByte& type, wxByte& bentPitch, wxByte& releasePitch,
wxByte& duration, wxByte& drawStartPoint, wxByte& drawEndPoint) const
{
//------Last Checked------//
// - Jan 24, 2005
type = 0;
duration = 0;
bentPitch = 0;
releasePitch = 0;
drawStartPoint = 0;
drawEndPoint = 0;
// Get the index of the bend
wxUint32 index = FindComplexSymbol(bend);
if (index == (wxUint32)-1)
return (false);
// Get the individual pieces that make up the bend
wxUint32 symbolData = m_complexSymbolArray[index];
type = (wxByte)((symbolData & bendTypeMask) >> 20);
duration = HIBYTE(LOWORD(symbolData));
bentPitch = (wxByte)((symbolData & bentPitchMask) >> 4);
releasePitch = (wxByte)(symbolData & releasePitchMask);
drawStartPoint = (wxByte)((symbolData & drawStartMask) >> 18);
drawEndPoint = (wxByte)((symbolData & drawEndMask) >> 16);
return (true);
}
/// Determines if the note has a bend
/// @return True if the note has a bend, false if not
bool Note::HasBend() const
{
//------Last Checked------//
// - Jan 23, 2005
return (FindComplexSymbol(bend) != (wxUint32)-1);
}
/// Removes a bend from the note
/// @return True if the bend was removed, false if not
bool Note::ClearBend()
{
//------Last Checked------//
// - Jan 23, 2005
return (RemoveComplexSymbol(bend));
}
// Tapped Harmonic Functions
/// Sets (adds or updates) a tapped harmonic
/// @param tappedFretNumber Tapped fret number
/// @return True if the tapped harmonic was added or updated
bool Note::SetTappedHarmonic(wxByte tappedFretNumber)
{
//------Last Checked------//
// - Jan 19, 2005
wxCHECK(IsValidTappedHarmonic(tappedFretNumber), false);
// Construct the symbol data, then add it to the array
wxUint32 symbolData = MAKELONG(MAKEWORD(tappedFretNumber, 0),
MAKEWORD(0, tappedHarmonic));
return (AddComplexSymbol(symbolData));
}
/// Gets the tapped harmonic data (if any)
/// @param tappedFretNumber Holds the tapped fret number return value
/// @return True if the data was returned, false if not
bool Note::GetTappedHarmonic(wxByte& tappedFretNumber) const
{
//------Last Checked------//
// - Jan 19, 2005
tappedFretNumber = 0;
// Get the index of the tapped harmonic
wxUint32 index = FindComplexSymbol(tappedHarmonic);
if (index == (wxUint32)-1)
return (false);
// Get the individual pieces that make up the tapped harmonic
wxUint32 symbolData = m_complexSymbolArray[index];
tappedFretNumber = LOBYTE(LOWORD(symbolData));
return (true);
}
/// Determines if the note has a tapped harmonic
/// @return True if the note has a tapped harmonic, false if not
bool Note::HasTappedHarmonic() const
{
//------Last Checked------//
// - Jan 19, 2005
return (FindComplexSymbol(tappedHarmonic) != (wxUint32)-1);
}
/// Removes a tapped harmonic from the note
/// @return True if the tapped harmonic was removed, false if not
bool Note::ClearTappedHarmonic()
{
//------Last Checked------//
// - Jan 19, 2005
return (RemoveComplexSymbol(tappedHarmonic));
}
// Trill Functions
/// Sets (adds or updates) a trill
/// @param trilledFretNumber Trilled fret number
/// @return True if the trill was added or updated
bool Note::SetTrill(wxByte trilledFretNumber)
{
//------Last Checked------//
// - Jan 19, 2005
wxCHECK(IsValidTrill(trilledFretNumber), false);
// Construct the symbol data, then add it to the array
wxUint32 symbolData = MAKELONG(0, MAKEWORD(trilledFretNumber, trill));
return (AddComplexSymbol(symbolData));
}
/// Gets the trill data (if any)
/// @param trilledFretNumber Holds the trilled fret number return value
/// @return True if the data was returned, false if not
bool Note::GetTrill(wxByte& trilledFretNumber) const
{
//------Last Checked------//
// - Jan 19, 2005
trilledFretNumber = 0;
// Get the index of the trill
wxUint32 index = FindComplexSymbol(trill);
if (index == (wxUint32)-1)
return (false);
// Get the individual pieces that make up the trill
wxUint32 symbolData = m_complexSymbolArray[index];
trilledFretNumber = LOBYTE(HIWORD(symbolData));
return (true);
}
/// Determines if the note has a trill
/// @return True if the note has a trill, false if not
bool Note::HasTrill() const
{
//------Last Checked------//
// - Jan 19, 2005
return (FindComplexSymbol(trill) != (wxUint32)-1);
}
/// Removes a trill from the note
/// @return True if the trill was removed, false if not
bool Note::ClearTrill()
{
//------Last Checked------//
// - Jan 19, 2005
return (RemoveComplexSymbol(trill));
}
// Artificial Harmonic Functions
/// Sets (adds or updates) a artificial harmonic
/// @param key Key to set (see ChordName::keys enum for values)
/// @param keyVariation Key variation to set (see ChordName::keyVariation enum
/// for values)
/// @param octave Octave to set
/// @return True if the artificial harmonic was added or updated
bool Note::SetArtificialHarmonic(wxByte key, wxByte keyVariation, wxByte octave)
{
//------Last Checked------//
// - Jan 19, 2005
wxCHECK(IsValidArtificialHarmonic(key, keyVariation, octave), false);
// Construct the symbol data, then add it to the array
wxUint32 symbolData = MAKELONG(MAKEWORD(key, keyVariation),
MAKEWORD(octave, artificialHarmonic));
return (AddComplexSymbol(symbolData));
}
/// Gets the artificial harmonic data (if any)
/// @param key Holds the key return value
/// @param keyVariation Holds the key variation return value
/// @param octave Holds the octave return value
/// @return True if the data was returned, false if not
bool Note::GetArtificialHarmonic(wxByte& key, wxByte& keyVariation,
wxByte& octave) const
{
//------Last Checked------//
// - Jan 19, 2005
key = 0;
keyVariation = 0;
octave = 0;
// Get the index of the artificial harmonic
wxUint32 index = FindComplexSymbol(artificialHarmonic);
if (index == (wxUint32)-1)
return (false);
// Get the individual pieces that make up the artificial harmonic
wxUint32 symbolData = m_complexSymbolArray[index];
key = LOBYTE(LOWORD(symbolData));
keyVariation = HIBYTE(LOWORD(symbolData));
octave = LOBYTE(HIWORD(symbolData));
return (true);
}
/// Determines if the note has a artificial harmonic
/// @return True if the note has a artificial harmonic, false if not
bool Note::HasArtificialHarmonic() const
{
//------Last Checked------//
// - Jan 19, 2005
return (FindComplexSymbol(artificialHarmonic) != (wxUint32)-1);
}
/// Removes a artificial harmonic from the note
/// @return True if the artificial harmonic was removed, false if not
bool Note::ClearArtificialHarmonic()
{
//------Last Checked------//
// - Jan 19, 2005
return (RemoveComplexSymbol(artificialHarmonic));
}
// Complex Symbol Array Functions
/// Adds a complex symbol to the complex symbol array
/// @param symbolData Data that makes up the symbol
/// @return True if the symbol was added or updated, false if not
bool Note::AddComplexSymbol(wxUint32 symbolData)
{
//------Last Checked------//
// - Jan 19, 2005
// Get and validate the symbol type
wxByte type = HIBYTE(HIWORD(symbolData));
wxCHECK(IsValidComplexSymbolType(type), false);
bool returnValue = false;
// Get the index in the complex array where the symbol is stored
wxUint32 index = FindComplexSymbol(type);
// Found symbol in the array, update the symbol data
if (index != (wxUint32)-1)
{
m_complexSymbolArray[index] = symbolData;
returnValue = true;
}
// Symbol was not found in the array, find the first free array slot and
// insert there
else
{
wxUint32 i = 0;
for (; i < MAX_NOTE_COMPLEX_SYMBOLS; i++)
{
if (m_complexSymbolArray[i] == notUsed)
{
m_complexSymbolArray[i] = symbolData;
returnValue = true;
break;
}
}
}
return (returnValue);
}
/// Gets the number of complex symbols used by the note
/// @return The number of complex symbols used by the note
size_t Note::GetComplexSymbolCount() const
{
//------Last Checked------//
// - Jan 19, 2005
size_t returnValue = 0;
size_t i = 0;
for (; i < MAX_NOTE_COMPLEX_SYMBOLS; i++)
{
// Slot is not used; break out
if (m_complexSymbolArray[i] == notUsed)
break;
returnValue++;
}
return (returnValue);
}
/// Gets the index of a given complex symbol type in the complex symbol array
/// @param type Type of symbol to find
/// @return Index within the array where the symbol was found, or -1 if not
/// found
wxUint32 Note::FindComplexSymbol(wxByte type) const
{
//------Last Checked------//
// - Jan 19, 2005
wxUint32 returnValue = (wxUint32)-1;
wxUint32 i = 0;
for (; i < MAX_NOTE_COMPLEX_SYMBOLS; i++)
{
// Found the symbol type; break out
if (HIBYTE(HIWORD(m_complexSymbolArray[i])) == type)
{
returnValue = i;
break;
}
}
return (returnValue);
}
/// Removes a complex symbol from the complex symbol array
/// @param type Type of symbol to remove
/// @return True if the symbol was removed, false if not
bool Note::RemoveComplexSymbol(wxByte type)
{
//------Last Checked------//
// - Jan 19, 2005
bool returnValue = false;
wxUint32 i = 0;
for (; i < MAX_NOTE_COMPLEX_SYMBOLS; i++)
{
if (HIBYTE(HIWORD(m_complexSymbolArray[i])) == type)
{
m_complexSymbolArray[i] = notUsed;
returnValue = true;
break;
}
}
return (returnValue);
}
/// Clears the contents of the symbol array (sets all elements to "not used")
void Note::ClearComplexSymbolArrayContents()
{
//------Last Checked------//
// - Jan 19, 2005
wxUint32 i = 0;
for (; i < MAX_NOTE_COMPLEX_SYMBOLS; i++)
m_complexSymbolArray[i] = notUsed;
}