Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ Various additions

Remove GARLIC build target
* Use Portmaster-compatible distro instead

Find closest instrument
* In PhraseView, select the closest instrument from the top
* Less often edit the wrong instrument hopefully

Fixes:
Fixed incorrect interpolation (#248)
Expand Down
25 changes: 23 additions & 2 deletions sources/Application/Views/PhraseView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,10 @@ void PhraseView::processNormalButtonMask(unsigned short mask) {
if (*c != 0xFF) {
viewData_->currentInstrument_ = *c;
} else {
viewData_->currentInstrument_ = lastInstr_;
int nearest = findClosestInstrumentFor(row_);
if (nearest >= 0) {
viewData_->currentInstrument_ = nearest;
} else viewData_->currentInstrument_= lastInstr_;
}
if (viewData_->currentInstrument_ != 0xFF) {
ViewType vt = VT_INSTRUMENT;
Expand Down Expand Up @@ -1113,6 +1116,21 @@ void PhraseView::processNormalButtonMask(unsigned short mask) {
}
};

/*
* For currently selected row, find nearest instrument from the top
*/
int PhraseView::findClosestInstrumentFor(int row) {
unsigned char *instr = phrase_->instr_ + (16 * viewData_->currentPhrase_);
if (instr[row] != 0xFF) return instr[row];
for (int d = 1; d < 16; ++d) {
int up = row - d;
int down = row + d;
if (up >= 0 && instr[up] != 0xFF) return instr[up];
if (down < 16 && instr[down] != 0xFF) return instr[down];
}
return -1; // none found in phrase
}

void PhraseView::processSelectionButtonMask(unsigned short mask) {

Player *player = Player::GetInstance();
Expand Down Expand Up @@ -1163,7 +1181,10 @@ void PhraseView::processSelectionButtonMask(unsigned short mask) {
if (*c != 0xFF) {
viewData_->currentInstrument_ = *c;
} else {
viewData_->currentInstrument_ = lastInstr_;
int nearest = findClosestInstrumentFor(row_);
if (nearest >= 0) {
viewData_->currentInstrument_ = nearest;
} else viewData_->currentInstrument_= lastInstr_;
}
ViewType vt = VT_INSTRUMENT;
ViewEvent ve(VET_SWITCH_VIEW, &vt);
Expand Down
2 changes: 1 addition & 1 deletion sources/Application/Views/PhraseView.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class PhraseView : public View {
UIBigHexVarField *cmdEditField_;
void printHelpLegend(FourCC command, GUITextProperties props);
void enterCommandSelector();

int findClosestInstrumentFor(int);
struct clipboard {
bool active_;
int col_;
Expand Down
Loading