Skip to content

Commit

Permalink
lenmus#283 WIP - code, tutorials and samples updated
Browse files Browse the repository at this point in the history
  • Loading branch information
cecilios committed Jan 9, 2021
1 parent 98920a8 commit e8c19cb
Show file tree
Hide file tree
Showing 33 changed files with 642 additions and 626 deletions.
Binary file modified examples/samples/drawlines/drawlines
Binary file not shown.
21 changes: 10 additions & 11 deletions examples/samples/drawlines/drawlines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,14 +380,9 @@ void MyCanvas::open_test_document()
Document::k_format_ldp
);

//get the pointer to the interactor, set the rendering buffer and
//register for receiving desired events
//get the pointer to the interactor and register to receive desired events
if (SpInteractor spInteractor = m_pPresenter->get_interactor(0).lock())
{
//connect the View with the window buffer
spInteractor->set_rendering_buffer(&m_rbuf_window);

//register to receive desired events
spInteractor->add_event_handler(k_update_window_event, this, wrapper_update_window);
}
}
Expand Down Expand Up @@ -451,19 +446,23 @@ void MyCanvas::delete_rendering_buffer()
void MyCanvas::create_rendering_buffer(int width, int height)
{
//allocate memory for the Lomse rendering buffer.
//Any existing buffer is automatically deleted by Lomse.

#define BYTES_PER_PIXEL 4 //the chosen format is RGBA, 32 bits

// allocate a new rendering buffer
//delete current buffer
delete_rendering_buffer();

// allocate a new rendering buffer
m_nBufWidth = width;
m_nBufHeight = height;
m_pdata = (unsigned char*)malloc(m_nBufWidth * m_nBufHeight * BYTES_PER_PIXEL);

//Attach this memory to be used as Lomse rendering buffer
int stride = m_nBufWidth * BYTES_PER_PIXEL; //number of bytes per row
m_rbuf_window.attach(m_pdata, m_nBufWidth, m_nBufHeight, stride);
//use this memory as Lomse rendering buffer
if (m_pPresenter)
{
if (SpInteractor spInteractor = m_pPresenter->get_interactor(0).lock())
spInteractor->set_rendering_buffer(m_pdata, m_nBufWidth, m_nBufHeight);
}

m_view_needs_redraw = true;
}
Expand Down
8 changes: 2 additions & 6 deletions examples/samples/drawlines/drawlines.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,8 @@ class MyCanvas : public QWidget
LomseDoorway& m_lomse; //the Lomse library doorway
Presenter* m_pPresenter;

//the Lomse View renders its content on a bitmap. To manage it, Lomse
//associates the bitmap to a RenderingBuffer object.
//It is your responsibility to render the bitmap on a window.
//Here you define the rendering buffer and its associated memory
//for this View
RenderingBuffer m_rbuf_window;
//the Lomse View renders its content on a bitmap. We define here the
//memory area to be used to create the bitmap
unsigned char* m_pdata; //ptr to the bitmap
int m_nBufWidth, m_nBufHeight; //size of the bitmap

Expand Down
45 changes: 17 additions & 28 deletions examples/samples/extplayer/extplayer-wx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ typedef void (wxEvtHandler::*UpdateViewportEventFunction)(MyUpdateViewportEvent&
#define MY_EVT_UPDATE_VIEWPORT(fn) \
DECLARE_EVENT_TABLE_ENTRY( MY_EVT_UPDATE_VIEWPORT_TYPE, wxID_ANY, -1, \
(wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) \
wxStaticCastEvent( UpdateViewportEventFunction, & fn ), (wxObject *) NULL ),
wxStaticCastEvent( UpdateViewportEventFunction, & fn ), (wxObject *) nullptr ),



Expand Down Expand Up @@ -195,16 +195,9 @@ class MyCanvas : public wxWindow
LomseDoorway& m_lomse; //the Lomse library doorway
Presenter* m_pPresenter;

//the Lomse View renders its content on a bitmap. To manage it, Lomse
//associates the bitmap to a RenderingBuffer object.
//It is your responsibility to render the bitmap on a window.
//Here you define the rendering buffer and its associated bitmap to be
//used by the previously defined View.
RenderingBuffer m_rbuf_window;
//the Lomse View renders its content on a bitmap.
//Here we define the wxImage to be used as rendering buffer
wxImage* m_buffer; //the image to serve as buffer
unsigned char* m_pdata; //ptr to the bitmap
int m_nBufWidth, m_nBufHeight; //size of the bitmap


//some additinal variables
bool m_view_needs_redraw; //to control when the View must be re-drawn
Expand Down Expand Up @@ -298,7 +291,7 @@ END_EVENT_TABLE()

//---------------------------------------------------------------------------------------
MyFrame::MyFrame()
: wxFrame(NULL, wxID_ANY, _T("Lomse sample for wxWidgets"),
: wxFrame(nullptr, wxID_ANY, _T("Lomse sample for wxWidgets"),
wxDefaultPosition, wxSize(850, 600))
{
create_menu();
Expand Down Expand Up @@ -465,8 +458,8 @@ END_EVENT_TABLE()
MyCanvas::MyCanvas(wxFrame *frame, LomseDoorway& lomse)
: wxWindow(frame, wxID_ANY)
, m_lomse(lomse)
, m_pPresenter(NULL)
, m_buffer(NULL)
, m_pPresenter(nullptr)
, m_buffer(nullptr)
, m_view_needs_redraw(true)
, m_playbackTimer(this, k_id_tempo_line_timer)
, m_nBeatTime(1000) //1000 milliseconds = 1 sec.
Expand Down Expand Up @@ -527,22 +520,22 @@ void MyCanvas::delete_rendering_buffer()
//---------------------------------------------------------------------------------------
void MyCanvas::create_rendering_buffer(int width, int height)
{
//creates a bitmap of specified size and associates it to the rendering
//buffer for the view. Any existing buffer is automatically deleted
//creates a bitmap of specified size and defines it s the rendering
//buffer for the view.

delete_rendering_buffer();

// allocate a new rendering buffer
delete_rendering_buffer();
m_nBufWidth = width;
m_nBufHeight = height;
m_buffer = new wxImage(width, height);

//get pointer to wxImage internal bitmap
m_pdata = m_buffer->GetData();
unsigned char* pdata = m_buffer->GetData();

//Attach this bitmap to Lomse rendering buffer
#define BYTES_PER_PIXEL 3 //wxImage has RGB, 24 bits format
int stride = m_nBufWidth * BYTES_PER_PIXEL; //number of bytes per row
m_rbuf_window.attach(m_pdata, m_nBufWidth, m_nBufHeight, stride);
//use this bitmap as Lomse rendering buffer
if (SpInteractor spInteractor = m_pPresenter->get_interactor(0).lock())
{
spInteractor->set_rendering_buffer(pdata, width, height);
}

m_view_needs_redraw = true;
}
Expand Down Expand Up @@ -646,13 +639,9 @@ void MyCanvas::open_test_document()
")))",
Document::k_format_ldp);

//get the pointer to the interactor, set the rendering buffer and register for
//receiving desired events
//get the pointer to the interactor and register to receive desired events
if (SpInteractor spInteractor = m_pPresenter->get_interactor(0).lock())
{
//connect the View with the window buffer
spInteractor->set_rendering_buffer(&m_rbuf_window);

//ask to receive desired events
spInteractor->add_event_handler(k_update_window_event, this, wrapper_update_window);

Expand Down
2 changes: 1 addition & 1 deletion examples/samples/transpose/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ This sample shows how to use edition commands for transposing an score.
When running the sample, use the mouse for selecting the desired notes or the whole score (drag a rectangle around the desired area), and then select the transposition options from main menu.


## Building for wxWidgets
## Building in Linux for wxWidgets

```
g++ -std=c++11 transpose-wx.cpp -o transpose-wx `pkg-config --cflags liblomse` `wx-config --cflags` `pkg-config --libs liblomse` `wx-config --libs` -lstdc++
Expand Down
81 changes: 34 additions & 47 deletions examples/samples/transpose/transpose-wx.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//---------------------------------------------------------------------------------------
// This file is part of the Lomse library.
// Lomse is copyrighted work (c) 2010-2019. All rights reserved.
// Lomse is copyrighted work (c) 2010-2021. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
Expand Down Expand Up @@ -171,16 +171,9 @@ class MyCanvas : public wxWindow
LomseDoorway& m_lomse; //the Lomse library doorway
Presenter* m_pPresenter;

//the Lomse View renders its content on a bitmap. To manage it, Lomse
//associates the bitmap to a RenderingBuffer object.
//It is your responsibility to render the bitmap on a window.
//Here you define the rendering buffer and its associated bitmap to be
//used by the previously defined View.
RenderingBuffer m_rbuf_window;
//the Lomse View renders its content on a bitmap.
//Here we define the wxImage to be used as rendering buffer
wxImage* m_buffer; //the image to serve as buffer
unsigned char* m_pdata; //ptr to the bitmap
int m_nBufWidth, m_nBufHeight; //size of the bitmap


//some additinal variables
bool m_view_needs_redraw; //to control when the View must be re-drawn
Expand Down Expand Up @@ -316,7 +309,7 @@ END_EVENT_TABLE()

//---------------------------------------------------------------------------------------
MyFrame::MyFrame()
: wxFrame(NULL, wxID_ANY, _T("Lomse sample for wxWidgets"),
: wxFrame(nullptr, wxID_ANY, _T("Lomse sample for wxWidgets"),
wxDefaultPosition, wxSize(850, 600))
{
create_menu();
Expand Down Expand Up @@ -493,8 +486,8 @@ END_EVENT_TABLE()
MyCanvas::MyCanvas(wxFrame *frame, LomseDoorway& lomse)
: wxWindow(frame, wxID_ANY)
, m_lomse(lomse)
, m_pPresenter(NULL)
, m_buffer(NULL)
, m_pPresenter(nullptr)
, m_buffer(nullptr)
, m_view_needs_redraw(true)
{
}
Expand All @@ -518,17 +511,14 @@ void MyCanvas::open_file(const wxString& fullname)
m_pPresenter = m_lomse.open_document(k_view_vertical_book,
filename);

//get the pointer to the interactor, set the rendering buffer, register for
//receiving desired events and enable edition
//get the pointer to the interactor, register to receive desired events and
//enable edition
if (SpInteractor spIntor = m_pPresenter->get_interactor(0).lock())
{
//connect the View with the window buffer
spIntor->set_rendering_buffer(&m_rbuf_window);

//ask to receive desired events
spIntor->add_event_handler(k_update_window_event, this, wrapper_update_window);

//set in edition mode
//set edition mode
spIntor->set_operating_mode(Interactor::k_mode_edition);
}

Expand Down Expand Up @@ -577,22 +567,22 @@ void MyCanvas::delete_rendering_buffer()
//---------------------------------------------------------------------------------------
void MyCanvas::create_rendering_buffer(int width, int height)
{
//creates a bitmap of specified size and associates it to the rendering
//buffer for the view. Any existing buffer is automatically deleted
//creates a bitmap of specified size and defines it s the rendering
//buffer for the view.

delete_rendering_buffer();

// allocate a new rendering buffer
delete_rendering_buffer();
m_nBufWidth = width;
m_nBufHeight = height;
m_buffer = new wxImage(width, height);

//get pointer to wxImage internal bitmap
m_pdata = m_buffer->GetData();
unsigned char* pdata = m_buffer->GetData();

//Attach this bitmap to Lomse rendering buffer
#define BYTES_PER_PIXEL 3 //wxImage has RGB, 24 bits format
int stride = m_nBufWidth * BYTES_PER_PIXEL; //number of bytes per row
m_rbuf_window.attach(m_pdata, m_nBufWidth, m_nBufHeight, stride);
//use this bitmap as Lomse rendering buffer
if (SpInteractor spInteractor = m_pPresenter->get_interactor(0).lock())
{
spInteractor->set_rendering_buffer(pdata, width, height);
}

m_view_needs_redraw = true;
}
Expand All @@ -619,17 +609,14 @@ void MyCanvas::open_test_document()
")))",
Document::k_format_ldp);

//get the pointer to the interactor, set the rendering buffer, register for
//receiving desired events and enable edition
//get the pointer to the interactor, register to receive desired events
//and enable edition
if (SpInteractor spIntor = m_pPresenter->get_interactor(0).lock())
{
//connect the View with the window buffer
spIntor->set_rendering_buffer(&m_rbuf_window);

//ask to receive desired events
spIntor->add_event_handler(k_update_window_event, this, wrapper_update_window);

//set in edition mode
//set edition mode
spIntor->set_operating_mode(Interactor::k_mode_edition);
}

Expand Down Expand Up @@ -1012,9 +999,9 @@ DlgTransposeNotes::DlgTransposeNotes(wxWindow* parent, FIntval* interval, int* s
DlgTransposeNotes::~DlgTransposeNotes()
{
// Disconnect Events
m_radMethod->Disconnect( wxEVT_COMMAND_RADIOBOX_SELECTED, wxCommandEventHandler( DlgTransposeNotes::on_method_changed ), NULL, this );
m_btnOk->Disconnect( wxEVT_LEFT_DOWN, wxMouseEventHandler( DlgTransposeNotes::on_ok ), NULL, this );
m_btnCancel->Disconnect( wxEVT_LEFT_DOWN, wxMouseEventHandler( DlgTransposeNotes::on_cancel ), NULL, this );
m_radMethod->Disconnect( wxEVT_COMMAND_RADIOBOX_SELECTED, wxCommandEventHandler( DlgTransposeNotes::on_method_changed ), nullptr, this );
m_btnOk->Disconnect( wxEVT_LEFT_DOWN, wxMouseEventHandler( DlgTransposeNotes::on_ok ), nullptr, this );
m_btnCancel->Disconnect( wxEVT_LEFT_DOWN, wxMouseEventHandler( DlgTransposeNotes::on_cancel ), nullptr, this );
}

//---------------------------------------------------------------------------------------
Expand All @@ -1040,7 +1027,7 @@ void DlgTransposeNotes::create_controls()
wxStaticBoxSizer* szrInterval;
szrInterval = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Interval ") ), wxVERTICAL );

m_cboInterval = new wxComboBox( szrInterval->GetStaticBox(), wxID_ANY, _("Unison"), wxDefaultPosition, wxDefaultSize, 0, NULL, 0 );
m_cboInterval = new wxComboBox( szrInterval->GetStaticBox(), wxID_ANY, _("Unison"), wxDefaultPosition, wxDefaultSize, 0, nullptr, 0 );
szrInterval->Add( m_cboInterval, 0, wxALL|wxALIGN_CENTER_VERTICAL|wxEXPAND, 5 );


Expand Down Expand Up @@ -1072,9 +1059,9 @@ void DlgTransposeNotes::create_controls()
this->Centre( wxBOTH );

// Connect Events
m_radMethod->Connect( wxEVT_COMMAND_RADIOBOX_SELECTED, wxCommandEventHandler( DlgTransposeNotes::on_method_changed ), NULL, this );
m_btnOk->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( DlgTransposeNotes::on_ok ), NULL, this );
m_btnCancel->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( DlgTransposeNotes::on_cancel ), NULL, this );
m_radMethod->Connect( wxEVT_COMMAND_RADIOBOX_SELECTED, wxCommandEventHandler( DlgTransposeNotes::on_method_changed ), nullptr, this );
m_btnOk->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( DlgTransposeNotes::on_ok ), nullptr, this );
m_btnCancel->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( DlgTransposeNotes::on_cancel ), nullptr, this );
}

//---------------------------------------------------------------------------------------
Expand Down Expand Up @@ -1199,8 +1186,8 @@ DlgTransposeKey::DlgTransposeKey(wxWindow* parent, EKeySignature oldKey,
DlgTransposeKey::~DlgTransposeKey()
{
// Disconnect Events
m_btnOk->Disconnect( wxEVT_LEFT_DOWN, wxMouseEventHandler( DlgTransposeKey::on_ok ), NULL, this );
m_btnCancel->Disconnect( wxEVT_LEFT_DOWN, wxMouseEventHandler( DlgTransposeKey::on_cancel ), NULL, this );
m_btnOk->Disconnect( wxEVT_LEFT_DOWN, wxMouseEventHandler( DlgTransposeKey::on_ok ), nullptr, this );
m_btnCancel->Disconnect( wxEVT_LEFT_DOWN, wxMouseEventHandler( DlgTransposeKey::on_cancel ), nullptr, this );

}

Expand All @@ -1221,7 +1208,7 @@ void DlgTransposeKey::create_controls()
wxStaticBoxSizer* szrNewKey;
szrNewKey = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("New key signature") ), wxVERTICAL );

m_cboKeySignature = new wxComboBox( szrNewKey->GetStaticBox(), wxID_ANY, "", wxDefaultPosition, wxSize( 200,-1 ), 0, NULL, 0 );
m_cboKeySignature = new wxComboBox( szrNewKey->GetStaticBox(), wxID_ANY, "", wxDefaultPosition, wxSize( 200,-1 ), 0, nullptr, 0 );
szrNewKey->Add( m_cboKeySignature, 0, wxALL|wxALIGN_CENTER_VERTICAL|wxEXPAND, 5 );


Expand Down Expand Up @@ -1253,8 +1240,8 @@ void DlgTransposeKey::create_controls()
this->Centre( wxBOTH );

// Connect Events
m_btnOk->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( DlgTransposeKey::on_ok ), NULL, this );
m_btnCancel->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( DlgTransposeKey::on_cancel ), NULL, this );
m_btnOk->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( DlgTransposeKey::on_ok ), nullptr, this );
m_btnCancel->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( DlgTransposeKey::on_cancel ), nullptr, this );
}

//---------------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion examples/samples/viewtypes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
This sample is a test for displaying and playing back scores using the different Lomse View types.


## Building for wxWidgets
## Building in Linux for wxWidgets

```
g++ -std=c++11 viewtypes-wx.cpp ../../tutorials/wxMidi/wxMidi.cpp ../../tutorials/wxMidi/wxMidiDatabase.cpp -o viewtypes `pkg-config --cflags liblomse` `wx-config --cflags` -I ../../tutorials/wxMidi/ `pkg-config --libs liblomse` `wx-config --libs` -lstdc++ -lportmidi -lporttime
Expand Down
Loading

0 comments on commit e8c19cb

Please sign in to comment.