Skip to content

Commit

Permalink
More intuitive cutting/pasting of partial fx cmds
Browse files Browse the repository at this point in the history
This allows to you clear the effect type while leaving the effect
parameter intact and also to paste only a parameter value into a
slot with no effect (in both case the effect is set to arpeggio, which
is rendered as 0 in the pattern editor).
  • Loading branch information
exelotl authored and Deltafire committed May 23, 2020
1 parent 65885c3 commit 268da18
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 42 deletions.
4 changes: 2 additions & 2 deletions src/tracker/PatternEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1257,7 +1257,7 @@ bool PatternEditor::writeEffect(pp_int32 effNum, pp_uint8 eff, pp_uint8 op,
patternTools.setPosition(pattern, cursor.channel, cursor.row);

// only write effect, when valid effect
// (0 is not a valid effect in my internal format, arpeggio is mapped to 0x30)
// (0 is not a valid effect in my internal format, arpeggio is mapped to 0x20)
if (eff)
patternTools.setEffect(effNum, eff, op);
else
Expand Down Expand Up @@ -1290,7 +1290,7 @@ void PatternEditor::writeDirectEffect(pp_int32 effNum, pp_uint8 eff, pp_uint8 op
patternTools.setPosition(pattern, track, row);

// only write effect, when valid effect
// (0 is not a valid effect in my internal format, arpeggio is mapped to 0x30)
// (0 is not a valid effect in my internal format, arpeggio is mapped to 0x20)
if (eff)
patternTools.setEffect(effNum, eff, op);
}
Expand Down
9 changes: 5 additions & 4 deletions src/tracker/PatternEditorClipBoard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,22 @@ void PatternEditor::ClipBoard::makeCopy(TXMPattern& pattern, const PatternEditor
return;

// only entire instrument column is allowed
if (selectionStart.inner >= 1 && selectionStart.inner<=2)
if (selectionStart.inner >= 1 && selectionStart.inner <= 2)
selectionStart.inner = 1;
if (selectionEnd.inner >= 1 && selectionEnd.inner<=2)
if (selectionEnd.inner >= 1 && selectionEnd.inner <= 2)
selectionEnd.inner = 2;
// only entire volume column can be selected
if (selectionStart.inner >= 3 && selectionStart.inner<=4)
if (selectionStart.inner >= 3 && selectionStart.inner <= 4)
selectionStart.inner = 3;
if (selectionEnd.inner >= 3 && selectionEnd.inner<=4)
if (selectionEnd.inner >= 3 && selectionEnd.inner <= 4)
selectionEnd.inner = 4;

selectionWidth = selectionEnd.channel - selectionStart.channel + 1;
selectionHeight = selectionEnd.row - selectionStart.row + 1;

mp_sint32 slotSize = pattern.effnum * 2 + 2;

// sanity check: only operate on internal XM pattern data
ASSERT(slotSize == 6);

mp_sint32 rowSizeDst = slotSize*selectionWidth;
Expand Down
113 changes: 77 additions & 36 deletions src/tracker/PatternEditorTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,14 @@ void PatternEditorTools::clearSelection(const PatternEditorTools::Position& ss,
return;

// only entire instrument column is allowed
if (selectionStartInner >= 1 && selectionStartInner<=2)
if (selectionStartInner >= 1 && selectionStartInner <= 2)
selectionStartInner = 1;
if (selectionEndInner >= 1 && selectionEndInner<=2)
if (selectionEndInner >= 1 && selectionEndInner <= 2)
selectionEndInner = 2;
// only entire volume column can be selected
if (selectionStartInner >= 3 && selectionStartInner<=4)
if (selectionStartInner >= 3 && selectionStartInner <= 4)
selectionStartInner = 3;
if (selectionEndInner >= 3 && selectionEndInner<=4)
if (selectionEndInner >= 3 && selectionEndInner <= 4)
selectionEndInner = 4;

pp_int32 selectionWidth = selectionEndChannel - selectionStartChannel + 1;
Expand Down Expand Up @@ -393,14 +393,14 @@ pp_int32 PatternEditorTools::insRemapSelection(const Position& ss, const Positio
return 0;

// only entire instrument column is allowed
if (selectionStartInner >= 1 && selectionStartInner<=2)
if (selectionStartInner >= 1 && selectionStartInner <= 2)
selectionStartInner = 1;
if (selectionEndInner >= 1 && selectionEndInner<=2)
if (selectionEndInner >= 1 && selectionEndInner <= 2)
selectionEndInner = 2;
// only entire volume column can be selected
if (selectionStartInner >= 3 && selectionStartInner<=4)
if (selectionStartInner >= 3 && selectionStartInner <= 4)
selectionStartInner = 3;
if (selectionEndInner >= 3 && selectionEndInner<=4)
if (selectionEndInner >= 3 && selectionEndInner <= 4)
selectionEndInner = 4;

pp_int32 selectionWidth = selectionEndChannel - selectionStartChannel + 1;
Expand Down Expand Up @@ -496,14 +496,14 @@ pp_int32 PatternEditorTools::noteTransposeSelection(const Position& ss, const Po
return 0;

// only entire instrument column is allowed
if (selectionStartInner >= 1 && selectionStartInner<=2)
if (selectionStartInner >= 1 && selectionStartInner <= 2)
selectionStartInner = 1;
if (selectionEndInner >= 1 && selectionEndInner<=2)
if (selectionEndInner >= 1 && selectionEndInner <= 2)
selectionEndInner = 2;
// only entire volume column can be selected
if (selectionStartInner >= 3 && selectionStartInner<=4)
if (selectionStartInner >= 3 && selectionStartInner <= 4)
selectionStartInner = 3;
if (selectionEndInner >= 3 && selectionEndInner<=4)
if (selectionEndInner >= 3 && selectionEndInner <= 4)
selectionEndInner = 4;

pp_int32 selectionWidth = selectionEndChannel - selectionStartChannel + 1;
Expand Down Expand Up @@ -624,14 +624,14 @@ pp_int32 PatternEditorTools::interpolateValuesInSelection(const PatternEditorToo
return 0;

// only entire instrument column is allowed
if (selectionStartInner >= 1 && selectionStartInner<=2)
if (selectionStartInner >= 1 && selectionStartInner <= 2)
selectionStartInner = 1;
if (selectionEndInner >= 1 && selectionEndInner<=2)
if (selectionEndInner >= 1 && selectionEndInner <= 2)
selectionEndInner = 2;
// only entire volume column can be selected
if (selectionStartInner >= 3 && selectionStartInner<=4)
if (selectionStartInner >= 3 && selectionStartInner <= 4)
selectionStartInner = 3;
if (selectionEndInner >= 3 && selectionEndInner<=4)
if (selectionEndInner >= 3 && selectionEndInner <= 4)
selectionEndInner = 4;
// only entire effect operand column
if (selectionStartInner >= 6 && selectionStartInner<=7)
Expand Down Expand Up @@ -1733,14 +1733,14 @@ bool PatternEditorTools::selectionContains(const TXMPattern* pattern, const Posi
return false;

// only entire instrument column is allowed
if (selectionStartInner >= 1 && selectionStartInner<=2)
if (selectionStartInner >= 1 && selectionStartInner <= 2)
selectionStartInner = 1;
if (selectionEndInner >= 1 && selectionEndInner<=2)
if (selectionEndInner >= 1 && selectionEndInner <= 2)
selectionEndInner = 2;
// only entire volume column can be selected
if (selectionStartInner >= 3 && selectionStartInner<=4)
if (selectionStartInner >= 3 && selectionStartInner <= 4)
selectionStartInner = 3;
if (selectionEndInner >= 3 && selectionEndInner<=4)
if (selectionEndInner >= 3 && selectionEndInner <= 4)
selectionEndInner = 4;

bool outside =
Expand Down Expand Up @@ -1774,152 +1774,191 @@ void PatternEditorTools::slotCopy(mp_ubyte* dst, mp_ubyte* src, pp_int32 from, p
{
pp_int32 i = 0;

// copy note
if (i >= from && i <= to)
{
*dst = *src;
}
i++;


// copy instrument first digit
if (i >= from && i <= to)
{
*(dst+1) &= 0x0F;
*(dst+1) |= *(src+1)&0xF0;
}
i++;

// copy instrument second digit
if (i >= from && i <= to)
{
*(dst+1) &= 0xF0;
*(dst+1) |= *(src+1)&0xF;
}
i++;


// copy volume
if (i >= from && i <= to)
{
*(dst+2) = *(src+2);
*(dst+3) = *(src+3);
}
i+=2;


// copy effect type
if (i >= from && i <= to)
{
*(dst+4) = *(src+4);
}
i++;


// copy effect parameter first digit
if (i >= from && i <= to)
{
*(dst+5) &= 0x0F;
*(dst+5) |= *(src+5)&0xF0;
}
i++;

// copy effect parameter second digit
if (i >= from && i <= to)
{
*(dst+5) &= 0xF0;
*(dst+5) |= *(src+5)&0xF;
}
i++;

// special cases for arpeggio effect:
if (*(dst+4) == 0x20 && *(dst+5) == 0)
*(dst+4) = 0;
else if (*(dst+4) == 0 && *(dst+5) != 0)
*(dst+4) = 0x20;
}

void PatternEditorTools::slotTransparentCopy(mp_ubyte* dst, mp_ubyte* src, pp_int32 from, pp_int32 to)
{
pp_int32 i = 0;

// copy note
if (i >= from && i <= to && *src)
{
*dst = *src;
}
i++;


// copy instrument first digit
if (i >= from && i <= to && (*(src+1)&0xF0))
{
*(dst+1) &= 0x0F;
*(dst+1) |= *(src+1)&0xF0;
}
i++;

// copy instrument second digit
if (i >= from && i <= to && (*(src+1)&0xF))
{
*(dst+1) &= 0xF0;
*(dst+1) |= *(src+1)&0xF;
}
i++;


// copy volume
if (i >= from && i <= to && (*(src+2) || *(src+3)))
{
*(dst+2) = *(src+2);
*(dst+3) = *(src+3);
}
i+=2;


// copy effect type
if (i >= from && i <= to && (*(src+4)))
{
*(dst+4) = *(src+4);
}
i++;


// copy effect parameter first digit
if (i >= from && i <= to && (*(src+5)&0xF0))
{
*(dst+5) &= 0x0F;
*(dst+5) |= *(src+5)&0xF0;
}
i++;

// copy effect parameter second digit
if (i >= from && i <= to && (*(src+5)&0xF))
{
*(dst+5) &= 0xF0;
*(dst+5) |= *(src+5)&0xF;
}
i++;

// special cases for arpeggio effect:
if (*(dst+4) == 0x20 && *(dst+5) == 0)
*(dst+4) = 0;
else if (*(dst+4) == 0 && *(dst+5) != 0)
*(dst+4) = 0x20;
}

void PatternEditorTools::slotClear(mp_ubyte* dst, pp_int32 from, pp_int32 to)
{
pp_int32 i = 0;

// clear note
if (i >= from && i <= to)
{
*dst = 0;
}
i++;


// clear instrument first digit
if (i >= from && i <= to)
{
*(dst+1) &= 0x0F;
}
i++;

// clear instrument second digit
if (i >= from && i <= to)
{
*(dst+1) &= 0xF0;
}
i++;

// clear volume
if (i >= from && i <= to)
{
*(dst+2) = 0;
*(dst+3) = 0;
}
i+=2;


// clear effect type
if (i >= from && i <= to)
{
*(dst+4) = 0;
}
i++;


// clear effect parameter first digit
if (i >= from && i <= to)
{
*(dst+5) &= 0x0F;
}
i++;

// clear effect parameter second digit
if (i >= from && i <= to)
{
*(dst+5) &= 0xF0;
}
i++;

// special cases for arpeggio effect:
if (*(dst+4) == 0x20 && *(dst+5) == 0)
*(dst+4) = 0;
else if (*(dst+4) == 0 && *(dst+5) != 0)
*(dst+4) = 0x20;
}

bool PatternEditorTools::moveSelection(const Position& ss, const Position& se, pp_int32 moveChannels, pp_int32 moveRows, bool clear)
Expand All @@ -1946,23 +1985,25 @@ bool PatternEditorTools::moveSelection(const Position& ss, const Position& se, p
if (!normalizeSelection(pattern, ss, se,
selectionStartChannel, selectionStartRow, selectionStartInner,
selectionEndChannel, selectionEndRow,selectionEndInner))
return 0;
return false;

// only entire instrument column is allowed
if (selectionStartInner >= 1 && selectionStartInner<=2)
if (selectionStartInner >= 1 && selectionStartInner <= 2)
selectionStartInner = 1;
if (selectionEndInner >= 1 && selectionEndInner<=2)
if (selectionEndInner >= 1 && selectionEndInner <= 2)
selectionEndInner = 2;
// only entire volume column can be selected
if (selectionStartInner >= 3 && selectionStartInner<=4)
if (selectionStartInner >= 3 && selectionStartInner <= 4)
selectionStartInner = 3;
if (selectionEndInner >= 3 && selectionEndInner<=4)
if (selectionEndInner >= 3 && selectionEndInner <= 4)
selectionEndInner = 4;

pp_int32 selectionWidth = selectionEndChannel - selectionStartChannel + 1;
pp_int32 selectionHeight = selectionEndRow - selectionStartRow + 1;

mp_sint32 slotSize = pattern->effnum * 2 + 2;

// sanity check: only operate on internal XM pattern data
ASSERT(slotSize == 6);

mp_sint32 rowSizeDst = slotSize*selectionWidth;
Expand Down

0 comments on commit 268da18

Please sign in to comment.