From: <pst...@us...> - 2013-04-07 16:29:22
|
Revision: 1010 http://sourceforge.net/p/jazzplusplus/code/1010 Author: pstieber Date: 2013-04-07 16:29:20 +0000 (Sun, 07 Apr 2013) Log Message: ----------- Added the ability to open a rhythm file. Modified Paths: -------------- trunk/jazz/src/Rhythm.cpp trunk/jazz/src/Rhythm.h Modified: trunk/jazz/src/Rhythm.cpp =================================================================== --- trunk/jazz/src/Rhythm.cpp 2013-04-07 16:14:28 UTC (rev 1009) +++ trunk/jazz/src/Rhythm.cpp 2013-04-07 16:29:20 UTC (rev 1010) @@ -353,8 +353,9 @@ } } - #if 0 +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- void JZRhythm::Generate(JZTrack* pTrack, int FromClock, int ToClock, int TicksPerBar) { int chan = pTrack->Channel - 1; @@ -545,7 +546,6 @@ } //***************************************************************************** -// JZRhythmWindow //***************************************************************************** //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- @@ -789,7 +789,6 @@ //----------------------------------------------------------------------------- void JZRhythmWindow::OnSize(int w, int h) { - // wxFrame::OnSize(w, h); if (mpToolBar) { int cw, ch; @@ -1530,13 +1529,7 @@ //----------------------------------------------------------------------------- JZRhythmGeneratorWindow::~JZRhythmGeneratorWindow() { - for ( - vector<JZRhythm*>::iterator iInstrument = mInstruments.begin(); - iInstrument != mInstruments.end(); - ++iInstrument) - { - delete *iInstrument; - } + ClearInstruments(); } //----------------------------------------------------------------------------- @@ -1675,6 +1668,45 @@ //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- +void JZRhythmGeneratorWindow::Read(istream& Is) +{ + int Version; + Is >> Version; + if (Version > 2) + { + wxMessageBox("Wrong file format!", "Error", wxOK); + } + + ClearInstruments(); + + size_t InstrumentCount; + Is >> InstrumentCount; + for (size_t i = 0; i < InstrumentCount; ++i) + { + JZRhythm* pRhythm = new JZRhythm(0); + pRhythm->Read(Is, Version); + AddInstrument(pRhythm); + } + + Refresh(); +} + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +void JZRhythmGeneratorWindow::ClearInstruments() +{ + for ( + vector<JZRhythm*>::iterator iInstrument = mInstruments.begin(); + iInstrument != mInstruments.end(); + ++iInstrument) + { + delete *iInstrument; + } + mInstruments.clear(); +} + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- void JZRhythmGeneratorWindow::AddInstrument(JZRhythm* pRhythm) { mInstruments.push_back(pRhythm); @@ -1813,6 +1845,8 @@ //----------------------------------------------------------------------------- BEGIN_EVENT_TABLE(JZRhythmGeneratorFrame, wxFrame) + EVT_MENU(wxID_OPEN, JZRhythmGeneratorFrame::OnOpen) + EVT_MENU(ID_INSTRUMENT_ADD, JZRhythmGeneratorFrame::OnAddInstrument) EVT_MENU(ID_INSTRUMENT_DELETE, JZRhythmGeneratorFrame::OnDeleteInstrument) @@ -1825,6 +1859,10 @@ //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- +const wxString JZRhythmGeneratorFrame::mDefaultFileName = "noname.rhy"; + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- JZRhythmGeneratorFrame::JZRhythmGeneratorFrame() : wxFrame( 0, @@ -1906,6 +1944,27 @@ //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- +void JZRhythmGeneratorFrame::OnOpen(wxCommandEvent&) +{ + bool HasChanged = false; + wxString FileName = file_selector( + mDefaultFileName, + "Load Rhythm", + false, + HasChanged, + "*.rhy"); + if (!FileName.empty()) + { + ifstream Is(FileName.mb_str()); + if (Is) + { + mpRhythmGeneratorWindow->Read(Is); + } + } +} + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- void JZRhythmGeneratorFrame::OnAddInstrument(wxCommandEvent&) { mpRhythmGeneratorWindow->AddInstrument(); Modified: trunk/jazz/src/Rhythm.h =================================================================== --- trunk/jazz/src/Rhythm.h 2013-04-07 16:14:28 UTC (rev 1009) +++ trunk/jazz/src/Rhythm.h 2013-04-07 16:29:20 UTC (rev 1010) @@ -265,12 +265,16 @@ virtual ~JZRhythmGeneratorWindow(); + void Read(std::istream& Is); + void AddInstrument(); void DeleteInstrument(); private: + void ClearInstruments(); + void AddInstrument(JZRhythm* pRhythm); void Instrument2Win(); @@ -322,6 +326,8 @@ void CreateToolBar(); + void OnOpen(wxCommandEvent& Event); + void OnAddInstrument(wxCommandEvent& Event); void OnDeleteInstrument(wxCommandEvent& Event); @@ -332,6 +338,8 @@ private: + static const wxString mDefaultFileName; + JZToolBar* mpToolBar; JZRhythmGeneratorWindow* mpRhythmGeneratorWindow; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |