Skip to content

Commit

Permalink
implement global tuning from 0.5.0 beta
Browse files Browse the repository at this point in the history
  • Loading branch information
HertzDevil committed Jul 2, 2016
1 parent 81442c1 commit 3217f34
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 12 deletions.
36 changes: 31 additions & 5 deletions Source/FamiTrackerDoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,8 @@ void CFamiTrackerDoc::DeleteContents()
m_bLinearPitch = DEFAULT_LINEAR_PITCH;
m_iChannelsAvailable = CHANNELS_DEFAULT;
m_iSpeedSplitPoint = DEFAULT_SPEED_SPLIT_POINT;
m_iDetuneSemitone = 0; // // // 050B
m_iDetuneCent = 0; // // // 050B

m_vHighlight = CPatternData::DEFAULT_HIGHLIGHT; // // //

Expand Down Expand Up @@ -683,7 +685,7 @@ bool CFamiTrackerDoc::WriteBlocks(CDocumentFile *pDocFile) const
6, 1, 3, 6, 6, 3, 4, 1, 1,
#endif
6, 1, 1, // expansion
1, 1, 1, 1 // 0cc-ft
2, 1, 1, 1 // 0cc-ft
};

static bool (CFamiTrackerDoc::*FTM_WRITE_FUNC[])(CDocumentFile*, const int) const = { // // //
Expand Down Expand Up @@ -1673,8 +1675,8 @@ void CFamiTrackerDoc::ReadBlock_Parameters(CDocumentFile *pDocFile, const int Ve
AssertRange<MODULE_ERROR_STRICT>(m_iExpansionChip, 0, 0x3F, "Expansion chip flag");

if (Version >= 8) { // // // 050B
char Semitones = pDocFile->GetBlockChar();
char Cents = pDocFile->GetBlockChar();
m_iDetuneSemitone = pDocFile->GetBlockChar();
m_iDetuneCent = pDocFile->GetBlockChar();
}

SetupChannels(m_iExpansionChip);
Expand Down Expand Up @@ -2471,13 +2473,21 @@ bool CFamiTrackerDoc::WriteBlock_Bookmarks(CDocumentFile *pDocFile, const int Ve
void CFamiTrackerDoc::ReadBlock_ParamsExtra(CDocumentFile *pDocFile, const int Version)
{
m_bLinearPitch = pDocFile->GetBlockInt() != 0;
if (Version >= 2) {
m_iDetuneSemitone = AssertRange(pDocFile->GetBlockChar(), -12, 12, "Global semitone tuning");
m_iDetuneCent = AssertRange(pDocFile->GetBlockChar(), -100, 100, "Global cent tuning");
}
}

bool CFamiTrackerDoc::WriteBlock_ParamsExtra(CDocumentFile *pDocFile, const int Version) const
{
if (!m_bLinearPitch) return true;
if (!m_bLinearPitch && !m_iDetuneSemitone && !m_iDetuneCent) return true;
pDocFile->CreateBlock(FILE_BLOCK_PARAMS_EXTRA, Version);
pDocFile->WriteBlockInt(true);
pDocFile->WriteBlockInt(m_bLinearPitch);
if (Version >= 2) {
pDocFile->WriteBlockChar(m_iDetuneSemitone);
pDocFile->WriteBlockChar(m_iDetuneCent);
}
return pDocFile->FlushBlock();
}

Expand Down Expand Up @@ -4891,6 +4901,22 @@ void CFamiTrackerDoc::ResetDetuneTables() // // //
m_iDetuneTable[i][j] = 0;
}

void CFamiTrackerDoc::SetTuning(int Semitone, int Cent) // // // 050B
{
m_iDetuneSemitone = Semitone;
m_iDetuneCent = Cent;
}

int CFamiTrackerDoc::GetTuningSemitone() const // // // 050B
{
return m_iDetuneSemitone;
}

int CFamiTrackerDoc::GetTuningCent() const // // // 050B
{
return m_iDetuneCent;
}

CGroove* CFamiTrackerDoc::GetGroove(int Index) const // // //
{
return m_pGrooveTable[Index];
Expand Down
4 changes: 4 additions & 0 deletions Source/FamiTrackerDoc.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,9 @@ class CFamiTrackerDoc : public CDocument, public CFTMComponentInterface
void SetDetuneOffset(int Chip, int Note, int Detune); // // //
int GetDetuneOffset(int Chip, int Note) const;
void ResetDetuneTables();
void SetTuning(int Semitone, int Cent); // // // 050B
int GetTuningSemitone() const; // // // 050B
int GetTuningCent() const; // // // 050B

CGroove *GetGroove(int Index) const; // // //
void SetGroove(int Index, const CGroove* Groove);
Expand Down Expand Up @@ -521,6 +524,7 @@ class CFamiTrackerDoc : public CDocument, public CFTMComponentInterface
unsigned int m_iEngineSpeed; // Refresh rate
unsigned int m_iSpeedSplitPoint; // Speed/tempo split-point
int m_iDetuneTable[6][96]; // // // Detune tables
int m_iDetuneSemitone, m_iDetuneCent; // // // 050B tuning

// NSF info
char m_strName[32]; // Song name
Expand Down
1 change: 1 addition & 0 deletions Source/FamiTrackerView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1362,6 +1362,7 @@ void CFamiTrackerView::OnInitialUpdate()
// Setup speed/tempo (TODO remove?)
theApp.GetSoundGenerator()->ResetState();
theApp.GetSoundGenerator()->ResetTempo();
theApp.GetSoundGenerator()->DocumentPropertiesChanged(pDoc); // // //

// Default
SetInstrument(0);
Expand Down
2 changes: 1 addition & 1 deletion Source/SoundGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ void CSoundGen::DocumentPropertiesChanged(CFamiTrackerDoc *pDocument)
SetupVibratoTable(pDocument->GetVibratoStyle()); // // //

machine_t Machine = pDocument->GetMachine();
const int A440_NOTE = 45;
const double A440_NOTE = 45. - pDocument->GetTuningSemitone() - pDocument->GetTuningCent() / 100.;
double clock_ntsc = CAPU::BASE_FREQ_NTSC / 16.0;
double clock_pal = CAPU::BASE_FREQ_PAL / 16.0;

Expand Down
15 changes: 9 additions & 6 deletions Source/TextExporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -769,11 +769,13 @@ const CString& CTextExport::ImportFile(LPCTSTR FileName, CFamiTrackerDoc *pDoc)
CHECK(t.ReadEOL(&sResult));
break;
case CT_TUNING: // // // 050B
{
CHECK(t.ReadInt(i,-12,12,&sResult));

CHECK(t.ReadInt(i,-100,100,&sResult));

int cent;
CHECK(t.ReadInt(cent,-100,100,&sResult));
pDoc->SetTuning(i, cent);
CHECK(t.ReadEOL(&sResult));
}
break;
case CT_N163CHANNELS:
CHECK(t.ReadInt(i,1,8,&sResult));
Expand Down Expand Up @@ -1275,17 +1277,18 @@ const CString& CTextExport::ExportFile(LPCTSTR FileName, CFamiTrackerDoc *pDoc)
"%-15s %d\n"
"%-15s %d\n"
// "%-15s %d %d\n" // // // 050B
// "%-15s %d %d\n"
"\n"),
),
CT[CT_MACHINE], pDoc->GetMachine(),
CT[CT_FRAMERATE], pDoc->GetEngineSpeed(),
CT[CT_EXPANSION], pDoc->GetExpansionChip(),
CT[CT_VIBRATO], pDoc->GetVibratoStyle(),
CT[CT_SPLIT], pDoc->GetSpeedSplitPoint()
// ,CT[CT_PLAYBACKRATE], pDoc->, pDoc->
// ,CT[CT_TUNING], pDoc->, pDoc->
);
if (pDoc->GetTuningSemitone() || pDoc->GetTuningCent()) // // // 050B
s.AppendFormat(_T("%-15s %d %d\n"), CT[CT_TUNING], pDoc->GetTuningSemitone(), pDoc->GetTuningCent());
f.WriteString(s);
f.WriteString(_T("\n"));

int N163count = -1; // // //
if (pDoc->ExpansionEnabled(SNDCHIP_N163))
Expand Down

0 comments on commit 3217f34

Please sign in to comment.