Add Octave Transpositions

This commit is contained in:
Matthias Neeracher 2008-04-12 21:33:43 +00:00
parent 45f98adcc5
commit 1355516e6a
7 changed files with 587 additions and 1057 deletions

File diff suppressed because it is too large Load Diff

View File

@ -65,6 +65,7 @@ enum {
- (void) setDivisions:(int)divisions inSections:(NSRange)sections; - (void) setDivisions:(int)divisions inSections:(NSRange)sections;
- (void) setGroove:(NSString *)groove inSections:(NSRange)sections; - (void) setGroove:(NSString *)groove inSections:(NSRange)sections;
- (void) playWithGroove:(NSString *)groove inSections:(NSRange)sections; - (void) playWithGroove:(NSString *)groove inSections:(NSRange)sections;
- (void) changeOctave:(BOOL)up inSections:(NSRange)sections;
- (void) setRepeatVolta:(int)repeatVolta; - (void) setRepeatVolta:(int)repeatVolta;

View File

@ -5,7 +5,7 @@
// //
// (MN) Matthias Neeracher // (MN) Matthias Neeracher
// //
// Copyright © 2005-2007 Matthias Neeracher // Copyright © 2005-2008 Matthias Neeracher
// //
#import "VLDocument.h" #import "VLDocument.h"
@ -271,6 +271,14 @@
[self didChangeSong]; [self didChangeSong];
} }
- (void) changeOctave:(BOOL)up inSections:(NSRange)sections
{
[self willChangeSong];
while (sections.length-- > 0)
song->ChangeOctave(sections.location++, up);
[self didChangeSong];
}
- (void) setChordSize:(float)size - (void) setChordSize:(float)size
{ {
[[[self undoManager] prepareWithInvocationTarget:self] setChordSize:chordSize]; [[[self undoManager] prepareWithInvocationTarget:self] setChordSize:chordSize];

View File

@ -964,6 +964,25 @@ void VLSong::ChangeKey(int section, int newKey, int newMode, bool transpose)
} }
} }
void VLSong::ChangeOctave(int section, bool transposeUp)
{
int semi = transposeUp ? 12 : -12;
for (size_t measure=0; measure<fMeasures.size(); ++measure) {
if (fMeasures[measure].fPropIdx != section)
continue;
VLNoteList::iterator i = fMeasures[measure].fMelody.begin();
VLNoteList::iterator e = fMeasures[measure].fMelody.end();
for (; i!=e; ++i) {
if (i->fPitch == VLNote::kNoPitch)
continue;
i->fPitch += semi;
}
}
}
// //
// We try a table based approach for converting the beginning and end of // We try a table based approach for converting the beginning and end of
// notes // notes

View File

@ -5,7 +5,7 @@
// //
// (MN) Matthias Neeracher // (MN) Matthias Neeracher
// //
// Copyright © 2005-2007 Matthias Neeracher // Copyright © 2005-2008 Matthias Neeracher
// //
#include <list> #include <list>
@ -346,6 +346,7 @@ public:
bool DoesTieWithNextRepeat(size_t measure) const; bool DoesTieWithNextRepeat(size_t measure) const;
bool IsNonEmpty() const; bool IsNonEmpty() const;
void ChangeKey(int section, int newKey, int newMode, bool transpose); void ChangeKey(int section, int newKey, int newMode, bool transpose);
void ChangeOctave(int section, bool transposeUp);
void ChangeDivisions(int section, int newDivisions); void ChangeDivisions(int section, int newDivisions);
void ChangeTime(int section, VLFraction newTime); void ChangeTime(int section, VLFraction newTime);

View File

@ -103,6 +103,7 @@ enum VLRecalc {
- (IBAction) endSheetWithButton:(id)sender; - (IBAction) endSheetWithButton:(id)sender;
- (IBAction) selectGroove:(id)sender; - (IBAction) selectGroove:(id)sender;
- (IBAction) editDisplayOptions:(id)sender; - (IBAction) editDisplayOptions:(id)sender;
- (IBAction) transposeOctave:(id)sender;
- (VLDocument *) document; - (VLDocument *) document;
- (VLSong *) song; - (VLSong *) song;

View File

@ -625,6 +625,12 @@ const char * sBreak[3] = {"", "\xE2\xA4\xBE", "\xE2\x8E\x98"};
[self setKey:nil returnCode:NSAlertOtherReturn contextInfo:sender]; [self setKey:nil returnCode:NSAlertOtherReturn contextInfo:sender];
} }
- (IBAction) transposeOctave:(id)sender
{
[[self document] changeOctave:[sender tag] > 0
inSections:[self sectionsInSelection]];
}
- (IBAction) setTime:(id)sender - (IBAction) setTime:(id)sender
{ {
int time = [[sender selectedItem] tag]; int time = [[sender selectedItem] tag];