From: <pst...@us...> - 2008-05-27 14:01:34
|
Revision: 579 http://jazzplusplus.svn.sourceforge.net/jazzplusplus/?rev=579&view=rev Author: pstieber Date: 2008-05-27 07:01:15 -0700 (Tue, 27 May 2008) Log Message: ----------- 1. Changed the input and output device indexes from long to int for the Windows settings dialog. 2. Changed Installed member function to IsInstalled for all of the players and changed then corresponding data member from installed to mInstalled. 3. Added code for to use the portmidi device selection dialog in the project. 4. Made cosmetic changes in the portmidi player class. 5. Changed the configuration code to use strings instead of char* in several places. 6. Removed the configuration code that read and wrote long values. 7. Changed JZConfiguration::Check to tokenize the passed line using a new function in Globals.cpp. 8. Changed some I/O in the configuration class from C-style to C++ stream. More to come in this area. Modified Paths: -------------- trunk/jazz/src/AlsaDriver.cpp trunk/jazz/src/AlsaDriver.h trunk/jazz/src/AlsaPlayer.cpp trunk/jazz/src/AlsaPlayer.h trunk/jazz/src/AudioDriver.cpp trunk/jazz/src/AudioDriver.h trunk/jazz/src/Configuration.cpp trunk/jazz/src/Configuration.h trunk/jazz/src/Dialogs/midiTiming.cpp trunk/jazz/src/Globals.cpp trunk/jazz/src/Globals.h trunk/jazz/src/MidiDeviceDialog.cpp trunk/jazz/src/MidiDeviceDialog.h trunk/jazz/src/Player.cpp trunk/jazz/src/Player.h trunk/jazz/src/PortMidiPlayer.cpp trunk/jazz/src/PortMidiPlayer.h trunk/jazz/src/Project.cpp trunk/jazz/src/TrackFrame.cpp trunk/jazz/src/mswin/WindowsAudioInterface.cpp trunk/jazz/src/mswin/WindowsAudioInterface.h trunk/jazz/src/mswin/WindowsPlayer.cpp trunk/jazz/src/mswin/WindowsPlayer.h Modified: trunk/jazz/src/AlsaDriver.cpp =================================================================== --- trunk/jazz/src/AlsaDriver.cpp 2008-05-27 04:05:06 UTC (rev 578) +++ trunk/jazz/src/AlsaDriver.cpp 2008-05-27 14:01:15 UTC (rev 579) @@ -127,7 +127,7 @@ : tAlsaPlayer(pSong) { AudioBuffer = new tEventArray(); - installed = 0; + mInstalled = false; audio_enabled = 0; mpListener = 0; mCanDuplex = 0; // no duplex yet. @@ -139,7 +139,7 @@ // FIXME mCanDuplex = 1; - installed = 1; + mInstalled = true; audio_enabled = 1; } Modified: trunk/jazz/src/AlsaDriver.h =================================================================== --- trunk/jazz/src/AlsaDriver.h 2008-05-27 04:05:06 UTC (rev 578) +++ trunk/jazz/src/AlsaDriver.h 2008-05-27 14:01:15 UTC (rev 579) @@ -43,7 +43,10 @@ virtual void Notify(); virtual void StartPlay(long Clock, long LoopClock = 0, int Continue = 0); virtual void StopPlay(); - virtual int Installed() { return installed && tAlsaPlayer::Installed(); } + virtual bool IsInstalled() + { + return mInstalled && tAlsaPlayer::IsInstalled(); + } virtual int GetAudioEnabled() const { return audio_enabled; } virtual void SetAudioEnabled(int x) { audio_enabled = x; } virtual void ListenAudio(int key, int start_stop_mode = 1); @@ -82,7 +85,7 @@ int mCanDuplex; snd_pcm_t *pcm[2]; - int installed; + bool mInstalled; long audio_clock_offset; long cur_pos; Modified: trunk/jazz/src/AlsaPlayer.cpp =================================================================== --- trunk/jazz/src/AlsaPlayer.cpp 2008-05-27 04:05:06 UTC (rev 578) +++ trunk/jazz/src/AlsaPlayer.cpp 2008-05-27 14:01:15 UTC (rev 579) @@ -54,7 +54,7 @@ { ithru = othru = 0; - installed = 1; + mInstalled = true; poll_millisec = 25; recd_clock = 0; echo_clock = 0; @@ -62,14 +62,14 @@ if (snd_seq_open(&handle, "hw", SND_SEQ_OPEN_DUPLEX, 0) < 0) { perror("open sequencer"); - installed = 0; + mInstalled = false; return; } // set myself into non blocking mode if (set_blocking_mode(0) < 0) { - installed = 0; + mInstalled = false; return; } client = snd_seq_client_id(handle); @@ -190,7 +190,7 @@ snd_seq_set_output_buffer_size(handle, 65536); - if (installed) + if (mInstalled) { thru = new tAlsaThru(); SetSoftThru( @@ -381,9 +381,9 @@ //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- -int tAlsaPlayer::Installed() +bool tAlsaPlayer::IsInstalled() { - return installed; + return mInstalled; } //----------------------------------------------------------------------------- Modified: trunk/jazz/src/AlsaPlayer.h =================================================================== --- trunk/jazz/src/AlsaPlayer.h 2008-05-27 04:05:06 UTC (rev 578) +++ trunk/jazz/src/AlsaPlayer.h 2008-05-27 14:01:15 UTC (rev 579) @@ -50,7 +50,7 @@ virtual ~tAlsaPlayer(); void Notify(); - int Installed(); + bool IsInstalled(); int OutEvent(JZEvent *e, int now); int OutEvent(JZEvent *e) { return OutEvent(e, 0); } void OutNow(JZEvent *e) { OutEvent(e, 1); } @@ -79,7 +79,7 @@ int sync_in, sync_in_dev, sync_in_mtcType; int sync_out, sync_out_dev, sync_out_mtcType; - int installed; + bool mInstalled; static int create_port(snd_seq_t *handle, const char *name); static void set_client_info(snd_seq_t *handle, const char *name); Modified: trunk/jazz/src/AudioDriver.cpp =================================================================== --- trunk/jazz/src/AudioDriver.cpp 2008-05-27 04:05:06 UTC (rev 578) +++ trunk/jazz/src/AudioDriver.cpp 2008-05-27 14:01:15 UTC (rev 579) @@ -39,6 +39,8 @@ #define AUDIO_DEVICE "/dev/dsp" +//***************************************************************************** +//***************************************************************************** class tAudioListener : public wxTimer { public: @@ -115,14 +117,14 @@ int mHardExit; }; - - -tAudioPlayer::tAudioPlayer(JZSong *song) - : tSeq2Player(song) +//***************************************************************************** +//***************************************************************************** +tAudioPlayer::tAudioPlayer(JZSong* pSong) + : tSeq2Player(pSong) { long dummy = 0; AudioBuffer = new tEventArray(); - installed = 0; + mInstalled = false; dummy = gpConfig->GetValue(C_EnableAudio); audio_enabled = dummy; mpListener = 0; @@ -152,7 +154,7 @@ } else { - installed = 1; + mInstalled = true; } close(dev); @@ -163,7 +165,7 @@ } dev = -1; // closed - audio_enabled = audio_enabled && installed; + audio_enabled = audio_enabled && mInstalled; } Modified: trunk/jazz/src/AudioDriver.h =================================================================== --- trunk/jazz/src/AudioDriver.h 2008-05-27 04:05:06 UTC (rev 578) +++ trunk/jazz/src/AudioDriver.h 2008-05-27 14:01:15 UTC (rev 579) @@ -60,9 +60,9 @@ virtual void StartAudio(); - virtual int Installed() + virtual int IsIsInstalled() { - return installed && tSeq2Player::Installed(); + return mInstalled && tSeq2Player::IsInstalled(); } virtual int GetAudioEnabled() const @@ -107,7 +107,7 @@ void CloseDsp(bool Reset); int dev; - int installed; + bool mInstalled; long midi_clock; long audio_bytes; Modified: trunk/jazz/src/Configuration.cpp =================================================================== --- trunk/jazz/src/Configuration.cpp 2008-05-27 04:05:06 UTC (rev 578) +++ trunk/jazz/src/Configuration.cpp 2008-05-27 14:01:15 UTC (rev 579) @@ -32,6 +32,7 @@ #include <stack> #include <iostream> #include <sstream> +#include <fstream> using namespace std; @@ -407,20 +408,28 @@ //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- -int JZConfiguration::Check(const char* pName) const +int JZConfiguration::Check(const string& InputLine) const { - if (!pName || (pName[0] != '.')) + string::const_iterator iString = InputLine.begin(); + + if (iString == InputLine.end() || *iString != '.') { return -1; } + const string Delimiters(" \t"); + + vector<string> Tokens; + + Tokenize(InputLine, Delimiters, Tokens); + for (int i = 0; i < NumConfigNames; i++) { if (!mNames[i]) { continue; } - if (!strncmp(pName, mNames[i]->GetName(), strlen(mNames[i]->GetName()))) + if (Tokens[0] == mNames[i]->GetName()) { // Found return i; @@ -475,7 +484,7 @@ else if (mNames[entry]->GetType() == eConfigEntryTypeStr) { // Allow whitespace inside entries like "C:\Program Files\JazzWare". - int ofs = strlen(mNames[entry]->GetName()); + int ofs = mNames[entry]->GetName().length(); while (buf[ofs] == ' ' || buf[ofs] == '\t') // not \n { ++ofs; @@ -531,7 +540,7 @@ //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- -bool JZConfiguration::Get(int entry, char *value) +bool JZConfiguration::Get(int entry, char* value) { assert((entry >= 0) && (entry < NumConfigNames)); @@ -542,14 +551,14 @@ } FILE *fd = fopen(FileName.c_str(), "r"); - const char* name = GetName(entry); + const string& name = GetName(entry); - int len = strlen(name); + int len = name.length(); char buf[1000]; bool found = false; while (!found && fgets(buf, sizeof(buf), fd) != NULL) { - if (strncmp(buf, name, len) == 0) + if (strncmp(buf, name.c_str(), len) == 0) { while (isspace(buf[len])) { @@ -570,12 +579,12 @@ //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- -bool JZConfiguration::Get(int entry, long &value) +bool JZConfiguration::Get(int entry, int& value) { char buf[512]; if (Get(entry, buf)) { - sscanf(buf, " %ld ", &value); + sscanf(buf, " %d ", &value); return true; } return false; @@ -587,7 +596,7 @@ // entries to there. If the name/value pair is found, replace it, otherwise // write it. Finally copy the temp file over the old configuration file. //----------------------------------------------------------------------------- -bool JZConfiguration::Put(int Index, const char *value) +bool JZConfiguration::Put(int Index, const string& ValueString) { assert((Index >= 0) && (Index < NumConfigNames)); @@ -597,61 +606,53 @@ return false; } - char tempname[512]; - strcpy(tempname, FileName.c_str()); - strcat(tempname, ".tmp"); //make the temp file name - FILE *out = fopen(tempname, "w"); - if (!out) + // Create a temporary file name from the current file name. + string TempFileName(FileName); + TempFileName.append(".tmp"); + ofstream Os(TempFileName.c_str()); + if (!Os) { return false; } FILE* inp = fopen(FileName.c_str(), "r"); - const char* name = GetName(Index); + const string& name = GetName(Index); - int len = strlen(name); + int len = name.length(); char buf[1000]; bool found = false; while (fgets(buf, sizeof(buf), inp) != NULL) { - if (strncmp(buf, name, len) == 0) + if (strncmp(buf, name.c_str(), len) == 0) { - fprintf(out, "%s %s\n", name, value); + Os << name << ' ' << ValueString << endl; found = true; } else { - fputs(buf, out); + Os << buf; } } if (!found) { - fprintf(out, "%s %s\n", name, value); + Os << name << ' ' << ValueString << endl; } fclose(inp); - fclose(out); + Os.close(); + unlink(FileName.c_str()); - rename(tempname, FileName.c_str()); + rename(TempFileName.c_str(), FileName.c_str()); return true; } //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- -bool JZConfiguration::Put(int Index, long Value) -{ - ostringstream Oss; - Oss << Value; - return Put(Index, Oss.str().c_str()); -} - -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- bool JZConfiguration::Put(int Index) { assert((Index >= 0) && (Index < NumConfigNames)); mNames[Index]->SetValue(Index); - long LongValue = mNames[Index]->GetValue(); - return Put(Index, LongValue); + int Value = mNames[Index]->GetValue(); + return Put(Index, Value); } //----------------------------------------------------------------------------- @@ -660,8 +661,9 @@ { assert((Index >= 0) && (Index < NumConfigNames)); mNames[Index]->SetValue(Value); - long LongValue = mNames[Index]->GetValue(); - return Put(Index, LongValue); + ostringstream Oss; + Oss << Value; + return Put(Index, Oss.str()); } //----------------------------------------------------------------------------- @@ -692,6 +694,7 @@ vector<pair<string, int> >* pVector = 0; +// stack<ifstream> InputFileStreams; stack<FILE*> FileDescriptors; cout @@ -699,7 +702,11 @@ << " \"" << mFileName << '"' << endl; +// ifstream Is(mFileName.c_str()); +// InputFileStreams.push(Is); FileDescriptors.push(fopen(mFileName.c_str(), "r")); + +// if (!InputFileStreams.top()) if (FileDescriptors.top() == NULL) { wxString String; @@ -719,10 +726,17 @@ while (1) { // Read a line from the current file. + +// if (getline(InputFileStreams.top(), InputLine)) if (fgets(buf, sizeof(buf), FileDescriptors.top()) == NULL) { +// InputFileStreams.top().close(); fclose(FileDescriptors.top()); + +// InputFileStreams.pop(); FileDescriptors.pop(); + +// if (InputFileStreams.empty()) if (FileDescriptors.empty()) { // The code has reached the last line of the Jazz++ configuration file @@ -800,13 +814,16 @@ if (IncludeFileName.empty()) { +// InputFileStreams FileDescriptors.push(NULL); } else { +// InputFileStreams FileDescriptors.push(fopen(IncludeFileName, "r")); } +// InputFileStreams if (FileDescriptors.top() == NULL) { wxString String; @@ -814,6 +831,8 @@ << "Could not open configuration include file:" << '\n' << '"' << buf << '"'; ::wxMessageBox(String, "Warning", wxOK); + +// InputFileStreams.pop(); FileDescriptors.pop(); } } Modified: trunk/jazz/src/Configuration.h =================================================================== --- trunk/jazz/src/Configuration.h 2008-05-27 04:05:06 UTC (rev 578) +++ trunk/jazz/src/Configuration.h 2008-05-27 14:01:15 UTC (rev 579) @@ -144,7 +144,7 @@ TEConfigEntryType GetType() const; - const char* GetName() const; + const std::string& GetName() const; const int& GetValue() const; @@ -177,9 +177,9 @@ //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- inline -const char* JZConfigurationEntry::GetName() const +const std::string& JZConfigurationEntry::GetName() const { - return mName.c_str(); + return mName; } //----------------------------------------------------------------------------- @@ -218,31 +218,30 @@ void LoadConfig(const wxString& FileName); - int Check(const char* pName) const; + int Check(const std::string& Name) const; int Load(char* buf); - const std::pair<std::string, int>& GetDrumName(unsigned entry) const; - const std::pair<std::string, int>& GetDrumSet(unsigned entry) const; - const std::pair<std::string, int>& GetVoiceName(unsigned entry) const; - const std::pair<std::string, int>& GetCtrlName(unsigned entry) const; + const std::pair<std::string, int>& GetDrumName(unsigned Entry) const; + const std::pair<std::string, int>& GetDrumSet(unsigned Entry) const; + const std::pair<std::string, int>& GetVoiceName(unsigned Entry) const; + const std::pair<std::string, int>& GetCtrlName(unsigned Entry) const; - JZDoubleCommand& BankEntry(unsigned entry); + JZDoubleCommand& BankEntry(unsigned Entry); - const char* GetName(int entry) const; + const std::string& GetName(int Entry) const; - const std::string& GetStrValue(int entry) const; + const std::string& GetStrValue(int Entry) const; const int& GetValue(const char* pName) const; const int& GetValue(int Index) const; - bool Get(int entry, char* value); - bool Get(int entry, long& value); + bool Get(int Entry, char* pValue); + bool Get(int Entry, int& Value); - bool Put(int entry, const char *value); - bool Put(int entry, long value); - bool Put(int entry); - bool Put(int entry, int value); + bool Put(int Entry, const std::string& ValueString); + bool Put(int Entry); + bool Put(int Entry, int Value); const std::vector<std::pair<std::string, int> >& GetDrumSets() const; @@ -284,19 +283,19 @@ //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- inline -const char* JZConfiguration::GetName(int entry) const +const std::string& JZConfiguration::GetName(int Entry) const { - assert((entry >= 0) && (entry < NumConfigNames)); - return mNames[entry]->GetName(); + assert((Entry >= 0) && (Entry < NumConfigNames)); + return mNames[Entry]->GetName(); } //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- inline -const std::string& JZConfiguration::GetStrValue(int entry) const +const std::string& JZConfiguration::GetStrValue(int Entry) const { - assert((entry >= 0) && (entry < NumConfigNames)); - return mNames[entry]->GetStrValue(); + assert((Entry >= 0) && (Entry < NumConfigNames)); + return mNames[Entry]->GetStrValue(); } //----------------------------------------------------------------------------- Modified: trunk/jazz/src/Dialogs/midiTiming.cpp =================================================================== --- trunk/jazz/src/Dialogs/midiTiming.cpp 2008-05-27 04:05:06 UTC (rev 578) +++ trunk/jazz/src/Dialogs/midiTiming.cpp 2008-05-27 14:01:15 UTC (rev 579) @@ -62,9 +62,9 @@ Config(C_ClockSource) = CsMtc; ClkSrcListBox->SetStringSelection( ClkSrcArray[ Config(C_ClockSource) ] ); Midi = new JZWindowsMtcPlayer(EventWin->Song); - if (!Midi->Installed()) + if (!Midi->IsInstalled()) { - wxMessageBox("no midi driver installed", "Error", wxOK); + wxMessageBox("no MIDI driver installed", "Error", wxOK); Midi = new tNullPlayer(EventWin->Song); } } @@ -149,9 +149,9 @@ Midi = new tWinAudioPlayer(EventWin->Song); break; } - if (!Midi->Installed()) + if (!Midi->IsInstalled()) { - wxMessageBox("no midi driver installed", "Error", wxOK); + wxMessageBox("no MIDI driver installed", "Error", wxOK); Midi = new tNullPlayer(EventWin->Song); } #endif Modified: trunk/jazz/src/Globals.cpp =================================================================== --- trunk/jazz/src/Globals.cpp 2008-05-27 04:05:06 UTC (rev 578) +++ trunk/jazz/src/Globals.cpp 2008-05-27 14:01:15 UTC (rev 579) @@ -67,3 +67,42 @@ const double gDegreesToRadians = 0.01745329251994330212; const double gRadiansToDegrees = 57.2957795130823; + +//***************************************************************************** +// Decsription: +// This function tokenizes the input string. +//***************************************************************************** +int Tokenize( + const string& String, + const string& Delimiters, + vector<string>& Tokens) +{ + string::size_type Begin, End; + + // Initialize the token index. + int TokenIndex = 0; + + // Search the beginning of the line for the first token. + Begin = String.find_first_not_of(Delimiters); + + // While at the beginning of a word found. + while (Begin != string::npos) + { + // Search for the end of the actual token. + End = String.find_first_of(Delimiters, Begin); + + if (End == string::npos) + { + End = String.length(); + } + + Tokens.push_back(String.substr(Begin, End - Begin)); + + ++TokenIndex; + + Begin = String.find_first_not_of(Delimiters, End); + } + + return TokenIndex; +} + Modified: trunk/jazz/src/Globals.h =================================================================== --- trunk/jazz/src/Globals.h 2008-05-27 04:05:06 UTC (rev 578) +++ trunk/jazz/src/Globals.h 2008-05-27 14:01:15 UTC (rev 579) @@ -65,4 +65,11 @@ extern const double gDegreesToRadians; extern const double gRadiansToDegrees; +//***************************************************************************** +//***************************************************************************** +int Tokenize( + const std::string& String, + const std::string& Delimiters, + std::vector<std::string>& Tokens); + #endif // !defined(JZ_GLOBALS_H) Modified: trunk/jazz/src/MidiDeviceDialog.cpp =================================================================== --- trunk/jazz/src/MidiDeviceDialog.cpp 2008-05-27 04:05:06 UTC (rev 578) +++ trunk/jazz/src/MidiDeviceDialog.cpp 2008-05-27 14:01:15 UTC (rev 579) @@ -40,7 +40,7 @@ //----------------------------------------------------------------------------- JZMidiDeviceDialog::JZMidiDeviceDialog( const vector<pair<string, int> >& MidiDevices, - long& DeviceIndex, + int& DeviceIndex, wxWindow* pParent, const wxString& Title) : wxDialog(pParent, wxID_ANY, Title), Modified: trunk/jazz/src/MidiDeviceDialog.h =================================================================== --- trunk/jazz/src/MidiDeviceDialog.h 2008-05-27 04:05:06 UTC (rev 578) +++ trunk/jazz/src/MidiDeviceDialog.h 2008-05-27 14:01:15 UTC (rev 579) @@ -36,7 +36,7 @@ JZMidiDeviceDialog( const std::vector<std::pair<std::string, int> >& MidiDevices, - long& DeviceIndex, + int& DeviceIndex, wxWindow* pParent = 0, const wxString& Title = wxEmptyString); @@ -46,7 +46,7 @@ private: - long& mDeviceIndex; + int& mDeviceIndex; wxListBox* mpMidiDeviceListBox; Modified: trunk/jazz/src/Player.cpp =================================================================== --- trunk/jazz/src/Player.cpp 2008-05-27 04:05:06 UTC (rev 578) +++ trunk/jazz/src/Player.cpp 2008-05-27 14:01:15 UTC (rev 579) @@ -686,7 +686,7 @@ //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- -int tMpuPlayer::Installed() +bool tMpuPlayer::IsInstalled() { return dev >= 0; } @@ -1483,7 +1483,7 @@ if (mididev < 0) { - return; // Installed() == FALSE + return; // IsInstalled() == FALSE } } @@ -1509,7 +1509,7 @@ //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- -int tSeq2Player::Installed() +bool tSeq2Player::IsInstalled() { return seqfd >= 0 && mididev >= 0; } Modified: trunk/jazz/src/Player.h =================================================================== --- trunk/jazz/src/Player.h 2008-05-27 04:05:06 UTC (rev 578) +++ trunk/jazz/src/Player.h 2008-05-27 14:01:15 UTC (rev 579) @@ -38,7 +38,8 @@ class JZRecordingInfo; - +//***************************************************************************** +//***************************************************************************** class tPlayLoop { public: @@ -71,6 +72,8 @@ long mStopClock; }; +//***************************************************************************** +//***************************************************************************** enum tClockSource { CsInt = 0, @@ -79,6 +82,8 @@ CsMtc }; +//***************************************************************************** +//***************************************************************************** class tDeviceList { public: @@ -124,6 +129,8 @@ tDeviceList& operator = (const tDeviceList &); }; +//***************************************************************************** +//***************************************************************************** class JZPlayer : public wxTimer { protected: @@ -139,7 +146,9 @@ bool Playing; // successful StartPlay - virtual int Installed() = 0; // Hardware found + // Tests if hardware found and successfully setup. + virtual bool IsInstalled() = 0; + // if unable to install, pop up a messagebox explaining why. virtual void ShowError(); @@ -280,15 +289,17 @@ extern char *midinethost; -// -------------------------------------------------------- +//***************************************************************************** // Roland MPU 401 -// -------------------------------------------------------- +//***************************************************************************** #ifdef DEV_MPU401 #include <unistd.h> #include <fcntl.h> +//***************************************************************************** +//***************************************************************************** class tBuffer : public tWriteBase { @@ -440,6 +451,8 @@ #define ACTIVE_TRACKS 7 #define ACTIVE_TRACKS_MASK 0x7f +//***************************************************************************** +//***************************************************************************** class tMpuPlayer : public JZPlayer { int dev; @@ -465,7 +478,7 @@ void StartPlay(long Clock, long LoopClock = 0, int Continue = 0); void StopPlay(); long GetRealTimeClock(); - int Installed(); + virtual bool IsInstalled(); long GetRecordedData(); void SetHardThru(int on, int idev, int odev); @@ -482,8 +495,10 @@ #endif // DEV_MPU401 -// ------------------------------ null-driver ------------------------------- - +//***************************************************************************** +// Description: +// This is the null driver class declaration. +//***************************************************************************** class tNullPlayer : public JZPlayer { public: @@ -493,9 +508,9 @@ { } - int Installed() + virtual bool IsInstalled() { - return 1; + return true; } virtual ~tNullPlayer() @@ -544,6 +559,8 @@ void seqbuf_flush_last_event(); +//***************************************************************************** +//***************************************************************************** class tOSSThru : public wxTimer { public: @@ -552,14 +569,15 @@ ~tOSSThru(); }; - - +//***************************************************************************** +//***************************************************************************** class tSeq2Player : public JZPlayer { public: + friend class tOSSThru; tSeq2Player(JZSong *song); - int Installed(); + virtual bool IsInstalled(); virtual ~tSeq2Player(); int OutEvent(JZEvent *e, int now); int OutEvent(JZEvent *e) { OutEvent(e, 0); return 0; } Modified: trunk/jazz/src/PortMidiPlayer.cpp =================================================================== --- trunk/jazz/src/PortMidiPlayer.cpp 2008-05-27 04:05:06 UTC (rev 578) +++ trunk/jazz/src/PortMidiPlayer.cpp 2008-05-27 14:01:15 UTC (rev 579) @@ -1,10 +1,19 @@ #include "WxWidgets.h" #include "PortMidiPlayer.h" +#include "JazzPlusPlusApplication.h" +#include "TrackFrame.h" #include "TrackWindow.h" #include "Song.h" #include "Globals.h" +#include "MidiDeviceDialog.h" +#include <iostream> + +using namespace std; + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- JZPortMidiPlayer::JZPortMidiPlayer(JZSong* pSong) : JZPlayer(pSong), mInputDevices(), @@ -29,96 +38,102 @@ // mOutputQueue = Pm_QueueCreate(1024, sizeof(PmEvent)); } +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- JZPortMidiPlayer::~JZPortMidiPlayer() { // Pm_QueueDestroy(mOutputQueue); TermPM(); } -int -JZPortMidiPlayer::Installed() +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +bool JZPortMidiPlayer::IsInstalled() { return true; } -wxString -JZPortMidiPlayer::GetInputDeviceName() +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +wxString JZPortMidiPlayer::GetInputDeviceName() { return mInputDevice; } -wxString -JZPortMidiPlayer::GetOutputDeviceName() +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +wxString JZPortMidiPlayer::GetOutputDeviceName() { return mOutputDevice; } - -void -JZPortMidiPlayer::SetInputDevice(const wxString & name) +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +void JZPortMidiPlayer::SetInputDevice(const wxString& Name) { - bool term = InitPM(); - PmDeviceID id = FindDevice(name, true); + bool NeedToTerminate = InitPM(); + PmDeviceID id = FindDevice(Name, true); if (id != pmNoDevice) { - mInputDevice = name; + mInputDevice = Name; } - if (term) + if (NeedToTerminate) { TermPM(); } } -void -JZPortMidiPlayer::SetOutputDevice(const wxString& name) +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +void JZPortMidiPlayer::SetOutputDevice(const wxString& Name) { - bool term = InitPM(); - PmDeviceID id = FindDevice(name, false); + bool NeedToTerminate = InitPM(); + PmDeviceID id = FindDevice(Name, false); if (id != pmNoDevice) { - mOutputDevice = name; + mOutputDevice = Name; } - if (term) + if (NeedToTerminate) { TermPM(); } } -int -JZPortMidiPlayer::SupportsMultipleDevices() +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +int JZPortMidiPlayer::SupportsMultipleDevices() { return true; } -tDeviceList& -JZPortMidiPlayer::GetOutputDevices() +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +tDeviceList& JZPortMidiPlayer::GetOutputDevices() { - bool term = InitPM(); - int cnt; + bool NeedToTerminate = InitPM(); + int Count = Pm_CountDevices(); - cnt = Pm_CountDevices(); - mOutputDevices.Clear(); - for (int i = 0; i < cnt; i++) + for (int i = 0; i < Count; ++i) { - const PmDeviceInfo *di = Pm_GetDeviceInfo(i); + const PmDeviceInfo* pPmDeviceInfo = Pm_GetDeviceInfo(i); - if (di && di->output) + if (pPmDeviceInfo && pPmDeviceInfo->output) { - wxString name = - wxString(di->interf, wxConvISO8859_1) + + wxString Name = + wxString(pPmDeviceInfo->interf, wxConvISO8859_1) + wxT(", ") + - wxString(di->name, wxConvISO8859_1); - mOutputDevices.Add(name); + wxString(pPmDeviceInfo->name, wxConvISO8859_1); + mOutputDevices.Add(Name); } } - if (term) + if (NeedToTerminate) { TermPM(); } @@ -126,31 +141,30 @@ return mOutputDevices; } -tDeviceList& -JZPortMidiPlayer::GetInputDevices() +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +tDeviceList& JZPortMidiPlayer::GetInputDevices() { - bool term = InitPM(); - int cnt; - - cnt = Pm_CountDevices(); + bool NeedToTerminate = InitPM(); + int Count = Pm_CountDevices(); mInputDevices.Clear(); - for (int i = 0; i < cnt; i++) + for (int i = 0; i < Count; ++i) { - const PmDeviceInfo *di = Pm_GetDeviceInfo(i); + const PmDeviceInfo* pPmDeviceInfo = Pm_GetDeviceInfo(i); - if (di && di->input) + if (pPmDeviceInfo && pPmDeviceInfo->input) { - wxString name = - wxString(di->interf, wxConvISO8859_1) + + wxString Name = + wxString(pPmDeviceInfo->interf, wxConvISO8859_1) + wxT(", ") + - wxString(di->name, wxConvISO8859_1); - mInputDevices.Add(name); + wxString(pPmDeviceInfo->name, wxConvISO8859_1); + mInputDevices.Add(Name); } } - if (term) + if (NeedToTerminate) { TermPM(); } @@ -158,23 +172,24 @@ return mInputDevices; } -PmDeviceID -JZPortMidiPlayer::FindDevice(const wxString & name, bool input) +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +PmDeviceID JZPortMidiPlayer::FindDevice(const wxString& Name, bool input) { - int cnt = Pm_CountDevices(); + int Count = Pm_CountDevices(); - for (int i = 0; i < cnt; i++) + for (int i = 0; i < Count; i++) { - const PmDeviceInfo *di = Pm_GetDeviceInfo(i); + const PmDeviceInfo* pPmDeviceInfo = Pm_GetDeviceInfo(i); - if (di && (input ? di->input : di->output)) + if (pPmDeviceInfo && (input ? pPmDeviceInfo->input : pPmDeviceInfo->output)) { wxString n = - wxString(di->interf, wxConvISO8859_1) + + wxString(pPmDeviceInfo->interf, wxConvISO8859_1) + wxT(", ") + - wxString(di->name, wxConvISO8859_1); + wxString(pPmDeviceInfo->name, wxConvISO8859_1); - if (name == n) + if (Name == n) { return i; } @@ -184,8 +199,9 @@ return pmNoDevice; } -int -JZPortMidiPlayer::Clock2Time(int clock) +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +int JZPortMidiPlayer::Clock2Time(int clock) { if (clock < mStartClock) { @@ -195,8 +211,9 @@ return (int)((double)(clock - mStartClock) * 60000.0 / (double) mTicksPerMinute + mStartTime); } -int -JZPortMidiPlayer::Time2Clock(int time) +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +int JZPortMidiPlayer::Time2Clock(int time) { if (time < mStartTime) { @@ -206,8 +223,9 @@ return (int)((double)(time - mStartTime) * (double) mTicksPerMinute / 60000.0 + mStartClock); } -void -JZPortMidiPlayer::SetTempo(int bpm, int clock) +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +void JZPortMidiPlayer::SetTempo(int bpm, int clock) { int t1 = Clock2Time(clock); mTicksPerMinute = bpm * Song->GetTicksPerQuarter(); @@ -215,13 +233,15 @@ mStartTime += (t1 - t2); } -void -JZPortMidiPlayer::OutBreak() +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +void JZPortMidiPlayer::OutBreak() { } -int -JZPortMidiPlayer::OutEvent(JZEvent* pEvent, int now) +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +int JZPortMidiPlayer::OutEvent(JZEvent* pEvent, int now) { PmError rc = pmNoError; PmTimestamp t = (now ? 0 : pEvent->GetClock()); @@ -321,27 +341,30 @@ return rc != pmNoError; } -int -JZPortMidiPlayer::OutEvent(JZEvent* pEvent) +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +int JZPortMidiPlayer::OutEvent(JZEvent* pEvent) { return OutEvent(pEvent, 0); } -void -JZPortMidiPlayer::OutNow(JZEvent*pEvent) +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +void JZPortMidiPlayer::OutNow(JZEvent*pEvent) { OutEvent(pEvent, 1); } -void -JZPortMidiPlayer::StartPlay(int clock, int loopClock, int cont) +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +void JZPortMidiPlayer::StartPlay(int clock, int loopClock, int cont) { - bool term = InitPM(); + bool NeedToTerminate = InitPM(); PmDeviceID id = FindDevice(mOutputDevice, false); if (id == pmNoDevice) { - if (term) + if (NeedToTerminate) { TermPM(); } @@ -349,7 +372,10 @@ return; } - printf("rc = %d %d\n", Pm_OpenOutput(&mpStream, id, NULL, 0, NULL, NULL, 100), id); + cout + << "rc = " << Pm_OpenOutput(&mpStream, id, NULL, 0, NULL, NULL, 100) + << ' ' << id + << endl; mStartTime = Pt_Time() + 500; mStartClock = clock; @@ -358,8 +384,9 @@ JZPlayer::StartPlay(clock, loopClock, cont); } -void -JZPortMidiPlayer::StopPlay() +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +void JZPortMidiPlayer::StopPlay() { JZPlayer::StopPlay(); @@ -373,18 +400,21 @@ TermPM(); } -long -JZPortMidiPlayer::GetRealTimeClock() +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +long JZPortMidiPlayer::GetRealTimeClock() { long t = Pt_Time(); - gpTrackWindow->NewPlayPosition(PlayLoop->Ext2IntClock(Time2Clock(t) / 48 * 48)); + gpTrackWindow->NewPlayPosition( + PlayLoop->Ext2IntClock(Time2Clock(t) / 48 * 48)); return Time2Clock(t); } -bool -JZPortMidiPlayer::InitPM() +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +bool JZPortMidiPlayer::InitPM() { if (mInitialized) { @@ -398,8 +428,9 @@ return true; } -bool -JZPortMidiPlayer::TermPM() +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +bool JZPortMidiPlayer::TermPM() { if (!mInitialized) { @@ -412,3 +443,109 @@ return true; } + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +void JZPortMidiPlayer::DeviceSelectionDialog() +{ + // Create a list of devices. + bool NeedToTerminate = InitPM(); + int Count = Pm_CountDevices(); + + vector<pair<string, int> > MidiDevices; + + // Create a container of input devices. + for (int i = 0; i < Count; ++i) + { + const PmDeviceInfo* pPmDeviceInfo = Pm_GetDeviceInfo(i); + + if (pPmDeviceInfo && pPmDeviceInfo->input) + { + wxString Name = + wxString(pPmDeviceInfo->interf, wxConvISO8859_1) + + wxT(", ") + + wxString(pPmDeviceInfo->name, wxConvISO8859_1); + + MidiDevices.push_back(make_pair(Name.c_str(), i)); + } + } + + // Select the input device. + int InputDevice = -1; + if (!MidiDevices.empty()) + { + JZMidiDeviceDialog MidiInputDeviceDialog( + MidiDevices, + InputDevice, + ::wxGetApp().GetMainFrame(), + "Input MIDI device"); + MidiInputDeviceDialog.ShowModal(); + + // Set the input device based on the selected integer. + for ( + vector<pair<string, int> >::const_iterator iDevice = + MidiDevices.begin(); + iDevice != MidiDevices.end(); + ++iDevice) + { + if (iDevice->second == InputDevice) + { + SetOutputDevice(iDevice->first.c_str()); + break; + } + } + } + + MidiDevices.clear(); + + // Create a container of output devices. + for (int i = 0; i < Count; ++i) + { + const PmDeviceInfo* pPmDeviceInfo = Pm_GetDeviceInfo(i); + + if (pPmDeviceInfo && pPmDeviceInfo->output) + { + wxString Name = + wxString(pPmDeviceInfo->interf, wxConvISO8859_1) + + wxT(", ") + + wxString(pPmDeviceInfo->name, wxConvISO8859_1); + + MidiDevices.push_back(make_pair(Name.c_str(), i)); + } + } + + // Select the output device. + int OutputDevice = -1; + if (!MidiDevices.empty()) + { + JZMidiDeviceDialog MidiOutputDeviceDialog( + MidiDevices, + OutputDevice, + gpTrackWindow, + "Output MIDI device"); + MidiOutputDeviceDialog.ShowModal(); + + // Set the output device based on the selected integer. + for ( + vector<pair<string, int> >::const_iterator iDevice = + MidiDevices.begin(); + iDevice != MidiDevices.end(); + ++iDevice) + { + if (iDevice->second == OutputDevice) + { + SetOutputDevice(iDevice->first.c_str()); + break; + } + } + } + +// gpConfig->Put(C_WinInputDevice, InputDevice); + +// gpConfig->Put(C_WinOutputDevice, OutputDevice); + + if (NeedToTerminate) + { + TermPM(); + } +} Modified: trunk/jazz/src/PortMidiPlayer.h =================================================================== --- trunk/jazz/src/PortMidiPlayer.h 2008-05-27 04:05:06 UTC (rev 578) +++ trunk/jazz/src/PortMidiPlayer.h 2008-05-27 14:01:15 UTC (rev 579) @@ -17,7 +17,7 @@ virtual ~JZPortMidiPlayer(); - int Installed(); + virtual bool IsInstalled(); int SupportsMultipleDevices(); virtual tDeviceList& GetInputDevices(); @@ -41,6 +41,8 @@ int Time2Clock(int time); void SetTempo(int bpm, int clock); + void DeviceSelectionDialog(); + private: bool InitPM(); Modified: trunk/jazz/src/Project.cpp =================================================================== --- trunk/jazz/src/Project.cpp 2008-05-27 04:05:06 UTC (rev 578) +++ trunk/jazz/src/Project.cpp 2008-05-27 14:01:15 UTC (rev 579) @@ -168,14 +168,14 @@ { #ifdef DEV_SEQUENCER2 mpMidiPlayer = new tAudioPlayer(this); - if (!mpMidiPlayer->Installed()) + if (!mpMidiPlayer->IsInstalled()) { cerr << "tAudioPlayer didn't install." << endl; delete mpMidiPlayer; mpMidiPlayer = new tSeq2Player(this); } - if (!mpMidiPlayer->Installed()) + if (!mpMidiPlayer->IsInstalled()) { cerr << "tSeq2Player didn't install." << endl; @@ -195,14 +195,14 @@ { #ifdef DEV_ALSA mpMidiPlayer = new tAlsaAudioPlayer(this); - if (!mpMidiPlayer->Installed()) + if (!mpMidiPlayer->IsInstalled()) { cerr << "tAlsaAudioPlayer didn't install." << endl; delete mpMidiPlayer; mpMidiPlayer = new tAlsaPlayer(this); } - if (!mpMidiPlayer->Installed()) + if (!mpMidiPlayer->IsInstalled()) { cerr << "tAlsaPlayer didn't install." << endl; @@ -223,7 +223,7 @@ { #ifdef DEV_MPU401 mpMidiPlayer = new tMpuPlayer(this); - if (!mpMidiPlayer->Installed()) + if (!mpMidiPlayer->IsInstalled()) { cerr << "tMpuPlayer didn't install." << endl; @@ -267,7 +267,7 @@ case CsInt: default: mpMidiPlayer = new JZWindowsAudioPlayer(this); - if (!mpMidiPlayer->Installed()) + if (!mpMidiPlayer->IsInstalled()) { mpMidiPlayer->ShowError(); delete mpMidiPlayer; @@ -275,7 +275,7 @@ } break; } - if (!mpMidiPlayer->Installed()) + if (!mpMidiPlayer->IsInstalled()) { mpMidiPlayer->ShowError(); delete mpMidiPlayer; @@ -288,8 +288,12 @@ // Macintosh Drivers //------------------ mpMidiPlayer = new JZPortMidiPlayer(this); - if (!mpMidiPlayer->Installed()) + mpMidiPlayer.DeviceSelectionDialog(); + + if (!mpMidiPlayer->IsInstalled()) { + delete mpMidiPlayer; + mpMidiPlayer = 0; cout << "Jazz++ will start with no play/record ability." << endl; } #endif // __WXMAC__ Modified: trunk/jazz/src/TrackFrame.cpp =================================================================== --- trunk/jazz/src/TrackFrame.cpp 2008-05-27 04:05:06 UTC (rev 578) +++ trunk/jazz/src/TrackFrame.cpp 2008-05-27 14:01:15 UTC (rev 579) @@ -570,7 +570,7 @@ void JZTrackFrame::OnSettingsMidiDevice(wxCommandEvent& Event) { #ifdef __WXMSW__ - long InputDevice, OutputDevice; + int InputDevice, OutputDevice; gpConfig->Get(C_WinInputDevice, InputDevice); gpConfig->Get(C_WinOutputDevice, OutputDevice); JZWindowsPlayer::SettingsDlg(InputDevice, OutputDevice); Modified: trunk/jazz/src/mswin/WindowsAudioInterface.cpp =================================================================== --- trunk/jazz/src/mswin/WindowsAudioInterface.cpp 2008-05-27 04:05:06 UTC (rev 578) +++ trunk/jazz/src/mswin/WindowsAudioInterface.cpp 2008-05-27 14:01:15 UTC (rev 579) @@ -157,14 +157,14 @@ long dummy = 0; AudioBuffer = new tEventArray(); - installed = 0; + mInstalled = false; dummy = gpConfig->GetValue(C_EnableAudio); audio_enabled = dummy; hout_open = 0; hinp_open = 0; // check for device - installed = 0; + mInstalled = false; mCanDuplex = (gpConfig->GetValue(C_DuplexAudio) != 0); if (OpenDsp() == 0) @@ -188,11 +188,11 @@ if (!mErrorCode && CloseDsp() == 0) { - installed = 1; + mInstalled = true; } } recbuffers.Clear(); - audio_enabled = (audio_enabled && installed); + audio_enabled = (audio_enabled && mInstalled); } //----------------------------------------------------------------------------- Modified: trunk/jazz/src/mswin/WindowsAudioInterface.h =================================================================== --- trunk/jazz/src/mswin/WindowsAudioInterface.h 2008-05-27 04:05:06 UTC (rev 578) +++ trunk/jazz/src/mswin/WindowsAudioInterface.h 2008-05-27 14:01:15 UTC (rev 579) @@ -66,9 +66,9 @@ virtual void StartAudio(); // called async by driver - virtual int Installed() + virtual bool IsInstalled() { - return installed && JZWindowsIntPlayer::Installed(); + return mInstalled && JZWindowsIntPlayer::IsInstalled(); } virtual int GetAudioEnabled() const @@ -134,7 +134,7 @@ int OpenDsp(); // 0 = ok int CloseDsp(); // 0 = ok - int installed; + bool mInstalled; int audio_enabled; // 0 means midi only long blocks_played; // # of blocks written to device int play_buffers_needed; // driver requests more output buffers Modified: trunk/jazz/src/mswin/WindowsPlayer.cpp =================================================================== --- trunk/jazz/src/mswin/WindowsPlayer.cpp 2008-05-27 04:05:06 UTC (rev 578) +++ trunk/jazz/src/mswin/WindowsPlayer.cpp 2008-05-27 14:01:15 UTC (rev 579) @@ -63,7 +63,7 @@ state->doing_mtc_rec = FALSE; state->audio_player = 0; - long ilong = -1, olong = -1; + int ilong = -1, olong = -1; if ( !gpConfig->Get(C_WinInputDevice, ilong) || !gpConfig->Get(C_WinOutputDevice, olong)) @@ -162,7 +162,7 @@ //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- -int JZWindowsPlayer::Installed() +bool JZWindowsPlayer::IsInstalled() { return timer_installed && state->hout; } @@ -996,7 +996,7 @@ //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- -void JZWindowsPlayer::SettingsDlg(long& InputDevice, long& OutputDevice) +void JZWindowsPlayer::SettingsDlg(int& InputDevice, int& OutputDevice) { vector<pair<string, int> > MidiDevices; Modified: trunk/jazz/src/mswin/WindowsPlayer.h =================================================================== --- trunk/jazz/src/mswin/WindowsPlayer.h 2008-05-27 04:05:06 UTC (rev 578) +++ trunk/jazz/src/mswin/WindowsPlayer.h 2008-05-27 14:01:15 UTC (rev 579) @@ -40,7 +40,7 @@ JZWindowsPlayer(JZSong* pSong); - int Installed(); + virtual bool IsInstalled(); virtual ~JZWindowsPlayer(); virtual int OutEvent(JZEvent* e); virtual int OutSysex(JZEvent* e, DWORD time); @@ -63,7 +63,7 @@ return 0; } - static void SettingsDlg(long& InputDevice, long& OutputDevice); + static void SettingsDlg(int& InputDevice, int& OutputDevice); enum { MAX_MIDI_DEVS = 10 }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |