From: <pst...@us...> - 2010-07-17 21:15:06
|
Revision: 810 http://jazzplusplus.svn.sourceforge.net/jazzplusplus/?rev=810&view=rev Author: pstieber Date: 2010-07-17 21:15:00 +0000 (Sat, 17 Jul 2010) Log Message: ----------- Separated the sample frame class into its own source and header files. Modified Paths: -------------- trunk/jazz/src/Audio.cpp trunk/jazz/src/Makefile.am trunk/jazz/src/SampleDialog.cpp trunk/jazz/src/SampleWindow.cpp trunk/jazz/src/SampleWindow.h trunk/jazz/vc9/JazzPlusPlus-VC9.vcproj Modified: trunk/jazz/src/Audio.cpp =================================================================== --- trunk/jazz/src/Audio.cpp 2010-07-17 20:17:47 UTC (rev 809) +++ trunk/jazz/src/Audio.cpp 2010-07-17 21:15:00 UTC (rev 810) @@ -34,7 +34,7 @@ #include "RecordingInfo.h" #include "Resources.h" #include "Sample.h" -#include "SampleWindow.h" +#include "SampleFrame.h" #include "StringReadWrite.h" #include "Track.h" #include "TrackFrame.h" Modified: trunk/jazz/src/Makefile.am =================================================================== --- trunk/jazz/src/Makefile.am 2010-07-17 20:17:47 UTC (rev 809) +++ trunk/jazz/src/Makefile.am 2010-07-17 21:15:00 UTC (rev 810) @@ -89,9 +89,10 @@ RecordingInfo.cpp \ Rectangle.cpp \ Rhythm.cpp \ +Sample.cpp \ SampleCommand.cpp \ -Sample.cpp \ SampleDialog.cpp \ +SampleFrame.cpp \ SampleWindow.cpp \ SelectControllerDialog.cpp \ Signal2.cpp \ @@ -188,9 +189,10 @@ RecordingInfo.cpp \ Rectangle.cpp \ Rhythm.cpp \ +Sample.cpp \ SampleCommand.cpp \ -Sample.cpp \ SampleDialog.cpp \ +SampleFrame.cpp \ SampleWindow.cpp \ SelectControllerDialog.cpp \ Signal2.cpp \ @@ -292,9 +294,10 @@ Rectangle.h \ Resources.h \ Rhythm.h \ +Sample.h \ SampleCommand.h \ SampleDialog.h \ -Sample.h \ +SampleFrame.h \ SampleWindow.h \ SelectControllerDialog.h \ Signal2.h \ Modified: trunk/jazz/src/SampleDialog.cpp =================================================================== --- trunk/jazz/src/SampleDialog.cpp 2010-07-17 20:17:47 UTC (rev 809) +++ trunk/jazz/src/SampleDialog.cpp 2010-07-17 21:15:00 UTC (rev 810) @@ -23,7 +23,7 @@ #include "SampleDialog.h" #include "Sample.h" -#include "SampleWindow.h" +#include "SampleFrame.h" #include "Mapper.h" #include "Audio.h" #include "SignalInterface.h" @@ -44,8 +44,10 @@ using namespace std; -JZCommandPainter::JZCommandPainter(JZSampleFrame &w, JZPaintableCommand &c) - : win(w), +JZCommandPainter::JZCommandPainter( + JZSampleFrame& SampleFrame, + JZPaintableCommand &c) + : win(SampleFrame), cmd(c) { c.Initialize(); @@ -104,11 +106,11 @@ int JZEqualizer::geo[4] = { 50, 80, 350, 200 }; -JZEqualizer::JZEqualizer(JZSampleFrame &w) - : JZSliderWindow(&w, "Equalizer", geo), +JZEqualizer::JZEqualizer(JZSampleFrame& SampleFrame) + : JZSliderWindow(&SampleFrame, "Equalizer", geo), array(12, -100, 100), - win(w), - spl(w.GetSample()) + win(SampleFrame), + spl(SampleFrame.GetSample()) { int i; channels = spl.GetChannelCount(); @@ -215,10 +217,10 @@ int JZDistortion::geo[4] = { 50, 80, 300, 320 }; -JZDistortion::JZDistortion(JZSampleFrame &w) -: JZSliderWindow(&w, "Distortion", geo), - arr(200, 0, 100), - win(w) +JZDistortion::JZDistortion(JZSampleFrame& SampleFrame) + : JZSliderWindow(&SampleFrame, "Distortion", geo), + arr(200, 0, 100), + win(SampleFrame) { N = 200; ymin = 0; @@ -320,7 +322,9 @@ { int fr, to; if (!win.HaveSelection(fr, to)) + { return; + } wxBeginBusyCursor(); JZSample &spl = win.GetSample(); @@ -491,9 +495,9 @@ }; -JZSynthDlg::JZSynthDlg(JZSampleFrame &w) -: JZSliderWindow(&w, "Additive Synthesis", geo, syn_tdefs), - win(w) +JZSynthDlg::JZSynthDlg(JZSampleFrame& SampleFrame) +: JZSliderWindow(&SampleFrame, "Additive Synthesis", geo, syn_tdefs), + win(SampleFrame) { Initialize(); default_filename = copystring("noname.syn"); @@ -902,9 +906,9 @@ int JZReverbForm::volume = 20; // effect volume int JZReverbForm::rvbtime = 30; // echo absorbtion -JZReverbForm::JZReverbForm(JZSampleFrame &w) +JZReverbForm::JZReverbForm(JZSampleFrame& SampleFrame) : wxForm( USED_WXFORM_BUTTONS ), - win(w) + win(SampleFrame) { } @@ -974,9 +978,9 @@ bool JZEchoForm::rand = false; -JZEchoForm::JZEchoForm(JZSampleFrame &w) -: wxForm( USED_WXFORM_BUTTONS ), - win(w) +JZEchoForm::JZEchoForm(JZSampleFrame& SampleFrame) + : wxForm(USED_WXFORM_BUTTONS), + win(SampleFrame) { wxForm::OnCancel(); } @@ -1019,9 +1023,9 @@ bool JZShifterForm::keep_length = 1; -JZShifterForm::JZShifterForm(JZSampleFrame &w) -: wxForm( USED_WXFORM_BUTTONS ), - win(w) +JZShifterForm::JZShifterForm(JZSampleFrame& SampleFrame) + : wxForm( USED_WXFORM_BUTTONS ), + win(SampleFrame) { } @@ -1119,12 +1123,19 @@ int JZSplFilterForm::lo_freq = 400; int JZSplFilterForm::hi_freq = 2000; int JZSplFilterForm::band_width = 20; // in % of corner freq -static const char *filter_types[] = { "Low Pass", "High Pass", "Band Pass", "Band Stop", 0 }; +static const char *filter_types[] = +{ + "Low Pass", + "High Pass", + "Band Pass", + "Band Stop", + 0 +}; -JZSplFilterForm::JZSplFilterForm(JZSampleFrame &w, bool p) -: wxForm( USED_WXFORM_BUTTONS ), - win(w) +JZSplFilterForm::JZSplFilterForm(JZSampleFrame& SampleFrame, bool p) + : wxForm( USED_WXFORM_BUTTONS ), + win(SampleFrame) { painter = p; } @@ -1231,9 +1242,11 @@ // filter painter settings // ------------------------------------------------------------------------- -JZWahSettingsForm::JZWahSettingsForm(JZSampleFrame &win, JZWahWah &w) - : JZSplFilterForm(win, true), - wah(w) +JZWahSettingsForm::JZWahSettingsForm( + JZSampleFrame& SampleFrame, + JZWahWah& WahWah) + : JZSplFilterForm(SampleFrame, true), + wah(WahWah) { type = (int)wah.filter_type; } @@ -1260,10 +1273,10 @@ int JZSplPitchForm::range = 1; -JZSplPitchForm::JZSplPitchForm(JZSampleFrame &w, JZSplPitch &p) -: wxForm( USED_WXFORM_BUTTONS ), - win(w), - pitch(p) +JZSplPitchForm::JZSplPitchForm(JZSampleFrame& SampleFrame, JZSplPitch& p) + : wxForm(USED_WXFORM_BUTTONS), + win(SampleFrame), + pitch(p) { } @@ -1302,9 +1315,9 @@ int JZChorusForm::pan_spread = 50; int JZChorusForm::volume = 50; -JZChorusForm::JZChorusForm(JZSampleFrame &w) -: wxForm( USED_WXFORM_BUTTONS ), - win(w) +JZChorusForm::JZChorusForm(JZSampleFrame& SampleFrame) + : wxForm( USED_WXFORM_BUTTONS ), + win(SampleFrame) { } @@ -1383,9 +1396,9 @@ int JZStereoForm::delay = 10; // millisec int JZStereoForm::stereo_spread = 50; -JZStereoForm::JZStereoForm(JZSampleFrame &w) -: wxForm( USED_WXFORM_BUTTONS ), - win(w) +JZStereoForm::JZStereoForm(JZSampleFrame& SampleFrame) + : wxForm(USED_WXFORM_BUTTONS), + win(SampleFrame) { } @@ -1444,10 +1457,10 @@ bool JZStretcherForm::keep_pitch = 1; -JZStretcherForm::JZStretcherForm(JZSampleFrame &w) -: wxForm( USED_WXFORM_BUTTONS ), - win(w), - spl(w.GetSample()) +JZStretcherForm::JZStretcherForm(JZSampleFrame& SampleFrame) + : wxForm( USED_WXFORM_BUTTONS ), + win(SampleFrame), + spl(SampleFrame.GetSample()) { } Modified: trunk/jazz/src/SampleWindow.cpp =================================================================== --- trunk/jazz/src/SampleWindow.cpp 2010-07-17 20:17:47 UTC (rev 809) +++ trunk/jazz/src/SampleWindow.cpp 2010-07-17 21:15:00 UTC (rev 810) @@ -22,161 +22,91 @@ #include "SampleWindow.h" -#include "Audio.h" -#include "FileSelector.h" -#include "Globals.h" -#include "Help.h" #include "Mapper.h" -#include "MouseAction.h" #include "Player.h" -#include "Resources.h" -#include "Rhythm.h" -#include "Sample.h" -#include "SampleCommand.h" -#include "SampleDialog.h" -#include "Song.h" -#include "SliderWindow.h" -#include "ToolBar.h" +#include "SampleFrame.h" #include <wx/dcclient.h> -#include <wx/menu.h> -#include <wx/msgdlg.h> -#include <wx/scrolbar.h> -//DEBUG#include <iostream> - -#define MEN_HELP 5 - -#define MEN_SILENCE 21 -#define MEN_SILENCE_INS 22 -#define MEN_SILENCE_APP 23 -#define MEN_SILENCE_OVR 24 - -#define MEN_ACCEPT 42 - -#define MEN_FLIP 56 -#define MEN_FLIP_LEFT 57 -#define MEN_FLIP_RIGHT 58 - -class JZSamplePlayPosition; - //***************************************************************************** //***************************************************************************** -class JZInsertionPoint +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +void JZInsertionPoint::Draw(int x) { - public: + last_x = x; + visible ^= 1; + wxDC *dc = new wxClientDC(mpScrolledWindow); + int cw, ch; + mpScrolledWindow->GetClientSize(&cw, &ch); + dc->SetPen(*wxRED_PEN); + dc->SetLogicalFunction(wxXOR); + dc->DrawLine(x, 0, x, ch); + dc->SetPen(*wxBLACK_PEN); + dc->SetLogicalFunction(wxCOPY); +} - JZInsertionPoint(wxScrolledWindow* pScrolledWindow) - : mpScrolledWindow(pScrolledWindow) - { - last_x = 0; - visible = 0; - } - - void Draw(int x) - { - last_x = x; - visible ^= 1; - wxDC *dc = new wxClientDC(mpScrolledWindow); - int cw, ch; - mpScrolledWindow->GetClientSize(&cw, &ch); - dc->SetPen(*wxRED_PEN); - dc->SetLogicalFunction(wxXOR); - dc->DrawLine(x, 0, x, ch); - dc->SetPen(*wxBLACK_PEN); - dc->SetLogicalFunction(wxCOPY); - } - - void Draw() - { - Draw(last_x); - } - - int IsVisible() const - { - return visible; - } - - float GetX() const - { - return last_x; - } - - private: - - int last_x; - int visible; - wxScrolledWindow* mpScrolledWindow; -}; - //***************************************************************************** //***************************************************************************** -class JZSampleWindow : public wxScrolledWindow +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +void JZSamplePlayPosition::StopListen() { - friend class JZSampleFrame; - friend class JZSmplWinSettingsForm; + Stop(); + if (gpMidiPlayer->IsListening()) + gpMidiPlayer->ListenAudio(-1); + if (visible) + Draw(); +} - public: +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +void JZSamplePlayPosition::StartListen(int fr, int to) +{ + fr_smpl = fr; + to_smpl = to; + gpMidiPlayer->ListenAudio(spl, fr_smpl, to_smpl); + Start(100); +} - JZSampleWindow(JZSampleFrame* pSampleFrame, JZSample& Sample); +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +bool JZSamplePlayPosition::IsListening() const +{ + return gpMidiPlayer->IsListening(); +} - virtual ~JZSampleWindow(); +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +void JZSamplePlayPosition::Draw() +{ + visible ^= 1; + wxDC *dc = new wxClientDC(&cnvs); + int cw, ch; + cnvs.GetClientSize(&cw, &ch); + dc->SetPen(*wxGREEN_PEN); + dc->SetLogicalFunction(wxXOR); + dc->DrawLine(x, 0, x, ch); + dc->SetPen(*wxBLACK_PEN); + dc->SetLogicalFunction(wxCOPY); +} - void Redraw() - { - OnPaint(); - } +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +void JZSamplePlayPosition::Notify() +{ + int pos = mpPlayer->GetListenerPlayPosition(); + if (pos < 0) + { + StopListen(); + return; + } + if (visible) + Draw(); + x = cnvs.Sample2Pixel(fr_smpl + pos); + Draw(); +} - virtual void OnPaint(); - - virtual void OnSize(int w, int h); - - virtual void OnEvent(wxMouseEvent& MouseEvent); - - void ClearSelection(); - - void SetInsertionPoint(int offs); - - void SetSelection(int fr, int to); - - int Sample2Pixel(int sample); - - int Pixel2Sample(float pixel); - - void Play(); - - private: - - void DrawSample(int channel, int x, int y, int w, int h); - - void DrawTicks(int x, int y, int w); - - private: - - JZSampleFrame* mpSampleFrame; - - JZSample& spl; - - int paint_offset; - int paint_length; - - JZSnapSelection snapsel; - - // sel_fr == 0: no selection and no insertion point - // sel_fr > 0 && sel_fr == sel_to: insertion point - // sel_fr > 0 && sel_fr < sel_to: selected range - int sel_fr, sel_to; - JZInsertionPoint inspt; - int mouse_up_sets_insertion_point; - JZSamplePlayPosition *playpos; - - // for tickmark display - bool midi_time; - int midi_offs; - - bool mouse_down; -}; - #ifdef OBSOLETE //***************************************************************************** //***************************************************************************** @@ -215,90 +145,6 @@ //***************************************************************************** //***************************************************************************** -class JZSamplePlayPosition : public wxTimer -{ - public: - - JZSamplePlayPosition( - JZSampleWindow& SampleWindow, - JZPlayer* pPlayer, - JZSample& Sample) - : cnvs(SampleWindow), - mpPlayer(pPlayer), - spl(Sample) - { - visible = false; - x = 0; - } - - ~JZSamplePlayPosition() - { - Stop(); - if (visible) - Draw(); - } - - void StopListen() - { - Stop(); - if (gpMidiPlayer->IsListening()) - gpMidiPlayer->ListenAudio(-1); - if (visible) - Draw(); - } - - void StartListen(int fr, int to) - { - fr_smpl = fr; - to_smpl = to; - gpMidiPlayer->ListenAudio(spl, fr_smpl, to_smpl); - Start(100); - } - - bool IsListening() const - { - return gpMidiPlayer->IsListening(); - } - - void Draw() - { - visible ^= 1; - wxDC *dc = new wxClientDC(&cnvs); - int cw, ch; - cnvs.GetClientSize(&cw, &ch); - dc->SetPen(*wxGREEN_PEN); - dc->SetLogicalFunction(wxXOR); - dc->DrawLine(x, 0, x, ch); - dc->SetPen(*wxBLACK_PEN); - dc->SetLogicalFunction(wxCOPY); - } - - virtual void Notify() - { - int pos = mpPlayer->GetListenerPlayPosition(); - if (pos < 0) - { - StopListen(); - return; - } - if (visible) - Draw(); - x = cnvs.Sample2Pixel(fr_smpl + pos); - Draw(); - } - - private: - JZSampleWindow& cnvs; - JZPlayer* mpPlayer; - JZSample& spl; - bool visible; - int x; - int fr_smpl; - int to_smpl; -}; - -//***************************************************************************** -//***************************************************************************** //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- JZSampleWindow::JZSampleWindow(JZSampleFrame* pSampleFrame, JZSample& Sample) @@ -565,13 +411,15 @@ BarInfo.SetBar(BarInfo.GetBarIndex()); while (BarInfo.GetClock() < cto) { - int ticks_per_count = BarInfo.GetTicksPerBar() / BarInfo.GetCountsPerBar(); + int ticks_per_count = + BarInfo.GetTicksPerBar() / BarInfo.GetCountsPerBar(); int ticks_per_step = ticks_per_count / 4; for (int i = 0; i < BarInfo.GetCountsPerBar(); ++i) { for (int j = 0; j < 4; j++) { - int clock = BarInfo.GetClock() + i * ticks_per_count + j * ticks_per_step; + int clock = + BarInfo.GetClock() + i * ticks_per_count + j * ticks_per_step; int xx = static_cast<int>(Map.XToY(clock)); // draw a tickmark line dc->DrawLine(xx, y - 5, xx, y); @@ -675,847 +523,3 @@ } -// ---------------------------------------------------------------- -// -------------------------- JZSampleFrame -------------------------- -// ---------------------------------------------------------------- - - -#include "Bitmaps/open.xpm" -#include "Bitmaps/save.xpm" -#include "Bitmaps/play.xpm" -#include "Bitmaps/help.xpm" -#include "Bitmaps/accept.xpm" -#include "Bitmaps/cancel.xpm" -#include "Bitmaps/zoomin.xpm" -#include "Bitmaps/zoomout.xpm" - -static JZToolDef tdefs[] = -{ - { wxID_OPEN, false, open_xpm, "open wave file" }, - { wxID_SAVE, false, save_xpm, "save wave file" }, - { JZToolBar::eToolBarSeparator }, - { wxID_ZOOM_IN, false, zoomin_xpm, "zoom to selection" }, - { wxID_ZOOM_OUT, false, zoomout_xpm, "zoom out" }, - { MEN_ACCEPT, false, accept_xpm, "accept painting" }, - { ID_PAINTER_NONE, false, cancel_xpm, "cancel painting" }, - { JZToolBar::eToolBarSeparator }, - { ID_PLAY, false, play_xpm, "play sample" }, - { MEN_HELP, false, help_xpm, "help" }, - { JZToolBar::eToolBarEnd } -}; - -int JZSampleFrame::geo[4] = -{ - 30, - 30, - 600, - 300 -}; - -JZSample *JZSampleFrame::copy_buffer; - -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -JZSampleFrame::JZSampleFrame( - wxWindow* pParent, - JZSampleFrame **ref, - JZSample& Sample) - : wxFrame( - pParent, - wxID_ANY, - Sample.GetFileName(), - wxPoint(geo[0], geo[1]), - wxSize(geo[2], geo[3])), - spl(Sample), - vol_command(Sample), - pan_command(Sample), - pitch_command(Sample), - wah_command(Sample) -{ - this->ref = ref; - - in_constructor = true; - - cnvs = 0; - mpToolBar = 0; - scrol_panel = 0; - pos_scrol = 0; - zoom_scrol = 0; - num_params = 0; - on_accept = 0; - equalizer = 0; - distortion = 0; - reverb = 0; - echo = 0; - shifter = 0; - stretcher = 0; - filter = 0; - settings = 0; - wah_settings = 0; - pitch_settings = 0; - chorus = 0; - synth = 0; - - if (copy_buffer == 0) - copy_buffer = new JZSample(spl.SampleSet()); - - mpToolBar = new JZToolBar(this, tdefs); - - // Create a menu bar, the various menus with entries, and attach them to the - // menu bar. - - wxMenu* pMenu = 0; - wxMenu* pSubMenu = 0; - wxMenuBar* pMenuBar = new wxMenuBar; - - // Create and populate the File menu. - pMenu = new wxMenu; - - pMenu->Append(ID_FILE_REVERT_TO_SAVED, "&Revert to Saved"); - pMenu->Append(wxID_OPEN, "&Load..."); - pMenu->Append(wxID_SAVE, "&Save"); - pMenu->Append(wxID_SAVEAS, "&Save As..."); - pMenu->Append(wxID_CLOSE, "&Close"); - - pMenuBar->Append(pMenu, "&File"); - - // Create and populate the Edit menu. - pMenu = new wxMenu; - pMenu->Append(wxID_CUT, "&Cut"); - pMenu->Append(wxID_COPY, "Co&py"); - pMenu->Append(wxID_PASTE, "&Paste"); - pMenu->Append(ID_EDIT_PASTE_MERGE, "Paste &Merge"); - pSubMenu = new wxMenu; - pSubMenu->Append(MEN_SILENCE_OVR, "&Replace"); - pSubMenu->Append(MEN_SILENCE_INS, "&Insert"); - pSubMenu->Append(MEN_SILENCE_APP, "&Append"); - pMenu->Append(MEN_SILENCE, "&Silence", pSubMenu); - pSubMenu = new wxMenu; - pSubMenu->Append(MEN_FLIP_LEFT, "Left"); - pSubMenu->Append(MEN_FLIP_RIGHT, "Right"); - pMenu->Append(MEN_FLIP, "In&vert Phase", pSubMenu); - pMenu->Append(ID_EDIT_MAXIMIZE_VOLUME, "&Maximize Volume"); - pMenuBar->Append(pMenu, "&Edit"); - - pMenu = new wxMenu; - pMenu->Append(ID_PAINTERS_VOLUME, "&Volume..."); - pMenu->Append(ID_PAINTER_PAN, "&Panpot..."); - pMenu->Append(ID_PAINTER_PITCH, "&Pitch..."); - pMenu->Append(ID_PAINTER_WAHWAH, "&Filter..."); - pMenu->Append(ID_PAINTER_NONE, "&None..."); - pMenuBar->Append(pMenu, "&Painters"); - - pMenu = new wxMenu; - pMenu->Append(ID_EFFECTS_EQUALIZER, "&Equalizer..."); - pMenu->Append(ID_EFFECTS_FILTER, "&Filter..."); - pMenu->Append(ID_EFFECTS_DISTORTION, "&Distortion..."); - pMenu->Append(ID_EFFECTS_REVERB, "&Reverb..."); - pMenu->Append(ID_EFFECTS_ECHO, "&Echo..."); - pMenu->Append(ID_EFFECTS_CHORUS, "&Chorus..."); - pMenu->Append(ID_EFFECTS_PITCH_SHIFTER, "&Pitch shifter..."); - pMenu->Append(ID_EFFECTS_STRETCHER, "&Time stretcher..."); - pMenu->Append(ID_EFFECTS_REVERSE, "Re&verse"); - pMenu->Append(ID_EFFECTS_SYNTH, "&Synth..."); - pMenuBar->Append(pMenu, "&Effects"); - - pMenu = new wxMenu; - pMenu->Append(ID_SETTINGS_PITCH_PAINTER, "&Pitch Painter..."); - pMenu->Append(ID_SETTINGS_WAHWAH, "&Filter Painter..."); -// pMenu->Append(wxID_ZOOM_IN, "Zoom &In"); -// pMenu->Append(wxID_ZOOM_OUT, "Zoom &Out"); - pMenu->Append(ID_VIEW_SETTINGS, "&View Settings..."); - pMenuBar->Append(pMenu, "&Settings"); - - SetMenuBar(pMenuBar); - - // construct a panel containing the scrollbars - cnvs = new JZSampleWindow(this, spl); - scrol_panel = new wxPanel(this); - -//OBSOLETE pos_scrol = new wxScrollBar(scrol_panel, (wxFunction)ScrollCallback); - pos_scrol = new wxScrollBar(scrol_panel, wxID_ANY); -// pos_scrol->SetObjectLength(1000); -// pos_scrol->SetViewLength(1000); -// pos_scrol->SetValue(0); - pos_scrol->SetScrollbar(0, 1000, 1000, 1000); - -//OBSOLETE zoom_scrol = new wxScrollBar(scrol_panel, (wxFunction)ScrollCallback); - zoom_scrol = new wxScrollBar(scrol_panel, wxID_ANY); -// zoom_scrol->SetObjectLength(1000); -// zoom_scrol->SetViewLength(10); -// zoom_scrol->SetPageLength(100); -// zoom_scrol->SetValue(0); - zoom_scrol->SetScrollbar(0, 10, 1000, 100); - - in_constructor = false; - - // now force a resize for motif - int cw, ch; - GetClientSize(&cw, &ch); - OnSize(cw, ch); -} - -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -JZSampleFrame::~JZSampleFrame() -{ - *ref = 0; - GetPosition(&geo[0], &geo[1]); - GetSize(&geo[2], &geo[3]); - delete mpToolBar; - delete cnvs; - delete zoom_scrol; - delete pos_scrol; - delete scrol_panel; - for (int i = 0; i < num_params; i++) - delete params[i]; - delete equalizer; - delete distortion; - delete reverb; - delete echo; - delete chorus; - delete synth; - delete shifter; - delete stretcher; - delete filter; - delete settings; - delete wah_settings; - delete pitch_settings; -} - -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -bool JZSampleFrame::OnClose() -{ - return true; -} - -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -void JZSampleFrame::OnSize(int w, int h) -{ - // constructor finished? - if (in_constructor) - return; - - int cw, ch; - GetClientSize(&cw, &ch); - - wxSize ToolBarSize = mpToolBar->GetSize(); - int pw, ph; - pos_scrol->GetSize(&pw, &ph); - int zw, zh; - zoom_scrol->GetSize(&zw, &zh); - -//OBSOLETE mpToolBar->SetSize(0, 0, (int)cw, ToolBarSize.GetHeight()); - scrol_panel->SetSize(0, ch-zh-ph, cw, zh+ph); - zoom_scrol->SetSize(0, 0, cw, zh); - pos_scrol->SetSize(0, zh, cw, ph); - - // divide the remaining space on cnvs and params - int xx = 0; - int yy = ToolBarSize.GetHeight(); - int ww = cw; - int hh = ch - ToolBarSize.GetHeight() - zh - ph; - int nn = spl.GetChannelCount() + num_params; - - int hi = hh * spl.GetChannelCount() / nn; - cnvs->SetSize(xx, yy, ww, hi); - - hi = hh / nn; - for (int i = 0; i < num_params; i++) - { - int yi = yy + (i + spl.GetChannelCount()) * hh / nn; - params[i]->SetSize(xx, yi, ww, hi); - } -} - -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -void JZSampleFrame::Redraw() -{ - cnvs->Redraw(); -} - -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -bool JZSampleFrame::HaveInsertionPoint(int &offs, bool warn) -{ - if (cnvs->sel_fr == cnvs->sel_to && cnvs->sel_fr >= 0) - { - offs = cnvs->sel_fr; - return true; - } - else - { - offs = -1; - if (warn) - wxMessageBox("please set insertion point first", "Error", wxOK); - return false; - } -} - -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -bool JZSampleFrame::HaveSelection( - int& fr_smpl, - int& to_smpl, - HaveSelectionMode mode) -{ - if (cnvs->sel_fr < cnvs->sel_to && cnvs->sel_fr >= 0) - { - fr_smpl = cnvs->sel_fr; - to_smpl = cnvs->sel_to; - return true; - } - else if (mode == SelAll) - { - fr_smpl = 0; - to_smpl = spl.GetLength(); - return true; - } - fr_smpl = to_smpl = -1; - if (mode == SelWarn) - wxMessageBox("please select samples first", "Error", wxOK); - return false; -} - -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -void JZSampleFrame::AddParam(JZRndArray *array, const char *label) -{ - params[num_params] = new JZArrayEdit(this, *array, 0, 0, 10, 10, 0); - params[num_params]->SetLabel(label); - num_params++; - int cw, ch; - GetClientSize(&cw, &ch); - OnSize(cw, ch); -} - -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -void JZSampleFrame::ClrParam() -{ - if (num_params > 0) - { - int n = num_params; - num_params = 0; - for (int i = 0; i < n; ++i) - { - delete params[i]; - } - int cw, ch; - GetClientSize(&cw, &ch); - OnSize(cw, ch); - } -} - -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -void JZSampleFrame::ClearSelection() -{ - cnvs->ClearSelection(); -} - -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -void JZSampleFrame::LoadError(JZSample& Sample) -{ - wxString Message; - Message << "Could not load " << Sample.GetFileName(); - ::wxMessageBox(Message, "Error", wxOK); -} - -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -extern int effect(JZSample &spl); - -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -void JZSampleFrame::OnMenuCommand(int id) -{ - if (gpMidiPlayer->IsPlaying()) - { - return; - } - - // Player crashes if data disappear. - if (id != ID_PLAY) - { - cnvs->playpos->StopListen(); - } - - switch (id) - { - case ID_EFFECTS_EQUALIZER: - if (equalizer == 0) - equalizer = new JZEqualizer(*this); - equalizer->Show(true); - break; - - case MEN_FLIP_LEFT: - spl.Flip(0); - break; - case MEN_FLIP_RIGHT: - spl.Flip(1); - break; - - case ID_EFFECTS_DISTORTION: - if (distortion == 0) - distortion = new JZDistortion(*this); - distortion->Show(true); - break; - - case ID_EFFECTS_REVERB: -#ifdef OBSOLETE - if (reverb == 0) - { - // Old version was not modal. - reverb = new wxDialog(this, wxID_ANY, "Reverb"); - tReverbForm *form = new tReverbForm(*this); - form->EditForm(reverb); - reverb->Fit(); - } - ClearSelection(); - SetViewPos(0, spl.GetLength()); - reverb->Show(true); -#endif - break; - - case ID_EFFECTS_REVERSE: - { - int fr, to; - if (HaveSelection(fr, to)) - { - spl.Reverse(fr, to); - Redraw(); - } - } - break; - - case ID_EFFECTS_PITCH_SHIFTER: -#ifdef OBSOLETE - if (shifter == 0) - { - shifter = new wxDialogBox(this, "Shifter", false ); - tShifterForm *form = new tShifterForm(*this); - form->EditForm(shifter); - shifter->Fit(); - } - ClearSelection(); - SetViewPos(0, spl.GetLength()); - shifter->Show(true); -#endif - break; - - case ID_EFFECTS_STRETCHER: -#ifdef OBSOLETE - if (stretcher == 0) - { - stretcher = new wxDialogBox(this, "Stretcher", false ); - tStretcherForm *form = new tStretcherForm(*this); - form->EditForm(stretcher); - stretcher->Fit(); - } - ClearSelection(); - SetViewPos(0, spl.GetLength()); - stretcher->Show(true); -#endif - break; - - case ID_EFFECTS_FILTER: -#ifdef OBSOLETE - if (filter == 0) - { - filter = new wxDialogBox(this, "Filter", false ); - tSplFilterForm *form = new tSplFilterForm(*this); - form->EditForm(filter); - filter->Fit(); - } - filter->Show(true); -#endif - break; - - case ID_VIEW_SETTINGS: -#ifdef OBSOLETE - if (settings == 0) - { - settings = new wxDialogBox(this, "Settings", false ); - JZSmplWinSettingsForm *form = new JZSmplWinSettingsForm(*this); - form->EditForm(settings); - settings->Fit(); - } - settings->Show(true); -#endif - break; - - case ID_EFFECTS_ECHO: -#ifdef OBSOLETE - if (echo == 0) - { - echo = new wxDialogBox(this, "Echo", false ); - tEchoForm *form = new tEchoForm(*this); - form->EditForm(echo); - echo->Fit(); - } - ClearSelection(); - SetViewPos(0, spl.GetLength()); - echo->Show(true); -#endif - break; - - case ID_EFFECTS_CHORUS: -#ifdef OBSOLETE - if (chorus == 0) - { - chorus = new wxDialogBox(this, "Chorus", false ); - tChorusForm *form = new tChorusForm(*this); - form->EditForm(chorus); - chorus->Fit(); - } - ClearSelection(); - SetViewPos(0, spl.GetLength()); - chorus->Show(true); -#endif - break; - - case ID_EFFECTS_SYNTH: - if (synth == 0) - synth = new JZSynthDlg(*this); - synth->Show(true); - break; - - case MEN_ACCEPT: - if (on_accept) - { - int fr = GetPaintOffset(); - int to = fr + GetPaintLength(); - on_accept->OnAccept(fr, to); - delete on_accept; - on_accept = 0; - } - break; - - case ID_PAINTER_NONE: - if (on_accept) - { - delete on_accept; - on_accept = 0; - } - break; - - case wxID_CUT: - { - int fr, to; - if (HaveSelection(fr, to, SelWarn)) - { - spl.Cut(*copy_buffer, fr, to); - cnvs->ClearSelection(); - cnvs->SetInsertionPoint(fr); - Redraw(); - } - } - break; - - case wxID_COPY: - { - int fr, to; - if (HaveSelection(fr, to, SelAll)) - spl.Copy(*copy_buffer, fr, to); - } - break; - - case wxID_ZOOM_IN: - { - int fr, to; - if (HaveSelection(fr, to, SelWarn)) - SetViewPos(fr, to); - } - break; - - case wxID_ZOOM_OUT: - SetViewPos(0, spl.GetLength()); - break; - - case ID_EDIT_MAXIMIZE_VOLUME: - spl.Rescale(); - Redraw(); - break; - - case ID_PAINTERS_VOLUME: - delete on_accept; - on_accept = new JZCommandPainter(*this, vol_command); - break; - - case ID_PAINTER_WAHWAH: - delete on_accept; - on_accept = new JZCommandPainter(*this, wah_command); - break; - - case ID_SETTINGS_WAHWAH: -#ifdef OBSOLETE - if (wah_settings == 0) - { - wah_settings = new wxDialogBox(this, "Filter Painter", false); - tWahSettingsForm *form = new tWahSettingsForm(*this); - form->EditForm(wah_settings); - wah_settings->Fit(); - } - wah_settings->Show(true); -#endif - break; - - case ID_SETTINGS_PITCH_PAINTER: -#ifdef OBSOLETE - if (pitch_settings == 0) - { - pitch_settings = new wxDialogBox(this, "Pitch Painter"); - tSplPitchForm *form = new tSplPitchForm(*this); - form->EditForm(pitch_settings); - pitch_settings->Fit(); - } - pitch_settings->Show(true); -#endif - break; - - - case ID_PAINTER_PAN: - delete on_accept; - on_accept = new JZCommandPainter(*this, pan_command); - break; - - case ID_EDIT_PASTE_MERGE: - { - int offs; - if (HaveInsertionPoint(offs)) - { - spl.PasteMix(*copy_buffer, offs); - cnvs->SetSelection(offs, offs + copy_buffer->GetLength()); - Redraw(); - } - } - break; - - case wxID_PASTE: - { - int offs, fr, to; - if (HaveInsertionPoint(offs, false)) - { - spl.PasteIns(*copy_buffer, offs); - cnvs->SetSelection(offs, offs + copy_buffer->GetLength()); - Redraw(); - } - else if (HaveSelection(fr, to, SelWarn)) - { - spl.PasteOvr(*copy_buffer, fr, to); - cnvs->SetInsertionPoint(fr); - Redraw(); - } - } - break; - - case MEN_SILENCE_INS: - { - int fr, to; - if (HaveSelection(fr, to, SelWarn)) - { - spl.InsertSilence(fr, to - fr); - Redraw(); - } - } - break; - - case MEN_SILENCE_APP: - { - int fr, to; - if (HaveSelection(fr, to, SelWarn)) - { - spl.InsertSilence(to, to - fr); - Redraw(); - } - } - break; - - case MEN_SILENCE_OVR: - { - int fr, to; - if (HaveSelection(fr, to, SelWarn)) - { - spl.ReplaceSilence(fr, to - fr); - Redraw(); - } - } - break; - - case ID_PAINTER_PITCH: - delete on_accept; - SetViewPos(0, spl.GetLength()); - on_accept = new JZCommandPainter(*this, pitch_command); - break; - - case ID_FILE_REVERT_TO_SAVED: - cnvs->ClearSelection(); - if (spl.Load(true)) - LoadError(spl); - Redraw(); - break; - - case wxID_CLOSE: -// DELETE_THIS(); - Destroy(); - break; - - case ID_PLAY: - cnvs->Play(); - break; - - case wxID_OPEN: - { - wxString FileName = file_selector( - spl.GetFileName(), - "Load Sample", - false, - false, - "*.wav"); - if (!FileName.empty()) - { - wxBeginBusyCursor(); - cnvs->ClearSelection(); - spl.SetFileName(FileName); - if (spl.Load(true)) - { - LoadError(spl); - } - spl->RefreshDialogs(); - SetTitle(FileName); - Redraw(); - wxEndBusyCursor(); - } - } - break; - - case wxID_SAVEAS: - { - wxString FileName = file_selector( - spl.GetFileName(), - "Save Sample", - true, - false, - "*.wav"); - if (!FileName.empty()) - { - spl.SetFileName(FileName); - OnMenuCommand(wxID_SAVE); - spl->RefreshDialogs(); - SetTitle(FileName); - } - } - break; - - case wxID_SAVE: - { - if (spl.GetFileName().empty()) - { - OnMenuCommand(wxID_SAVEAS); - } - else - { - wxBeginBusyCursor(); - cnvs->ClearSelection(); - int err = spl.Save(); - Redraw(); - wxEndBusyCursor(); - if (err) - { - wxMessageBox("writing failed!!", "Error", wxOK); - } - } - } - break; - - case MEN_HELP: - gpHelpInstance->ShowTopic("Sample Editor"); - break; - - default: - break; - } -} - -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -void JZSampleFrame::PlaySample() -{ - cnvs->Play(); -} - -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -int JZSampleFrame::GetPaintLength() -{ - // return the visible amount of sample data - double sb = zoom_scrol->GetThumbPosition(); - JZMapper Map(0, 1000, spl.GetLength(), 0); - int len = static_cast<int>(Map.XToY(sb)); - return spl.Align(len); -} - -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -int JZSampleFrame::GetPaintOffset() -{ - // return the visible Offset in sample data - double sb = pos_scrol->GetThumbPosition(); - JZMapper Map(0, 1000, 0, spl.GetLength()); - int ofs = static_cast<int>(Map.XToY(sb)); - return spl.Align(ofs); -} - -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -void JZSampleFrame::SetViewPos(int fr, int to) -{ - JZMapper Map(0, spl.GetLength(), 0, 1000); - int zval = 1000 - (int)Map.XToY(to - fr); - zoom_scrol->SetThumbPosition(zval); - - int pval = (int)Map.XToY(fr); - if (pval > zval) - pval = zval; - - // avoid motif warnings: by setting a very small length, - // every position is valid. -// pos_scrol->SetViewLength(1); -// pos_scrol->SetValue(pval); -// pos_scrol->SetViewLength(1000 - zval); -// pos_scrol->SetPageLength((1000 - zval) * 2 / 3); - pos_scrol->SetScrollbar(pval, 1, 1000 - zval, (1000 - zval) * 2 / 3); - - Redraw(); -} - -#ifdef OBSOLETE -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -void JZSampleFrame::OnScroll(wxItem &item) -{ - int zval = zoom_scrol->GetValue(); - int pval = pos_scrol->GetValue(); - - if (pval > zval) - pval = zval; - - pos_scrol->SetValue(pval); - pos_scrol->SetViewLength(1000 - zval); - pos_scrol->SetPageLength((1000 - zval) * 2 / 3); - - Redraw(); -} - -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -void JZSampleFrame::ScrollCallback(wxItem &itm, wxCommandEvent& Event) -{ - ((JZSampleFrame *)(itm.GetParent()->GetParent()))->OnScroll(itm); -} -#endif Modified: trunk/jazz/src/SampleWindow.h =================================================================== --- trunk/jazz/src/SampleWindow.h 2010-07-17 20:17:47 UTC (rev 809) +++ trunk/jazz/src/SampleWindow.h 2010-07-17 21:15:00 UTC (rev 810) @@ -23,106 +23,163 @@ #ifndef JZ_SAMPLEWINDOW_H #define JZ_SAMPLEWINDOW_H -#include "SampleCommand.h" +#include "MouseAction.h" -#include <wx/frame.h> +#include <wx/scrolwin.h> -class JZRndArray; -class JZToolBar; -class JZArrayEdit; -class JZCommandPainter; -class JZDistortion; -class JZEqualizer; +class JZPlayer; class JZSample; +class JZSampleFrame; class JZSampleWindow; -class JZSynthDlg; -class wxDialog; -class wxScrollBar; //***************************************************************************** //***************************************************************************** -class JZSampleFrame : public wxFrame +class JZInsertionPoint { - friend class JZSampleWindow; - friend class JZCommandPainter; - friend class JZSmplWinSettingsForm; + public: + JZInsertionPoint(wxScrolledWindow* pScrolledWindow) + : mpScrolledWindow(pScrolledWindow) + { + last_x = 0; + visible = 0; + } + + void Draw(int x); + + void Draw() + { + Draw(last_x); + } + + int IsVisible() const + { + return visible; + } + + float GetX() const + { + return last_x; + } + + private: + + int last_x; + int visible; + wxScrolledWindow* mpScrolledWindow; +}; + +//***************************************************************************** +//***************************************************************************** +class JZSamplePlayPosition : public wxTimer +{ public: - JZSampleFrame(wxWindow* pParent, JZSampleFrame** ref, JZSample& Sample); - ~JZSampleFrame(); - virtual void OnSize(int w, int h); - virtual bool OnClose(); - virtual void OnMenuCommand(int id); - void Redraw(); - bool HaveInsertionPoint(int &offs, bool warn = TRUE); - enum HaveSelectionMode + JZSamplePlayPosition( + JZSampleWindow& SampleWindow, + JZPlayer* pPlayer, + JZSample& Sample) + : cnvs(SampleWindow), + mpPlayer(pPlayer), + spl(Sample) { - SelWarn, - SelNoWarn, - SelAll - }; - bool HaveSelection(int &fr_smpl, int &to_smpl, HaveSelectionMode = SelAll); + visible = false; + x = 0; + } - void AddParam(JZRndArray *array, const char *label); - void ClrParam(); - void ClearSelection(); - JZSample &GetSample() + ~JZSamplePlayPosition() { - return spl; + Stop(); + if (visible) + Draw(); } - void PlaySample(); + void StopListen(); + + void StartListen(int fr, int to); + + bool IsListening() const; + + void Draw(); + + virtual void Notify(); + private: + JZSampleWindow& cnvs; + JZPlayer* mpPlayer; + JZSample& spl; + bool visible; + int x; + int fr_smpl; + int to_smpl; +}; - int GetPaintLength(); - int GetPaintOffset(); -#ifdef OBSOLETE - static void ScrollCallback(wxItem &itm, wxCommandEvent& event); - void OnScroll(wxItem &item); -#endif - void SetViewPos(int fr, int to); - void LoadError(JZSample &spl); +//***************************************************************************** +//***************************************************************************** +class JZSampleWindow : public wxScrolledWindow +{ + friend class JZSampleFrame; + friend class JZSmplWinSettingsForm; + public: + + JZSampleWindow(JZSampleFrame* pSampleFrame, JZSample& Sample); + + virtual ~JZSampleWindow(); + + void Redraw() + { + OnPaint(); + } + + virtual void OnPaint(); + + virtual void OnSize(int w, int h); + + virtual void OnEvent(wxMouseEvent& MouseEvent); + + void ClearSelection(); + + void SetInsertionPoint(int offs); + + void SetSelection(int fr, int to); + + int Sample2Pixel(int sample); + + int Pixel2Sample(float pixel); + + void Play(); + private: + void DrawSample(int channel, int x, int y, int w, int h); + + void DrawTicks(int x, int y, int w); + + private: + + JZSampleFrame* mpSampleFrame; + JZSample& spl; - JZSampleWindow* cnvs; - wxPanel* scrol_panel; - wxScrollBar* pos_scrol; - wxScrollBar* zoom_scrol; - JZToolBar* mpToolBar; - int in_constructor; - JZSampleFrame** ref; - static int geo[4]; - static JZSample* copy_buffer; + int paint_offset; + int paint_length; - enum - { - MAXPARAM = 4 - }; - JZArrayEdit* params[MAXPARAM]; - int num_params; + JZSnapSelection snapsel; - JZCommandPainter* on_accept; - JZSplVolume vol_command; - JZSplPan pan_command; - JZSplPitch pitch_command; - JZWahWah wah_command; + // sel_fr == 0: no selection and no insertion point + // sel_fr > 0 && sel_fr == sel_to: insertion point + // sel_fr > 0 && sel_fr < sel_to: selected range + int sel_fr, sel_to; + JZInsertionPoint inspt; + int mouse_up_sets_insertion_point; + JZSamplePlayPosition *playpos; - JZEqualizer* equalizer; - JZDistortion* distortion; - JZSynthDlg* synth; - wxDialog* reverb; - wxDialog* echo; - wxDialog* chorus; - wxDialog* shifter; - wxDialog* stretcher; - wxDialog* filter; - wxDialog* settings; - wxDialog* wah_settings; - wxDialog* pitch_settings; + // for tickmark display + bool midi_time; + int midi_offs; + + bool mouse_down; }; #endif // !defined(JZ_SAMPLEWINDOW_H) Modified: trunk/jazz/vc9/JazzPlusPlus-VC9.vcproj =================================================================== --- trunk/jazz/vc9/JazzPlusPlus-VC9.vcproj 2010-07-17 20:17:47 UTC (rev 809) +++ trunk/jazz/vc9/JazzPlusPlus-VC9.vcproj 2010-07-17 21:15:00 UTC (rev 810) @@ -938,6 +938,14 @@ > </File> <File + RelativePath="..\src\SampleFrame.cpp" + > + </File> + <File + RelativePath="..\src\SampleFrame.h" + > + </File> + <File RelativePath="..\src\SampleWindow.cpp" > </File> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |