Skip to content

Commit

Permalink
Add Unicode support (UTF-8 only)
Browse files Browse the repository at this point in the history
  • Loading branch information
qwertymodo committed Mar 20, 2017
1 parent 64d4bdc commit d384c42
Show file tree
Hide file tree
Showing 19 changed files with 179 additions and 145 deletions.
15 changes: 6 additions & 9 deletions 3rdparty/sox/src/unicode_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

#include <windows.h>
#include <io.h>
#include <fcntl.h>

static UINT g_old_output_cp = ((UINT)-1);

Expand Down Expand Up @@ -85,7 +86,6 @@ void lsx_init_commandline_arguments(int *argc, char ***argv)
{
int i, nArgs;
LPWSTR *szArglist;
size_t sz;

szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs);

Expand All @@ -95,22 +95,18 @@ void lsx_init_commandline_arguments(int *argc, char ***argv)
exit(-1);
}

*argc = nArgs - 1;
*argv = (char**) malloc(sizeof(char*) * (*argc));

szArglist[1] = malloc(sizeof(wchar_t) * 4);

mbstowcs_s(&sz, szArglist[1], 4, "sox", 3);
*argv = (char**) malloc(sizeof(char*) * nArgs);
*argc = nArgs;

if(NULL == *argv)
{
fprintf(stderr, "\nFATAL: Malloc failed\n\n");
exit(-1);
}

for(i = 0; i < (*argc); i++)
for(i = 0; i < nArgs; i++)
{
(*argv)[i] = utf16_to_utf8(szArglist[i + 1]);
(*argv)[i] = utf16_to_utf8(szArglist[i]);
if(NULL == (*argv)[i])
{
fprintf(stderr, "\nFATAL: utf16_to_utf8 failed\n\n");
Expand Down Expand Up @@ -191,6 +187,7 @@ void lsx_init_console(void)
{
g_old_output_cp = GetConsoleOutputCP();
SetConsoleOutputCP(CP_UTF8);
_setmode(_fileno(stdout), _O_U16TEXT);
}

void lsx_uninit_console(void)
Expand Down
16 changes: 8 additions & 8 deletions msupcm++/AudioBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using namespace msu;

AudioBase::AudioBase() :
m_infile(""), m_outfile(""),
m_infile(L""), m_outfile(L""),
m_trim_start(0), m_trim_end(0), m_start_offset(0), m_loop(0),
m_fade_in(0), m_fade_out(0), m_cross_fade(0),
m_pad_start(0), m_pad_end(0),
Expand All @@ -17,13 +17,13 @@ AudioBase::AudioBase() :
}


AudioBase::AudioBase(const char *in): AudioBase()
AudioBase::AudioBase(std::wstring in): AudioBase()
{
m_infile = in;
}


AudioBase::AudioBase(const char *in, const char *out) : AudioBase()
AudioBase::AudioBase(std::wstring in, std::wstring out) : AudioBase()
{
m_infile = in;
m_outfile = out;
Expand Down Expand Up @@ -107,31 +107,31 @@ void AudioBase::render()
}
else if (config.verbosity() > 0)
{
std::cout << "Error opening input file " << m_infile << std::endl;
std::wcout << L"Error opening input file " << m_infile << std::endl;
}
}
}


const std::string& AudioBase::inFile() const
const std::wstring& AudioBase::inFile() const
{
return m_infile;
}


std::string& AudioBase::inFile()
std::wstring& AudioBase::inFile()
{
return m_infile;
}


const std::string& AudioBase::outFile() const
const std::wstring& AudioBase::outFile() const
{
return m_outfile;
}


std::string& AudioBase::outFile()
std::wstring& AudioBase::outFile()
{
return m_outfile;
}
Expand Down
16 changes: 8 additions & 8 deletions msupcm++/AudioBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ namespace msu
{
public:
AudioBase();
AudioBase(const char *in);
AudioBase(const char *in, const char *out);
AudioBase(std::wstring in);
AudioBase(std::wstring in, std::wstring out);
AudioBase(const AudioBase& a);
~AudioBase();

Expand All @@ -18,11 +18,11 @@ namespace msu

virtual void render();

const std::string& inFile() const;
std::string& inFile();
const std::wstring& inFile() const;
std::wstring& inFile();

const std::string& outFile() const;
std::string& outFile();
const std::wstring& outFile() const;
std::wstring& outFile();

int loop() const;
int& loop();
Expand Down Expand Up @@ -55,8 +55,8 @@ namespace msu
double& normalization();

protected:
std::string m_infile;
std::string m_outfile;
std::wstring m_infile;
std::wstring m_outfile;
int m_loop;
int m_trim_start;
int m_trim_end;
Expand Down
8 changes: 4 additions & 4 deletions msupcm++/AudioSubChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ AudioSubChannel::AudioSubChannel() :
}


AudioSubChannel::AudioSubChannel(const char *in) : AudioBase(in)
AudioSubChannel::AudioSubChannel(std::wstring in) : AudioBase(in)
{
m_sub_tracks = 0;
m_num_sub_tracks = 0;
}


AudioSubChannel::AudioSubChannel(const char *in, const char *out) : AudioBase(in, out)
AudioSubChannel::AudioSubChannel(std::wstring in, std::wstring out) : AudioBase(in, out)
{
m_sub_tracks = 0;
m_num_sub_tracks = 0;
Expand Down Expand Up @@ -133,7 +133,7 @@ void AudioSubChannel::render()
if (p->trimStart() > p->loop())
p->loop() = p->trimStart();

p->outFile() = m_outfile.substr(0, m_outfile.find_last_of(".")).append("_str").append(std::to_string(i)).append(".wav");
p->outFile() = m_outfile.substr(0, m_outfile.find_last_of(L".")).append(L"_str").append(std::to_wstring(i)).append(L".wav");
p->render();
if (!m_loop)
{
Expand Down Expand Up @@ -176,7 +176,7 @@ void AudioSubChannel::render()
for (auto i = 0; i < m_num_sub_tracks; ++i)
{
if (!config.keep_temps())
remove(dynamic_cast<AudioSubTrack*>(m_sub_tracks)[i].outFile().c_str());
_wremove(dynamic_cast<AudioSubTrack*>(m_sub_tracks)[i].outFile().c_str());
}
}
else
Expand Down
4 changes: 2 additions & 2 deletions msupcm++/AudioSubChannel.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ namespace msu
{
public:
AudioSubChannel();
AudioSubChannel(const char *in);
AudioSubChannel(const char *in, const char *out);
AudioSubChannel(std::wstring in);
AudioSubChannel(std::wstring in, std::wstring out);
AudioSubChannel(const AudioSubChannel& a);
~AudioSubChannel();

Expand Down
8 changes: 4 additions & 4 deletions msupcm++/AudioSubTrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ AudioSubTrack::AudioSubTrack() : AudioBase()
}


AudioSubTrack::AudioSubTrack(const char *in) : AudioBase(in)
AudioSubTrack::AudioSubTrack(std::wstring in) : AudioBase(in)
{
m_sub_channels = 0;
m_num_sub_channels = 0;
}


AudioSubTrack::AudioSubTrack(const char *in, const char *out) : AudioBase(in, out)
AudioSubTrack::AudioSubTrack(std::wstring in, std::wstring out) : AudioBase(in, out)
{
m_sub_channels = 0;
m_num_sub_channels = 0;
Expand Down Expand Up @@ -134,7 +134,7 @@ void AudioSubTrack::render()
if (m_loop && !p->loop())
p->loop() = m_loop + p->trimStart();

p->outFile() = m_outfile.substr(0, m_outfile.find_last_of(".")).append("_sch").append(std::to_string(i)).append(".wav");
p->outFile() = m_outfile.substr(0, m_outfile.find_last_of(L".")).append(L"_sch").append(std::to_wstring(i)).append(L".wav");
p->render();
if (!m_loop)
{
Expand Down Expand Up @@ -174,7 +174,7 @@ void AudioSubTrack::render()
{
for (auto i = 0; i < m_num_sub_channels; ++i)
{
remove(dynamic_cast<AudioSubChannel*>(m_sub_channels)[i].outFile().c_str());
_wremove(dynamic_cast<AudioSubChannel*>(m_sub_channels)[i].outFile().c_str());
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions msupcm++/AudioSubTrack.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ namespace msu
{
public:
AudioSubTrack();
AudioSubTrack(const char *in);
AudioSubTrack(const char *in, const char *out);
AudioSubTrack(std::wstring in);
AudioSubTrack(std::wstring in, std::wstring out);
AudioSubTrack(const AudioSubTrack& a);
~AudioSubTrack();

Expand Down
14 changes: 7 additions & 7 deletions msupcm++/AudioTrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ AudioTrack::AudioTrack(): AudioBase()
}


AudioTrack::AudioTrack(const char *in): AudioBase(in)
AudioTrack::AudioTrack(std::wstring in): AudioBase(in)
{
m_track_number = 0;
m_title.clear();
}


AudioTrack::AudioTrack(const char *in, const char *out): AudioBase(in, out)
AudioTrack::AudioTrack(std::wstring in, std::wstring out): AudioBase(in, out)
{
m_track_number = 0;
m_title.clear();
Expand Down Expand Up @@ -106,12 +106,12 @@ void AudioTrack::render()
{
if (config.verbosity() > 0 && (!inFile().empty() || m_num_sub_channels > 0 || m_num_sub_tracks > 0))
{
std::cout << "Track " << m_track_number;
std::wcout << L"Track " << m_track_number;

if (!m_title.empty())
std::cout << ": " << m_title;
std::wcout << L": " << m_title;

std::cout << std::endl;
std::wcout << std::endl;
}

if (config.dither())
Expand Down Expand Up @@ -145,13 +145,13 @@ int& AudioTrack::trackNumber()
}


const std::string& AudioTrack::title() const
const std::wstring& AudioTrack::title() const
{
return m_title;
}


std::string& AudioTrack::title()
std::wstring& AudioTrack::title()
{
return m_title;
}
10 changes: 5 additions & 5 deletions msupcm++/AudioTrack.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ namespace msu
{
public:
AudioTrack();
AudioTrack(const char *in);
AudioTrack(const char *in, const char *out);
AudioTrack(std::wstring in);
AudioTrack(std::wstring in, std::wstring out);
AudioTrack(const AudioTrack& a);
~AudioTrack();

Expand All @@ -33,11 +33,11 @@ namespace msu
int trackNumber() const;
int& trackNumber();

const std::string& title() const;
std::string& title();
const std::wstring& title() const;
std::wstring& title();

protected:
int m_track_number;
std::string m_title;
std::wstring m_title;
};
}
12 changes: 6 additions & 6 deletions msupcm++/AudioTrackList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ void AudioTrackList::render()
{
if (config.verbosity() > 0)
{
std::cout << "MSU-1 Audio Conversion Tool" << std::endl;
std::wcout << L"MSU-1 Audio Conversion Tool" << std::endl;

if (!config.game().empty())
std::cout << "Game: " << config.game() << std::endl;
std::wcout << L"Game: " << config.game() << std::endl;

if (!config.pack().empty())
std::cout << "Pack: " << config.pack() << std::endl;
std::wcout << L"Pack: " << config.pack() << std::endl;

if (!config.artist().empty())
std::cout << "Artist: " << config.artist() << std::endl;
std::wcout << L"Artist: " << config.artist() << std::endl;

if (!config.url().empty())
std::cout << config.url() << std::endl;
std::wcout << config.url() << std::endl;

std::cout << std::endl;
std::wcout << std::endl;
}

for each (AudioTrack track in m_tracks)
Expand Down
4 changes: 2 additions & 2 deletions msupcm++/AudioTrackListBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

using namespace msu;

AudioTrackListBuilder::AudioTrackListBuilder(std::string config)
AudioTrackListBuilder::AudioTrackListBuilder(std::wstring config)
{
std::ifstream ifs(config);
if (ifs.is_open())
Expand All @@ -19,7 +19,7 @@ AudioTrackListBuilder::AudioTrackListBuilder(std::string config)
}
catch (const std::exception& e)
{
std::cout << e.what() << std::endl;
std::wcout << e.what() << std::endl;
exit(1);
}

Expand Down
2 changes: 1 addition & 1 deletion msupcm++/AudioTrackListBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace msu
class AudioTrackListBuilder
{
public:
AudioTrackListBuilder(std::string config = "tracks.json");
AudioTrackListBuilder(std::wstring config = L"tracks.json");

const AudioTrackList& get() const;
AudioTrackList& get();
Expand Down
Loading

0 comments on commit d384c42

Please sign in to comment.