Where is my "render loop"?

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
idontknow
In need of some credit
In need of some credit
Posts: 2
Joined: Sun Jun 10, 2018 11:54 am

Where is my "render loop"?

Post by idontknow »

wxMain.cpp

Code: Select all

#include "wx_pch.h"
#include "wxMCIMain.h"
#include <wx/msgdlg.h>
#include <mciplayer.h>
#include <windows.h>

//(*InternalHeaders(wxMCIFrame)
#include <wx/intl.h>
#include <wx/string.h>
//*)

//helper functions
enum wxbuildinfoformat {
    short_f, long_f };

wxString wxbuildinfo(wxbuildinfoformat format)
{
    wxString wxbuild(wxVERSION_STRING);

    if (format == long_f )
    {
#if defined(__WXMSW__)
        wxbuild << _T("-Windows");
#elif defined(__UNIX__)
        wxbuild << _T("-Linux");
#endif

#if wxUSE_UNICODE
        wxbuild << _T("-Unicode build");
#else
        wxbuild << _T("-ANSI build");
#endif // wxUSE_UNICODE
    }

    return wxbuild;
}
mciplayer test;
//(*IdInit(wxMCIFrame)
const long wxMCIFrame::ID_FILEPICKERCTRL1 = wxNewId();
const long wxMCIFrame::ID_BUTTON1 = wxNewId();
const long wxMCIFrame::ID_BUTTON2 = wxNewId();
const long wxMCIFrame::ID_BUTTON3 = wxNewId();
const long wxMCIFrame::ID_BUTTON4 = wxNewId();
const long wxMCIFrame::ID_SLIDER1 = wxNewId();
const long wxMCIFrame::ID_SLIDER2 = wxNewId();
const long wxMCIFrame::ID_TEXTCTRL1 = wxNewId();
const long wxMCIFrame::ID_PANEL1 = wxNewId();
const long wxMCIFrame::idMenuQuit = wxNewId();
const long wxMCIFrame::idMenuAbout = wxNewId();
const long wxMCIFrame::ID_STATUSBAR1 = wxNewId();
//*)

BEGIN_EVENT_TABLE(wxMCIFrame,wxFrame)
    //(*EventTable(wxMCIFrame)
    //*)
END_EVENT_TABLE()

wxMCIFrame::wxMCIFrame(wxWindow* parent,wxWindowID id)
{
    //(*Initialize(wxMCIFrame)
    wxBoxSizer* BoxSizer1;
    wxGridSizer* GridSizer1;
    wxMenu* Menu1;
    wxMenu* Menu2;
    wxMenuBar* MenuBar1;
    wxMenuItem* MenuItem1;
    wxMenuItem* MenuItem2;

    Create(parent, id, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE, _T("id"));
    SetClientSize(wxSize(1354,194));
    BoxSizer1 = new wxBoxSizer(wxHORIZONTAL);
    Panel1 = new wxPanel(this, ID_PANEL1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, _T("ID_PANEL1"));
    GridSizer1 = new wxGridSizer(2, 7, 0, 0);
    FilePickerCtrl1 = new wxFilePickerCtrl(Panel1, ID_FILEPICKERCTRL1, wxEmptyString, wxEmptyString, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxFLP_FILE_MUST_EXIST|wxFLP_OPEN|wxFLP_USE_TEXTCTRL, wxDefaultValidator, _T("ID_FILEPICKERCTRL1"));
    GridSizer1->Add(FilePickerCtrl1, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    Button1 = new wxButton(Panel1, ID_BUTTON1, _("Play"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON1"));
    GridSizer1->Add(Button1, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    Button2 = new wxButton(Panel1, ID_BUTTON2, _("Pause"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON2"));
    GridSizer1->Add(Button2, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    Button3 = new wxButton(Panel1, ID_BUTTON3, _("Resume"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON3"));
    GridSizer1->Add(Button3, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    Button4 = new wxButton(Panel1, ID_BUTTON4, _("n2"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON4"));
    GridSizer1->Add(Button4, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    Slider1 = new wxSlider(Panel1, ID_SLIDER1, 0, 0, 1000, wxDefaultPosition, wxSize(182,24), 0, wxDefaultValidator, _T("ID_SLIDER1"));
    GridSizer1->Add(Slider1, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    Slider2 = new wxSlider(Panel1, ID_SLIDER2, 0, 0, 2000, wxDefaultPosition, wxSize(150,24), 0, wxDefaultValidator, _T("ID_SLIDER2"));
    GridSizer1->Add(Slider2, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    TextCtrl1 = new wxTextCtrl(Panel1, ID_TEXTCTRL1, _("Text"), wxDefaultPosition, wxSize(196,21), 0, wxDefaultValidator, _T("ID_TEXTCTRL1"));
    GridSizer1->Add(TextCtrl1, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    Panel1->SetSizer(GridSizer1);
    GridSizer1->Fit(Panel1);
    GridSizer1->SetSizeHints(Panel1);
    BoxSizer1->Add(Panel1, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    SetSizer(BoxSizer1);
    MenuBar1 = new wxMenuBar();
    Menu1 = new wxMenu();
    MenuItem1 = new wxMenuItem(Menu1, idMenuQuit, _("Quit\tAlt-F4"), _("Quit the application"), wxITEM_NORMAL);
    Menu1->Append(MenuItem1);
    MenuBar1->Append(Menu1, _("&File"));
    Menu2 = new wxMenu();
    MenuItem2 = new wxMenuItem(Menu2, idMenuAbout, _("About\tF1"), _("Show info about this application"), wxITEM_NORMAL);
    Menu2->Append(MenuItem2);
    MenuBar1->Append(Menu2, _("Help"));
    SetMenuBar(MenuBar1);
    StatusBar1 = new wxStatusBar(this, ID_STATUSBAR1, 0, _T("ID_STATUSBAR1"));
    int __wxStatusBarWidths_1[1] = { -1 };
    int __wxStatusBarStyles_1[1] = { wxSB_NORMAL };
    StatusBar1->SetFieldsCount(1,__wxStatusBarWidths_1);
    StatusBar1->SetStatusStyles(1,__wxStatusBarStyles_1);
    SetStatusBar(StatusBar1);
    SetSizer(BoxSizer1);
    Layout();

    Connect(ID_FILEPICKERCTRL1,wxEVT_COMMAND_FILEPICKER_CHANGED,(wxObjectEventFunction)&wxMCIFrame::Filechange);
    Connect(ID_BUTTON1,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&wxMCIFrame::Play);
    Connect(ID_BUTTON2,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&wxMCIFrame::Pause);
    Connect(ID_BUTTON3,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&wxMCIFrame::Resume);
    Connect(ID_BUTTON4,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&wxMCIFrame::n2);
    Connect(ID_SLIDER1,wxEVT_COMMAND_SLIDER_UPDATED,(wxObjectEventFunction)&wxMCIFrame::OnSlider1CmdScrollChanged);
    Connect(ID_SLIDER2,wxEVT_COMMAND_SLIDER_UPDATED,(wxObjectEventFunction)&wxMCIFrame::OnSlider2CmdSliderUpdated);
    Connect(idMenuQuit,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&wxMCIFrame::OnQuit);
    Connect(idMenuAbout,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&wxMCIFrame::OnAbout);
    //*)

}

wxMCIFrame::~wxMCIFrame()
{
    //(*Destroy(wxMCIFrame)
    //*)
}


void wxMCIFrame::OnQuit(wxCommandEvent& event)
{
    Close();
}

void wxMCIFrame::OnAbout(wxCommandEvent& event)
{
    wxString msg = wxbuildinfo(long_f);
    wxMessageBox(msg, _("Welcome to..."));
}

void wxMCIFrame::Play(wxCommandEvent& event)
{
mciplayer *tr=&test;
tr->close("song1");
tr->open("song1");
tr->play("song1");
tr->getduration();
Slider3->SetMax(tr->getduration());


}

void wxMCIFrame::Pause(wxCommandEvent& event)
{

    mciplayer *tr=&test;

tr->pause("song1");
}

void wxMCIFrame::Resume(wxCommandEvent& event)
{
    mciplayer *tr=&test;

tr->resume("song1");

}

void wxMCIFrame::n2(wxCommandEvent& event)
{
mciplayer *tr=&test;
cout <<tr->getposition("song1")<<endl;
string cas = tr->tostring((tr->getposition("song1")/1000)/60)+":"+tr->tostring((tr->getposition("song1")/1000)%60);
TextCtrl1->SetValue(cas.c_str());

}

void wxMCIFrame::Filechange(wxFileDirPickerEvent& event)
{
    mciplayer *tr=&test;
    tr->close("song1");
    wxString res = FilePickerCtrl1->GetPath();
    tr->pathget(tr->tostring(res));


}

void wxMCIFrame::OnSlider1CmdScrollChanged(wxScrollEvent& event)
{
    int volume = Slider1->GetValue();
    mciplayer *tr=&test;
    tr->setvolume("song1",volume);
}

void wxMCIFrame::OnSlider2CmdSliderUpdated(wxScrollEvent& event)
{

   int speed = Slider2->GetValue();

   mciplayer *tr=&test;
    tr->setspeed("song1",speed);
}






void wxMCIFrame::position(wxScrollEvent& event)
{
     mciplayer *tr=&test;
tr->setposition("song1",Slider3->GetValue()*1000);
string cas = tr->tostring(Slider3->GetValue()/60)+":"+tr->tostring(Slider3->GetValue()%60);
TextCtrl1->SetValue(cas.c_str());
}
wxMain.h

Code: Select all

#ifndef WXMCIMAIN_H
#define WXMCIMAIN_H
#include <mciplayer.h>
//(*Headers(wxMCIFrame)
#include <wx/button.h>
#include <wx/filepicker.h>
#include <wx/frame.h>
#include <wx/menu.h>
#include <wx/panel.h>
#include <wx/sizer.h>
#include <wx/slider.h>
#include <wx/statusbr.h>
#include <wx/textctrl.h>
//*)

class wxMCIFrame: public wxFrame
{
    public:


        wxMCIFrame(wxWindow* parent,wxWindowID id = -1);
        virtual ~wxMCIFrame();
mciplayer test;
    private:

        //(*Handlers(wxMCIFrame)
        void OnQuit(wxCommandEvent& event);
        void OnAbout(wxCommandEvent& event);
        void Play(wxCommandEvent& event);
        void Pause(wxCommandEvent& event);
        void Resume(wxCommandEvent& event);
        void n2(wxCommandEvent& event);
        void Filechange(wxFileDirPickerEvent& event);
        void OnSlider1CmdScrollChanged(wxScrollEvent& event);
        void OnSlider2CmdSliderUpdated(wxScrollEvent& event);
        void OnSlider3CmdSliderUpdated(wxScrollEvent& event);
        void OnSlider3CmdScroll(wxScrollEvent& event);
        void OnSlider3CmdScroll1(wxScrollEvent& event);
        void position(wxScrollEvent& event);
        void OnPaint(wxPaintEvent& event);
        
        //*)

        //(*Identifiers(wxMCIFrame)
        static const long ID_FILEPICKERCTRL1;
        static const long ID_BUTTON1;
        static const long ID_BUTTON2;
        static const long ID_BUTTON3;
        static const long ID_BUTTON4;
        static const long ID_SLIDER1;
        static const long ID_SLIDER2;
        static const long ID_TEXTCTRL1;
        static const long ID_PANEL1;
        static const long idMenuQuit;
        static const long idMenuAbout;
        static const long ID_STATUSBAR1;
        //*)

        //(*Declarations(wxMCIFrame)
        wxButton* Button1;
        wxButton* Button2;
        wxButton* Button3;
        wxButton* Button4;
        wxFilePickerCtrl* FilePickerCtrl1;
        wxPanel* Panel1;
        wxSlider* Slider1;
        wxSlider* Slider2;
        wxStatusBar* StatusBar1;
        wxTextCtrl* TextCtrl1;
        //*)

        DECLARE_EVENT_TABLE()
};

#endif // WXMCIMAIN_H
wxApp.cpp

Code: Select all

#include "wx_pch.h"
#include "wxMCIApp.h"

//(*AppHeaders
#include "wxMCIMain.h"
#include <wx/image.h>
//*)

IMPLEMENT_APP(wxMCIApp);

bool wxMCIApp::OnInit()
{

    //(*AppInitialize
    bool wxsOK = true;
    wxInitAllImageHandlers();
    if ( wxsOK )
    {

    	wxMCIFrame* Frame = new wxMCIFrame(0);
    	Frame->Show();

    	SetTopWindow(Frame);

    }
    //*)
    return wxsOK;}
    
wxApp.h

Code: Select all

#ifndef WXMCIAPP_H
#define WXMCIAPP_H

#include <wx/app.h>

class wxMCIApp : public wxApp
{
    public:
        virtual bool OnInit();
};

#endif // WXMCIAPP_H
I am using CB with wxSmith plugin, but i need to refresh position of audio play. I thank you for your every answer and your time.
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Where is my "render loop"?

Post by doublemax »

There is no classical render loop in wxWidgets.

For your purpose, use a wxTimer: http://docs.wxwidgets.org/trunk/classwx_timer.html
Use the source, Luke!
Post Reply