| 1 |
/** |
| 2 |
* Furnace Tracker - multi-system chiptune tracker |
| 3 |
* Copyright (C) 2021-2025 tildearrow and contributors |
| 4 |
* |
| 5 |
* This program is free software; you can redistribute it and/or modify |
| 6 |
* it under the terms of the GNU General Public License as published by |
| 7 |
* the Free Software Foundation; either version 2 of the License, or |
| 8 |
* (at your option) any later version. |
| 9 |
* |
| 10 |
* This program is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
* GNU General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU General Public License along |
| 16 |
* with this program; if not, write to the Free Software Foundation, Inc., |
| 17 |
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 |
*/ |
| 19 |
|
| 20 |
#include "engine.h" |
| 21 |
#include "../ta-log.h" |
| 22 |
|
| 23 |
static DivPattern emptyPat; |
| 24 |
|
| 25 |
DivPattern::DivPattern() { |
| 26 |
clear(); |
| 27 |
} |
| 28 |
|
| 29 |
DivPattern* DivChannelData::getPattern(int index, bool create) { |
| 30 |
if (data[index]==NULL) { |
| 31 |
if (create) { |
| 32 |
data[index]=new DivPattern; |
| 33 |
} else { |
| 34 |
return &emptyPat; |
| 35 |
} |
| 36 |
} |
| 37 |
return data[index]; |
| 38 |
} |
| 39 |
|
| 40 |
std::vector<std::pair<int,int>> DivChannelData::optimize() { |
| 41 |
std::vector<std::pair<int,int>> ret; |
| 42 |
for (int i=0; i<DIV_MAX_PATTERNS; i++) { |
| 43 |
if (data[i]!=NULL) { |
| 44 |
// compare |
| 45 |
for (int j=0; j<DIV_MAX_PATTERNS; j++) { |
| 46 |
if (j==i) continue; |
| 47 |
if (data[j]==NULL) continue; |
| 48 |
if (memcmp(data[i]->data,data[j]->data,DIV_MAX_ROWS*DIV_MAX_COLS*sizeof(short))==0) { |
| 49 |
delete data[j]; |
| 50 |
data[j]=NULL; |
| 51 |
logV("%d == %d",i,j); |
| 52 |
ret.push_back(std::pair<int,int>(j,i)); |
| 53 |
} |
| 54 |
} |
| 55 |
} |
| 56 |
} |
| 57 |
return ret; |
| 58 |
} |
| 59 |
|
| 60 |
std::vector<std::pair<int,int>> DivChannelData::rearrange() { |
| 61 |
std::vector<std::pair<int,int>> ret; |
| 62 |
for (int i=0; i<DIV_MAX_PATTERNS; i++) { |
| 63 |
if (data[i]==NULL) { |
| 64 |
for (int j=i; j<DIV_MAX_PATTERNS; j++) { |
| 65 |
if (data[j]!=NULL) { |
| 66 |
data[i]=data[j]; |
| 67 |
data[j]=NULL; |
| 68 |
logV("%d -> %d",j,i); |
| 69 |
ret.push_back(std::pair<int,int>(j,i)); |
| 70 |
if (++i>=DIV_MAX_PATTERNS) break; |
| 71 |
} |
| 72 |
} |
| 73 |
} |
| 74 |
} |
| 75 |
return ret; |
| 76 |
} |
| 77 |
|
| 78 |
void DivChannelData::wipePatterns() { |
| 79 |
for (int i=0; i<DIV_MAX_PATTERNS; i++) { |
| 80 |
if (data[i]!=NULL) { |
| 81 |
delete data[i]; |
| 82 |
data[i]=NULL; |
| 83 |
} |
| 84 |
} |
| 85 |
} |
| 86 |
|
| 87 |
void DivPattern::copyOn(DivPattern* dest) { |
| 88 |
dest->name=name; |
| 89 |
memcpy(dest->data,data,sizeof(data)); |
| 90 |
} |
| 91 |
|
| 92 |
void DivPattern::clear() { |
| 93 |
memset(data,-1,DIV_MAX_ROWS*DIV_MAX_COLS*sizeof(short)); |
| 94 |
for (int i=0; i<DIV_MAX_ROWS; i++) { |
| 95 |
data[i][0]=0; |
| 96 |
data[i][1]=0; |
| 97 |
} |
| 98 |
} |
| 99 |
|
| 100 |
DivChannelData::DivChannelData(): |
| 101 |
effectCols(1) { |
| 102 |
memset(data,0,DIV_MAX_PATTERNS*sizeof(void*)); |
| 103 |
} |