Skip to content

Commit

Permalink
Implement Export song as text #22
Browse files Browse the repository at this point in the history
  • Loading branch information
mborik committed Dec 1, 2022
1 parent d6857ae commit 24fdf61
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/tracker/controls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,10 @@ Tracker.prototype.onCmdFileExport = function() {
this.file.exportFile();
};
//---------------------------------------------------------------------------------------
Tracker.prototype.onCmdFileExportText = function() {
this.file.exportTextDump();
};
//---------------------------------------------------------------------------------------
Tracker.prototype.onCmdFileCompile = function() {
this.compiler.show();
};
Expand Down
49 changes: 49 additions & 0 deletions src/tracker/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -657,4 +657,53 @@ export class STMFile {

this.system.save(data, `${fileName}.STMF`, constants.MIMETYPE);
}

exportTextDump() {
const player = this._parent.player;
const hexa = this._parent.settings.hexTracklines;
const fileName = this.getFixedFileName();
const empty = ' '.repeat(14);

const output = `SAA1099Tracker export of song "${
this._parent.songTitle
}" by "${
this._parent.songAuthor
}":\n\n${
player.positions.flatMap((pp, index) => {
const triDigitLine = (!hexa && pp.length > 100);
const lines = [
`Position ${index + 1}, speed: ${pp.speed}`,
` ${
pp.ch.map(
({ pitch }) => pitch ?
`${` [ ${pitch}`.substr(-12)} ]` :
empty
).join('')}`
];
for (let buf = '', line = 0; line < pp.length; line++) {
buf = (`00${line.toString(hexa ? 16 : 10)}`).substr(-3);
buf = ` ${(triDigitLine || (!hexa && line > 99)) ? buf[0] : ' '}${buf.slice(1)}`;
for (let channel = 0; channel < 6; channel++) {
const pt = player.patterns[pp.ch[channel].pattern];
const dat = pt.data[line].tracklist;
if (line >= pt.end) {
buf += empty;
}
else {
buf += ` ${dat.tone} ${dat.column.substr(0, 4)} ${dat.column.substr(4)}`;
}
}
lines.push(buf.replace(/\x7f/g, '.').toUpperCase());
}
lines.push('');
return lines;
}).join('\n')}`;

this.system.save(output, `${fileName}.txt`, 'text/plain');
}
}
1 change: 1 addition & 0 deletions src/tracker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export default class Tracker {
onCmdFileSave: (this: Tracker, as?: boolean) => void;
onCmdFileImport: (this: Tracker, type?: string) => void;
onCmdFileExport: (this: Tracker) => void;
onCmdFileExportText: (this: Tracker) => void;
onCmdFileCompile: (this: Tracker) => void;
onCmdPreferences: (this: Tracker) => void;
onCmdOrnClear: (this: Tracker) => void;
Expand Down
1 change: 1 addition & 0 deletions templates/menu.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<a class="dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-export"></span>&ensp;Export&nbsp;<span class="caret"></span>&ensp;</a>
<ul class="dropdown-menu" role="menu">
<li><a id="miFileExport">Export to native song format <i>(STMF)</i>&hellip;</a></li>
<li><a id="miFileExportText">Export tracklisting to plain text&hellip;</a></li>
<li class="divider"></li>
<li><a id="miFileCompile">Binary compilation&hellip;</a></li>
</ul>
Expand Down

0 comments on commit 24fdf61

Please sign in to comment.