From: <pst...@us...> - 2009-01-01 03:17:52
|
Revision: 670 http://jazzplusplus.svn.sourceforge.net/jazzplusplus/?rev=670&view=rev Author: pstieber Date: 2009-01-01 03:17:48 +0000 (Thu, 01 Jan 2009) Log Message: ----------- Encapsulated more of the data by using accessors and mutators. Modified Paths: -------------- trunk/jazz/src/Filter.cpp trunk/jazz/src/Filter.h Modified: trunk/jazz/src/Filter.cpp =================================================================== --- trunk/jazz/src/Filter.cpp 2009-01-01 03:14:00 UTC (rev 669) +++ trunk/jazz/src/Filter.cpp 2009-01-01 03:17:48 UTC (rev 670) @@ -22,184 +22,215 @@ #include "Filter.h" -#include "ClockDialog.h" +#include "Dialogs/FilterDialog.h" + #include "Events.h" #include "Help.h" -#include "PropertyListDialog.h" #include "Song.h" #include <cstdlib> +using namespace std; -const JZFilterEvent FltEvents[nFltEvents] = +//***************************************************************************** +//***************************************************************************** +const JZFilterEvent DefaultFilterEvents[eFilterCount] = { { StatKeyOn, "Note", 1, 0, 127}, { StatKeyPressure, "Poly Aftertouch", 1, 0, 127}, { StatControl, "Controller", 1, 0, 127}, { StatProgram, "Patch", 1, 0, 127}, - { StatPitch, "Pitch", 1, -8192, 8192}, - { StatTimeSignat, "Meter", 1, 0, 0}, - { StatChnPressure, "Channel Aftertouch", 1, 0, 0}, - { StatSysEx, "SysEx", 1, 0, 0} + { StatPitch, "Pitch", 1, -8192, 8192} }; - - -JZFilter::JZFilter(JZSong *s) +//***************************************************************************** +// Description: +// This is the filter class definition. +//***************************************************************************** +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +JZFilter::JZFilter(JZSong* pSong) + : mFilterEvents(0), + mOtherSelected(true), + mpSong(pSong), + mFromClock(0), + mToClock(120 * 4), + mFromTrack(1), + mToTrack(1) { - mpSong = s; - FltEvents = new JZFilterEvent [nFltEvents]; - memcpy(FltEvents, ::FltEvents, sizeof(::FltEvents)); + mFilterEvents = new JZFilterEvent [eFilterCount]; + memcpy(mFilterEvents, ::DefaultFilterEvents, sizeof(::DefaultFilterEvents)); - FromClock = 0; - ToClock = 120*4; - FromTrack = 1; - ToTrack = 1; - OtherSelected = 1; - - for (int i = 0; i < nFltEvents; i++) + for (int i = 0; i < eFilterCount; ++i) { - FltEvents[i].FromValue = FltEvents[i].MinValue; - FltEvents[i].ToValue = FltEvents[i].MaxValue; + mFilterEvents[i].FromValue = DefaultFilterEvents[i].MinValue; + mFilterEvents[i].ToValue = DefaultFilterEvents[i].MaxValue; } } - -JZFilter::JZFilter(JZFilter *f) +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +JZFilter::JZFilter(JZFilter const& Other) + : mFilterEvents(0), + mOtherSelected(Other.mOtherSelected), + mpSong(Other.mpSong), + mFromClock(Other.mFromClock), + mToClock(Other.mToClock), + mFromTrack(Other.mFromTrack), + mToTrack(Other.mToTrack) { - copy (*f); + mFilterEvents = new JZFilterEvent [eFilterCount]; + memcpy(mFilterEvents, Other.mFilterEvents, sizeof(::DefaultFilterEvents)); } - -JZFilter::JZFilter(JZFilter const &o) { - copy(o); +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +JZFilter& JZFilter::operator = (JZFilter const& Rhs) +{ + if (this != &Rhs) + { + memcpy(mFilterEvents, Rhs.mFilterEvents, sizeof(::DefaultFilterEvents)); + mOtherSelected = Rhs.mOtherSelected; + mpSong = Rhs.mpSong; + mFromClock = Rhs.mFromClock; + mToClock = Rhs.mToClock; + mFromTrack = Rhs.mFromTrack; + mToTrack = Rhs.mToTrack; + } + return *this; } - -JZFilter& JZFilter::operator=(JZFilter const &o) { - delete FltEvents; - copy(o); - return *this; +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +JZFilter::~JZFilter() +{ + delete mFilterEvents; } -void JZFilter::copy(JZFilter const &o) +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +void JZFilter::GetFilterEvent( + TEFilterType FilterType, + bool& Selected, + int& FromValue, + int& ToValue) { - mpSong = o.mpSong; - FromClock = o.FromClock; - ToClock = o.ToClock; - FromTrack = o.FromTrack; - ToTrack = o.ToTrack; - OtherSelected = o.OtherSelected; - - FltEvents = new JZFilterEvent [nFltEvents]; - memcpy(FltEvents, o.FltEvents, sizeof(::FltEvents)); + Selected = mFilterEvents[FilterType].Selected; + FromValue = mFilterEvents[FilterType].FromValue; + ToValue = mFilterEvents[FilterType].ToValue; } - -JZFilter::~JZFilter() +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +void JZFilter::SetFilterEvent( + TEFilterType FilterType, + bool Selected, + int FromValue, + int ToValue) { - delete FltEvents; + mFilterEvents[FilterType].Selected = Selected; + mFilterEvents[FilterType].FromValue = FromValue; + mFilterEvents[FilterType].ToValue = ToValue; } - -// ************************************************************************* -// Dialog -// ************************************************************************* - - - -class tFilterDlg : public tPropertyListDlg +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +void JZFilter::SetOtherSelected(bool OtherSelected) { - JZFilter *Filter; - JZClockDialog FromClockDlg, ToClockDlg; + mOtherSelected = OtherSelected; +} - public: - tFilterDlg(JZFilter *f, JZSong *s, int ShowEventStats); - void AddProperties(); - bool OnClose(); - void OnHelp(); - int ShowEventStats; -}; - - -tFilterDlg::tFilterDlg(JZFilter *f, JZSong *Song, int ShowEventStats) - : tPropertyListDlg("Filter"), - FromClockDlg(Song, "From Time: ", f->FromClock), - ToClockDlg(Song, "To Time: ", f->ToClock) +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +void JZFilter::GenerateFromTimeString(string& FromTimeString) const { - this->ShowEventStats=ShowEventStats; - Filter = f; + if (mpSong) + { + mpSong->ClockToString(mFromClock, FromTimeString); + } } - -void tFilterDlg::AddProperties() +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +void JZFilter::SetFromTime(const string& FromTimeString) { -// Add(FromClockDlg.mkFormItem(150)); -// Add(ToClockDlg.mkFormItem(150)); -// Add(wxMakeFormNewLine()); -// #ifdef __WXMSW__ -// Add(wxMakeFormShort("From Track:", &Filter->FromTrack, wxFORM_DEFAULT, 0,0,0,110)); -// Add(wxMakeFormShort("To Track:", &Filter->ToTrack, wxFORM_DEFAULT, 0,0,0,110)); -// Add(wxMakeFormNewLine()); -// #else -// Add(wxMakeFormShort("From Track:", &Filter->FromTrack, wxFORM_DEFAULT)); -// Add(wxMakeFormShort("To Track:", &Filter->ToTrack, wxFORM_DEFAULT)); -// Add(wxMakeFormNewLine()); -// #endif - -// if (ShowEventStats) -// { -// for (int i = 0; i < nFltEvents; i++) -// { -// if (Filter->FltEvents[i].MinValue != Filter->FltEvents[i].MaxValue) -// { -// Add(wxMakeFormShort("Min:", &Filter->FltEvents[i].FromValue, wxFORM_DEFAULT,0,0,0,90)); -// Add(wxMakeFormShort("Max:", &Filter->FltEvents[i].ToValue, wxFORM_DEFAULT,0,0,0,90)); -// Add(wxMakeFormBool(Filter->FltEvents[i].Name, &Filter->FltEvents[i].Selected, wxFORM_DEFAULT)); -// Add(wxMakeFormNewLine()); -// } -// else -// Add(wxMakeFormBool(Filter->FltEvents[i].Name, &Filter->FltEvents[i].Selected, wxFORM_DEFAULT)); -// } - -// Add(wxMakeFormBool("Other", &Filter->OtherSelected)); -// } -// AssociatePanel(panel); + if (mpSong) + { + mFromClock = mpSong->StringToClock(FromTimeString); + } } - -bool tFilterDlg::OnClose() +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +void JZFilter::GenerateToTimeString(string& ToTimeString) const { - Filter->FromClock = FromClockDlg.GetClock(); - Filter->ToClock = ToClockDlg.GetClock(); - //wxForm::OnOk(); - return FALSE; + if (mpSong) + { + mpSong->ClockToString(mToClock, ToTimeString); + } } -void tFilterDlg::OnHelp() +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +void JZFilter::SetToTime(const string& ToTimeString) { - gpHelpInstance->ShowTopic("Filter"); + if (mpSong) + { + mToClock = mpSong->StringToClock(ToTimeString); + } } +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +int JZFilter::IsSelected(JZEvent* pEvent) +{ + int Value = pEvent->GetValue(); + for (int i = 0; i < eFilterCount; ++i) + { + if (pEvent->GetStat() == mFilterEvents[i].Stat) + { + // Aftertouch belongs to KeyOn events. + if (pEvent->GetStat() == StatKeyPressure) + { + int aval = pEvent->IsKeyPressure()->GetKey(); + return + mFilterEvents[i].Selected && + mFilterEvents[i].FromValue <= aval && + aval <= mFilterEvents[i].ToValue; + } + if (pEvent->GetStat() == StatTimeSignat) + { + return mFilterEvents[i].Selected; + } + if (pEvent->GetStat() == StatChnPressure) + { + return mFilterEvents[i].Selected; + } + if (pEvent->GetStat() == StatSysEx) + { + return mFilterEvents[i].Selected; + } + return + mFilterEvents[i].Selected && + mFilterEvents[i].FromValue <= Value && + Value <= mFilterEvents[i].ToValue; + } + } + return mOtherSelected; +} - - -void JZFilter::Dialog(wxFrame *parent, int ShowEventStats) +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +void JZFilter::Dialog(wxWindow* pParent) { - tFilterDlg *dlg; - // mpDialogBox = new wxDialogBox(parent, "Event Filter", FALSE ); - dlg = new tFilterDlg(this, mpSong, ShowEventStats); - dlg->Create(); -// dlg->EditForm(mpDialogBox, ShowEventStats); -// mpDialogBox->Fit(); -// mpDialogBox->Show(TRUE); + JZFilterDialog FilterDialog(*this, pParent); + if (FilterDialog.ShowModal() == wxID_OK) + { + } } - - - //***************************************************************************** // Description: // This is the track iterator class definition. @@ -207,7 +238,7 @@ //----------------------------------------------------------------------------- JZTrackIterator::JZTrackIterator(JZFilter* pFilter, bool Reverse) : mpFilter(pFilter), - mpSong(mpFilter->mpSong), + mpSong(mpFilter->GetSong()), mTrackIndex(0), mReverse(Reverse) { @@ -219,11 +250,11 @@ { if (mReverse) { - mTrackIndex = mpFilter->ToTrack; + mTrackIndex = mpFilter->GetToTrack(); } else { - mTrackIndex = mpFilter->FromTrack; + mTrackIndex = mpFilter->GetFromTrack(); } return mpSong->GetTrack(mTrackIndex); } @@ -235,7 +266,7 @@ if (mReverse) { --mTrackIndex; - if (mTrackIndex < mpFilter->FromTrack) + if (mTrackIndex < mpFilter->GetFromTrack()) { return 0; } @@ -243,7 +274,7 @@ else { ++mTrackIndex; - if (mTrackIndex > mpFilter->ToTrack) + if (mTrackIndex > mpFilter->GetToTrack()) { return 0; } @@ -255,5 +286,5 @@ //----------------------------------------------------------------------------- int JZTrackIterator::Count() const { - return mpFilter->ToTrack - mpFilter->FromTrack + 1; + return mpFilter->GetToTrack() - mpFilter->GetFromTrack() + 1; } Modified: trunk/jazz/src/Filter.h =================================================================== --- trunk/jazz/src/Filter.h 2009-01-01 03:14:00 UTC (rev 669) +++ trunk/jazz/src/Filter.h 2009-01-01 03:17:48 UTC (rev 670) @@ -28,26 +28,27 @@ class JZSong; class JZTrack; class wxDialog; -class wxFrame; +class wxWindow; -#define FltKeyOn 0 -#define FltKeyPressure 1 // SN++ PolyAftertouch gehoert to KeyOn Events! -#define FltControl 2 -#define FltProgram 3 -#define FltPitch 4 -#define FltTempo 5 -#define FltChnPressure 6 // SN++ Channel Aftertouch -#define FltSysEx 7 +//***************************************************************************** +//***************************************************************************** +enum TEFilterType +{ + eFilterKeyOn = 0, + eFilterKeyPressure = 1, // PolyAftertouch belongs to KeyOn Events. + eFilterControl = 2, + eFilterProgram = 3, + eFilterPitch = 4, + eFilterCount = 5 +}; -#define nFltEvents 8 - //***************************************************************************** //***************************************************************************** class JZFilterEvent { public: int Stat; - const char* Name; + const char* mName; bool Selected; int MinValue, MaxValue; int FromValue, ToValue; @@ -57,73 +58,87 @@ //***************************************************************************** class JZFilter : public wxObject { - friend class tFilterDlg; - wxDialog* mpDialogBox; - void copy(const JZFilter& Other); - public: - JZFilterEvent* FltEvents; - bool OtherSelected; + JZFilter(JZSong* pSong); + JZFilter(const JZFilter& Other); + + JZFilter& operator = (const JZFilter& Rhs); + + virtual ~JZFilter(); + + void GetFilterEvent( + TEFilterType FilterType, + bool& Selected, + int& FromValue, + int& ToValue); + + void SetFilterEvent( + TEFilterType FilterType, + bool Selected, + int FromValue, + int ToValue); + + void SetOtherSelected(bool OtherSelected); + + JZSong* GetSong() const; + + int GetFromClock() const; + void SetFromClock(int FromClock); + void GenerateFromTimeString(std::string& FromTimeString) const; + void SetFromTime(const std::string& FromTimeString); + + int GetToClock() const; + void SetToClock(int ToClock); + void GenerateToTimeString(std::string& ToTimeString) const; + void SetToTime(const std::string& ToTimeString); + + int GetFromTrack() const; + void SetFromTrack(int FromTrack); + + int GetToTrack() const; + void SetToTrack(int ToTrack); + + bool GetFilterMeter() const; + void SetFilterMeter(bool FilterMeter); + + bool GetFilterChannelAftertouch() const; + void SetFilterChannelAftertouch(bool FilterChannelAftertouch); + + bool GetFilterSysEx() const; + void SetFilterSysEx(bool FilterSysEx); + + bool GetFilterOther() const; + void SetFilterOther(bool FilterOther); + + int IsSelected(JZEvent* pEvent); + + void Dialog(wxWindow* pParent); + + private: + + JZFilterEvent* mFilterEvents; + + bool mOtherSelected; + JZSong* mpSong; - int FromClock, ToClock; // einschl .. ausschl + int mFromClock, mToClock; - int FromTrack, ToTrack; // 1..n einschl .. einschl + int mFromTrack, mToTrack; - void Dialog(wxFrame* parent, int ShowEventStats = 1); + bool mFilterMeter; - JZFilter(JZSong* pSong); - JZFilter(JZFilter* pOtherFilter); - JZFilter(const JZFilter& Other); - JZFilter& operator = (const JZFilter& Rhs); - virtual ~JZFilter(); + bool mFilterChannelAftertouch; - int IsSelected(JZEvent* pEvent) - { - int Value = pEvent->GetValue(); - for (int i = 0; i < nFltEvents; ++i) - { - if (pEvent->GetStat() == FltEvents[i].Stat) - { - // SN++ Aftertouch gehoert eigendlich zu KeyOn Events. - if (pEvent->GetStat() == StatKeyPressure) - { - int aval = pEvent->IsKeyPressure()->GetKey(); - return - FltEvents[i].Selected && - FltEvents[i].FromValue <= aval && - aval <= FltEvents[i].ToValue; - } - if (pEvent->GetStat() == StatTimeSignat) - { - return FltEvents[i].Selected; - } - // SN++ - if (pEvent->GetStat() == StatChnPressure) - { - return FltEvents[i].Selected; - } + bool mFilterSysEx; - if (pEvent->GetStat() == StatSysEx) - { - return FltEvents[i].Selected; - } + bool mFilterOther; - return - FltEvents[i].Selected && - FltEvents[i].FromValue <= Value && - Value <= FltEvents[i].ToValue; - } - } - return OtherSelected; - } + wxDialog* mpDialogBox; }; -// void GlobalFilterDlg(wxButton& but, wxMouseEvent& event); -// void GlobalFilterDlgNoStats(wxButton& but, wxMouseEvent& event); - //***************************************************************************** // Description: // This is the track iterator class declaration. @@ -145,4 +160,144 @@ bool mReverse; }; +//***************************************************************************** +// Description: +// These are the filter class inline member functions. +//***************************************************************************** +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +inline +JZSong* JZFilter::GetSong() const +{ + return mpSong; +} + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +inline +int JZFilter::GetFromClock() const +{ + return mFromClock; +} + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +inline +void JZFilter::SetFromClock(int FromClock) +{ + mFromClock = FromClock; +} + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +inline +int JZFilter::GetToClock() const +{ + return mToClock; +} + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +inline +void JZFilter::SetToClock(int ToClock) +{ + mToClock = ToClock; +} + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +inline +int JZFilter::GetFromTrack() const +{ + return mFromTrack; +} + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +inline +void JZFilter::SetFromTrack(int FromTrack) +{ + mFromTrack = FromTrack; +} + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +inline +int JZFilter::GetToTrack() const +{ + return mToTrack; +} + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +inline +void JZFilter::SetToTrack(int ToTrack) +{ + mToTrack = ToTrack; +} + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +inline +bool JZFilter::GetFilterMeter() const +{ + return mFilterMeter; +} + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +inline +void JZFilter::SetFilterMeter(bool FilterMeter) +{ + mFilterMeter = FilterMeter; +} + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +inline +bool JZFilter::GetFilterChannelAftertouch() const +{ + return mFilterChannelAftertouch; +} + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +inline +void JZFilter::SetFilterChannelAftertouch(bool FilterChannelAftertouch) +{ + mFilterChannelAftertouch = FilterChannelAftertouch; +} + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +inline +bool JZFilter::GetFilterSysEx() const +{ + return mFilterSysEx; +} + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +inline +void JZFilter::SetFilterSysEx(bool FilterSysEx) +{ + mFilterSysEx = FilterSysEx; +} + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +inline +bool JZFilter::GetFilterOther() const +{ + return mFilterOther; +} + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +inline +void JZFilter::SetFilterOther(bool FilterOther) +{ + mFilterOther = FilterOther; +} + #endif // !defined(JZ_FILTER_H) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |