How to remove trailing effect when drawing on a panel? Topic is solved

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.
User avatar
doublemax
Moderator
Moderator
Posts: 19158
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to remove trailing effect when drawing on a panel?

Post by doublemax »

You don't need the wxStaticBitmap.

Your paint event handler should look something like this:

Code: Select all

void MainFrame::OnPaintPlayhead(wxPaintEvent& event)
{
    wxPaintDC dc(m_TopWaveformPanel);
    
    // OnRenderPlayhead(dc);   i don't know what this does but it probably goes into the UpdateWaveformBitmap() method

   const wxSize size = m_TopWaveformPanel->GetClientSize();
   if(!m_bitmap.IsOk()
        || m_bitmap.GetWidth() != size.x
        || m_bitmap.GetHeight() != size.y
        || anyVisiblePropertyOfTheWaveformHasChanged() )
  {
     m_bitmap.Create(size.x, size.y, 32);
     UpdateWaveformBitmap();
  }

  dc.DrawBitmap(m_bitmap, 0, 0, false);
  
  // draw other stuff here, e.g. position indicator etc.
}

Code: Select all

void MainFrame::UpdateWaveformBitmap()
{
  wxMemoryDC mdc(m_bitmap);

  // render waveform into bitmap here
}
Use the source, Luke!
apoorv569
Super wx Problem Solver
Super wx Problem Solver
Posts: 426
Joined: Tue Oct 20, 2020 3:35 pm

Re: How to remove trailing effect when drawing on a panel?

Post by apoorv569 »

doublemax wrote: Thu Jul 29, 2021 6:15 pm You don't need the wxStaticBitmap.

Your paint event handler should look something like this:

Code: Select all

void MainFrame::OnPaintPlayhead(wxPaintEvent& event)
{
    wxPaintDC dc(m_TopWaveformPanel);
    
    // OnRenderPlayhead(dc);   i don't know what this does but it probably goes into the UpdateWaveformBitmap() method

   const wxSize size = m_TopWaveformPanel->GetClientSize();
   if(!m_bitmap.IsOk()
        || m_bitmap.GetWidth() != size.x
        || m_bitmap.GetHeight() != size.y
        || anyVisiblePropertyOfTheWaveformHasChanged() )
  {
     m_bitmap.Create(size.x, size.y, 32);
     UpdateWaveformBitmap();
  }

  dc.DrawBitmap(m_bitmap, 0, 0, false);
  
  // draw other stuff here, e.g. position indicator etc.
}

Code: Select all

void MainFrame::UpdateWaveformBitmap()
{
  wxMemoryDC mdc(m_bitmap);

  // render waveform into bitmap here
}
Thank you for the example code. I'm having trouble with rendering to bitmap, no matter what I try, when I open the app I get a error saying

Code: Select all

./src/gtk/bitmap.cpp(1262): assert "bmpData->m_pixbufNoMask" failed in SetSourceSurface(): no bitmap data
Here is the UpdateWaveformBitmap(),

Code: Select all

void MainFrame::UpdateWaveformBitmap(wxDC& dc)
{
    Database db(*m_InfoBar);
    Settings settings(this, m_ConfigFilepath, m_DatabaseFilepath);

    int selected_row = m_Library->GetSelectedRow();

    if (selected_row < 0) return;

    wxString selection = m_Library->GetTextValue(selected_row, 1);

    wxString filepath_with_extension = db.GetSamplePathByFilename(static_cast<std::string>(DATABASE_FILEPATH), selection.BeforeLast('.').ToStdString());
    wxString filepath_without_extension = db.GetSamplePathByFilename(static_cast<std::string>(DATABASE_FILEPATH), selection.ToStdString());

    std::string extension = settings.ShouldShowFileExtension() ?
        db.GetSampleFileExtension(static_cast<std::string>(DATABASE_FILEPATH), selection.ToStdString()) :
        db.GetSampleFileExtension(static_cast<std::string>(DATABASE_FILEPATH), selection.BeforeLast('.').ToStdString());

    wxString path = selection.Contains(wxString::Format(".%s", extension)) ?
        filepath_with_extension : filepath_without_extension;

    SndfileHandle snd_file(path);

    int channels = snd_file.channels();
    double sample_rate = snd_file.samplerate();
    sf_count_t frames = snd_file.frames();

    std::vector<float> sample;
    sample.resize(frames * channels);

    std::vector<signed char> waveform;

    snd_file.read(&sample.at(0), frames * channels);

    float display_width = m_TopWaveformPanel->GetSize().GetWidth();
    float display_height = m_TopWaveformPanel->GetSize().GetHeight();

    double max_value;
    snd_file.command(SFC_CALC_NORM_SIGNAL_MAX, &max_value, sizeof(max_value));

    float normalized_value = max_value > 1.0f ? 1.0f : 1.0f / max_value;

    float samples_per_pixel = static_cast<float>(frames) / (float)display_width;

    if (channels == 2)
    {
        for (int i = 0, j = 0 ; i < frames; i++)
        {
            float sum = (((sample[j] + sample[j + 1]) * 0.5f) * normalized_value) * float(display_height / 2.0f);
            waveform.push_back(sum);
            j += 2;
        }
    }
    else
    {
        waveform.resize(frames);

        for (int i = 0; i < frames; i++)
        {
            waveform[i] = (sample[i] * normalized_value) * float(display_height / 2.0f);
        }
    }

    /*===========================Draw code============================*/
    wxMemoryDC mdc(m_WaveformBitmap);
    dc.SetPen(wxPen(wxColour(0, 0, 0, 255), 2, wxPENSTYLE_SOLID));

    if (!mdc.IsOk())
        return;

    for(int i = 0; i < waveform.size() - 1; i++)
    {
        dc.DrawLine((display_width * i) / waveform.size(), waveform[i] + display_height / 2.0f,
                    (display_width * i) / waveform.size(), (waveform[i] / samples_per_pixel) + display_height / 2.0f);
    }

    dc.Blit(m_TopWaveformPanel->GetSize().GetWidth() - (m_TopWaveformPanel->GetSize().GetWidth() - 1),
            m_TopWaveformPanel->GetSize().GetHeight() - (m_TopWaveformPanel->GetSize().GetHeight() - 1),
            m_WaveformBitmap.GetWidth(), m_WaveformBitmap.GetHeight(), &mdc, 0, 0);
}
And here is the OnPaint()

Code: Select all

void MainFrame::OnPaint(wxPaintEvent& event)
{
    wxPaintDC dc(m_TopWaveformPanel);
    OnRenderPlayhead(dc);

    const wxSize size = m_TopWaveformPanel->GetClientSize();
    if(!m_WaveformBitmap.IsOk()
       || m_WaveformBitmap.GetWidth() != size.x
       || m_WaveformBitmap.GetHeight() != size.y
       /* || anyVisiblePropertyOfTheWaveformHasChanged() */ )
    {
        m_WaveformBitmap.Create(size.x, size.y, 32);
        UpdateWaveformBitmap(dc);
    }

    dc.DrawBitmap(m_WaveformBitmap, 0, 0, false);
}
OnRenderPlayhead() is for drawing the position marker.
apoorv569
Super wx Problem Solver
Super wx Problem Solver
Posts: 426
Joined: Tue Oct 20, 2020 3:35 pm

Re: How to remove trailing effect when drawing on a panel?

Post by apoorv569 »

doublemax wrote: Thu Jul 29, 2021 6:15 pm You don't need the wxStaticBitmap.

Your paint event handler should look something like this:

Code: Select all

void MainFrame::OnPaintPlayhead(wxPaintEvent& event)
{
    wxPaintDC dc(m_TopWaveformPanel);
    
    // OnRenderPlayhead(dc);   i don't know what this does but it probably goes into the UpdateWaveformBitmap() method

   const wxSize size = m_TopWaveformPanel->GetClientSize();
   if(!m_bitmap.IsOk()
        || m_bitmap.GetWidth() != size.x
        || m_bitmap.GetHeight() != size.y
        || anyVisiblePropertyOfTheWaveformHasChanged() )
  {
     m_bitmap.Create(size.x, size.y, 32);
     UpdateWaveformBitmap();
  }

  dc.DrawBitmap(m_bitmap, 0, 0, false);
  
  // draw other stuff here, e.g. position indicator etc.
}

Code: Select all

void MainFrame::UpdateWaveformBitmap()
{
  wxMemoryDC mdc(m_bitmap);

  // render waveform into bitmap here
}
Okay, I made some progress, I was drawing the bitmap without rendering anything to it, so I made some changes,

Code: Select all

void MainFrame::OnPaint(wxPaintEvent& event)
{
    wxPaintDC dc(m_TopWaveformPanel);

    const wxSize size = m_TopWaveformPanel->GetClientSize();
    if(!m_WaveformBitmap.IsOk()
       || m_WaveformBitmap.GetWidth() != size.x
       || m_WaveformBitmap.GetHeight() != size.y
       /* || anyVisiblePropertyOfTheWaveformHasChanged() */ )
    {
        m_WaveformBitmap.Create(size.x, size.y, 32);
        UpdateWaveformBitmap(dc);
    }

    if (!dc.IsOk())
        return;

    wxMemoryDC mdc(m_WaveformBitmap);

    if (!mdc.IsOk())
        return;

    UpdateWaveformBitmap(mdc);

    dc.Blit(m_TopWaveformPanel->GetSize().GetWidth() - (m_TopWaveformPanel->GetSize().GetWidth() - 1),
            m_TopWaveformPanel->GetSize().GetHeight() - (m_TopWaveformPanel->GetSize().GetHeight() - 1),
            m_WaveformBitmap.GetWidth(), m_WaveformBitmap.GetHeight(), &mdc, 0, 0);

    dc.DrawBitmap(m_WaveformBitmap, 0, 0, false);

    OnRenderPlayhead(dc);
}
And the render code is,

Code: Select all

    /*===========================Draw code============================*/
    wxMemoryDC mdc(m_WaveformBitmap);
    dc.SetPen(wxPen(wxColour(0, 0, 0, 255), 2, wxPENSTYLE_SOLID));

    for(int i = 0; i < waveform.size() - 1; i++)
    {
        dc.DrawLine((display_width * i) / waveform.size(), waveform[i] + display_height / 2.0f,
                    (display_width * i) / waveform.size(), (waveform[i] / samples_per_pixel) + display_height / 2.0f);
    }
I think I am creating 2 different wxMemoryDC's, but anything else I try causes a error or crash.

This seems to work, and this also takes care of resizing the waveform, when the window is resized or splitter is resized. But the performance is still not great, for example for small samples, 1-2 second long, it does fine, but if the sample is 10-15 seconds, it takes a while to render the bitmap, then it finally loads, and also the position marker moves very slowly, not smooth movement.
Last edited by apoorv569 on Fri Jul 30, 2021 7:02 am, edited 1 time in total.
User avatar
doublemax
Moderator
Moderator
Posts: 19158
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to remove trailing effect when drawing on a panel?

Post by doublemax »

Code: Select all

    if (!dc.IsOk())
        return;

    wxMemoryDC mdc(m_WaveformBitmap);

    if (!mdc.IsOk())
        return;

    UpdateWaveformBitmap(mdc);

    dc.Blit(m_TopWaveformPanel->GetSize().GetWidth() - (m_TopWaveformPanel->GetSize().GetWidth() - 1),
            m_TopWaveformPanel->GetSize().GetHeight() - (m_TopWaveformPanel->GetSize().GetHeight() - 1),
            m_WaveformBitmap.GetWidth(), m_WaveformBitmap.GetHeight(), &mdc, 0, 0);
Remove all this. The whole point of using the bitmap was that you update it only when necessary.

And for that you need to replace "anyVisiblePropertyOfTheWaveformHasChanged" with something useful later.
Use the source, Luke!
apoorv569
Super wx Problem Solver
Super wx Problem Solver
Posts: 426
Joined: Tue Oct 20, 2020 3:35 pm

Re: How to remove trailing effect when drawing on a panel?

Post by apoorv569 »

doublemax wrote: Fri Jul 30, 2021 6:35 am

Code: Select all

    if (!dc.IsOk())
        return;

    wxMemoryDC mdc(m_WaveformBitmap);

    if (!mdc.IsOk())
        return;

    UpdateWaveformBitmap(mdc);

    dc.Blit(m_TopWaveformPanel->GetSize().GetWidth() - (m_TopWaveformPanel->GetSize().GetWidth() - 1),
            m_TopWaveformPanel->GetSize().GetHeight() - (m_TopWaveformPanel->GetSize().GetHeight() - 1),
            m_WaveformBitmap.GetWidth(), m_WaveformBitmap.GetHeight(), &mdc, 0, 0);
Remove all this. The whole point of using the bitmap was that you update it only when necessary.

And for that you need to replace "anyVisiblePropertyOfTheWaveformHasChanged" with something useful later.
I tried doing it this way,

Code: Select all

void MainFrame::OnPaint(wxPaintEvent& event)
{
    wxPaintDC dc(m_TopWaveformPanel);

    const wxSize size = m_TopWaveformPanel->GetClientSize();
    if(!m_WaveformBitmap.IsOk()
       || m_WaveformBitmap.GetWidth() != size.x
       || m_WaveformBitmap.GetHeight() != size.y
       || OnWaveformBitmapChanged(dc) )
    {
        m_WaveformBitmap.Create(size.x, size.y, 32);
        UpdateWaveformBitmap(dc);
    }

    if (!OnWaveformBitmapChanged(dc))
        return;
    else
        dc.DrawBitmap(m_WaveformBitmap, 0, 0, false);

    OnRenderPlayhead(dc);
}

bool MainFrame::OnWaveformBitmapChanged(wxDC& dc)
{
    if (!dc.IsOk())
        return false;

    wxMemoryDC mdc(m_WaveformBitmap);

    if (!mdc.IsOk())
        return false;

    UpdateWaveformBitmap(mdc);

    if (dc.Blit(m_TopWaveformPanel->GetSize().GetWidth() - (m_TopWaveformPanel->GetSize().GetWidth() - 1),
                m_TopWaveformPanel->GetSize().GetHeight() - (m_TopWaveformPanel->GetSize().GetHeight() - 1),
                m_WaveformBitmap.GetWidth(), m_WaveformBitmap.GetHeight(), &mdc, 0, 0))
        return true;

    return false;
}
It still behaves kind of same.
Sorry, but I'm not able to understand how to do this. I understand what I have to, but not how to.

Do I need to catch event of the frame resized or splitter resized and do this code in that handler?
User avatar
doublemax
Moderator
Moderator
Posts: 19158
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to remove trailing effect when drawing on a panel?

Post by doublemax »

apoorv569 wrote: Fri Jul 30, 2021 9:01 am Sorry, but I'm not able to understand how to do this. I understand what I have to, but not how to.
I doubt that because you're still rendering the wave form in every paint event.
apoorv569 wrote: Fri Jul 30, 2021 9:01 am Do I need to catch event of the frame resized or splitter resized and do this code in that handler?
No. This is handled automatically through the check if the bitmap size differs from the panel size.

For a start, you should need just this, nothing else:

Code: Select all

void MainFrame::OnPaint(wxPaintEvent& event)
{
    wxPaintDC dc(m_TopWaveformPanel);

    const wxSize size = m_TopWaveformPanel->GetClientSize();
    if(!m_WaveformBitmap.IsOk()
       || m_WaveformBitmap.GetWidth() != size.x
       || m_WaveformBitmap.GetHeight() != size.y )
    {
        m_WaveformBitmap.Create(size.x, size.y, 32);
        UpdateWaveformBitmap(dc);
    }

    dc.DrawBitmap(m_WaveformBitmap, 0, 0, false);

    OnRenderPlayhead(dc);
}
Use the source, Luke!
apoorv569
Super wx Problem Solver
Super wx Problem Solver
Posts: 426
Joined: Tue Oct 20, 2020 3:35 pm

Re: How to remove trailing effect when drawing on a panel?

Post by apoorv569 »

For a start, you should need just this, nothing else:

Code: Select all

void MainFrame::OnPaint(wxPaintEvent& event)
{
    wxPaintDC dc(m_TopWaveformPanel);

    const wxSize size = m_TopWaveformPanel->GetClientSize();
    if(!m_WaveformBitmap.IsOk()
       || m_WaveformBitmap.GetWidth() != size.x
       || m_WaveformBitmap.GetHeight() != size.y )
    {
        m_WaveformBitmap.Create(size.x, size.y, 32);
        UpdateWaveformBitmap(dc);
    }

    dc.DrawBitmap(m_WaveformBitmap, 0, 0, false);

    OnRenderPlayhead(dc);
}
If I use this exact block of code, I get this error when I open the app,
Image

The waveform will only show when I click on sample in the wxDVLC. Initially nothing it shown.
User avatar
doublemax
Moderator
Moderator
Posts: 19158
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to remove trailing effect when drawing on a panel?

Post by doublemax »

I can only guess here:

Try setting the bitmap depth to 24.

Code: Select all

m_WaveformBitmap.Create(size.x, size.y, 24);
Use the source, Luke!
apoorv569
Super wx Problem Solver
Super wx Problem Solver
Posts: 426
Joined: Tue Oct 20, 2020 3:35 pm

Re: How to remove trailing effect when drawing on a panel?

Post by apoorv569 »

doublemax wrote: Fri Jul 30, 2021 9:53 am I can only guess here:

Try setting the bitmap depth to 24.

Code: Select all

m_WaveformBitmap.Create(size.x, size.y, 24);
I tried setting it to 24, still getting same error. :(

Also if I click continue on the error, the panel appears black in color for some reason.
Image

Though as soon I as click on a sample, it again shows error.
User avatar
doublemax
Moderator
Moderator
Posts: 19158
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to remove trailing effect when drawing on a panel?

Post by doublemax »

Once again, i can only guess when it comes to GTK specifics.

Leave bitmap at 32, but set "useMask" parameter in the DrawBitmap call to true

Code: Select all

    {
        m_WaveformBitmap.Create(size.x, size.y, 32);
        UpdateWaveformBitmap(dc);
    }

    dc.DrawBitmap(m_WaveformBitmap, 0, 0, true);
If that still fails, try to find out which line exactly triggers the assert. The backtrace doesn't seem to be complete.

Edit: Looking at the backtrace again and noticing that it only shows the wxWidgets methods, but not the ones from your app, i suspect that you're not building it in debug mode.
Use the source, Luke!
apoorv569
Super wx Problem Solver
Super wx Problem Solver
Posts: 426
Joined: Tue Oct 20, 2020 3:35 pm

Re: How to remove trailing effect when drawing on a panel?

Post by apoorv569 »

doublemax wrote: Fri Jul 30, 2021 10:49 am Once again, i can only guess when it comes to GTK specifics.

Leave bitmap at 32, but set "useMask" parameter in the DrawBitmap call to true

Code: Select all

    {
        m_WaveformBitmap.Create(size.x, size.y, 32);
        UpdateWaveformBitmap(dc);
    }

    dc.DrawBitmap(m_WaveformBitmap, 0, 0, true);
If that still fails, try to find out which line exactly triggers the assert. The backtrace doesn't seem to be complete.

Edit: Looking at the backtrace again and noticing that it only shows the wxWidgets methods, but not the ones from your app, i suspect that you're not building it in debug mode.
Setting the depth to 32, and useMask to true, still gives same error. I tried opening the binary with GDB, and it failed at dc.DrawBitmap()

Code: Select all

(gdb) run
Starting program: /tmp/SampleHive/bin/SampleHive
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".
16:28:32: Warning: Mismatch between the program and library build versions detected.
The library used 3.0 (wchar_t,compiler with C++ ABI 1014,wx containers,compatible with 2.8),
and your program used 3.0 (wchar_t,compiler with C++ ABI 1016,wx containers,compatible with 2.8).
[New Thread 0x7ffff3e63640 (LWP 2509252)]
[New Thread 0x7ffff3662640 (LWP 2509253)]
[New Thread 0x7ffff2dde640 (LWP 2509254)]
[New Thread 0x7ffff25dd640 (LWP 2509255)]
[New Thread 0x7ffff1ddc640 (LWP 2509256)]
[Thread 0x7ffff1ddc640 (LWP 2509256) exited]
[New Thread 0x7ffff1ddc640 (LWP 2509257)]
[New Thread 0x7ffff0b0c640 (LWP 2509258)]
[Thread 0x7ffff1ddc640 (LWP 2509257) exited]
[Thread 0x7ffff0b0c640 (LWP 2509258) exited]
(SampleHive:2509244): Gtk-CRITICAL **: 16:28:32.591: gtk_widget_set_size_request: assertion 'height >= -1' failed
[New Thread 0x7ffff0b0c640 (LWP 2509295)]
[New Thread 0x7ffff1ddc640 (LWP 2509296)]
[New Thread 0x7fffdafff640 (LWP 2509297)]
[Thread 0x7ffff1ddc640 (LWP 2509296) exited]

(SampleHive:2509244): Gtk-CRITICAL **: 16:28:32.790: gtk_widget_get_preferred_width_for_height: assertion 'height >= 0' failed

(SampleHive:2509244): Gtk-WARNING **: 16:28:32.790: gtk_widget_size_allocate(): attempt to allocate widget with width 121 and height -3
[Thread 0x7fffdafff640 (LWP 2509297) exited]
[New Thread 0x7fffdafff640 (LWP 2509298)]

Thread 1 "SampleHive" hit Breakpoint 1, MainFrame::OnPaint (this=0x555555796380, event=...) at ../src/MainFrame.cpp:2970
2970        if(!m_WaveformBitmap.IsOk()
(gdb) n
2972           || m_WaveformBitmap.GetHeight() != size.y)
(gdb) n
2970        if(!m_WaveformBitmap.IsOk()
(gdb) n
2974            m_WaveformBitmap.Create(size.x, size.y, 32);
(gdb) n
2975            UpdateWaveformBitmap(dc);
(gdb) n
2978        dc.DrawBitmap(m_WaveformBitmap, 0, 0, true);
(gdb) n
./src/gtk/bitmap.cpp(1262): assert "bmpData->m_pixbufNoMask" failed in SetSourceSurface(): no bitmap data
Here is the full backtrace,

Code: Select all

ASSERT INFO:
./src/gtk/bitmap.cpp(1262): assert "bmpData->m_pixbufNoMask" failed in SetSourceSurface(): no bitmap data

BACKTRACE:
[1] wxBitmap::SetSourceSurface(_cairo*, int, int, wxColour const*, wxColour const*) const
[2] wxBitmap::Draw(_cairo*, int, int, bool, wxColour const*, wxColour const*) const
[3] wxEvtHandler::ProcessEventIfMatchesId(wxEventTableEntryBase const&, wxEvtHandler*, wxEvent&)
[4] wxEvtHandler::SearchDynamicEventTable(wxEvent&)
[5] wxEvtHandler::TryHereOnly(wxEvent&)
[6] wxEvtHandler::ProcessEventLocally(wxEvent&)
[7] wxEvtHandler::ProcessEvent(wxEvent&)
[8] wxEvtHandler::SafelyProcessEvent(wxEvent&)
[9] wxWindow::GTKSendPaintEvents(_cairo*)
[10] g_closure_invoke
[11] g_signal_emit_valist
[12] g_signal_emit
[13] gtk_container_propagate_draw
[14] g_closure_invoke
[15] g_signal_emit_valist
[16] g_signal_emit
[17] gtk_container_propagate_draw
[18] g_closure_invoke
[19] g_signal_emit_valist
[20] g_signal_emit
[21] gtk_container_propagate_draw
[22] g_closure_invoke
[23] g_signal_emit_valist
[24] g_signal_emit
[25] gtk_container_propagate_draw
[26] g_closure_invoke
[27] g_signal_emit_valist
[28] g_signal_emit
[29] gtk_container_propagate_draw
[30] gtk_container_propagate_draw
[31] gtk_main_do_event
[32] g_signal_emit_valist
[33] g_signal_emit
[34] g_main_context_dispatch
[35] g_main_loop_run
[36] gtk_main
[37] wxGUIEventLoop::DoRun()
[38] wxEventLoopBase::Run()
[39] wxAppConsoleBase::MainLoop()
[40] wxEntry(int&, wchar_t**)
[41] __libc_start_main
User avatar
doublemax
Moderator
Moderator
Posts: 19158
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to remove trailing effect when drawing on a panel?

Post by doublemax »

I don't see any way the bitmap size could be 0.

Maybe that's one of the GTK oddities where windows get their size at a later time. Let's try adding a check for the panel size.

Code: Select all

const wxSize size = m_TopWaveformPanel->GetClientSize();
if (size.x < 1 || size.y < 1 ) return
Use the source, Luke!
apoorv569
Super wx Problem Solver
Super wx Problem Solver
Posts: 426
Joined: Tue Oct 20, 2020 3:35 pm

Re: How to remove trailing effect when drawing on a panel?

Post by apoorv569 »

doublemax wrote: Fri Jul 30, 2021 11:10 am I don't see any way the bitmap size could be 0.

Maybe that's one of the GTK oddities where windows get their size at a later time. Let's try adding a check for the panel size.

Code: Select all

const wxSize size = m_TopWaveformPanel->GetClientSize();
if (size.x < 1 || size.y < 1 ) return
Adding this still gives same error, however I found this link, https://groups.google.com/g/wx-commits- ... MnPZv-ZqPU

So I added this,

Code: Select all

    if (m_WaveformBitmap.IsNull())
        return;
This seems to suppress the assertion. But when I play a sample no waveform is drawn. The panel stays empty.
User avatar
doublemax
Moderator
Moderator
Posts: 19158
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to remove trailing effect when drawing on a panel?

Post by doublemax »

Code: Select all

if (m_WaveformBitmap.IsNull())
I don't think this is correct. This check will prevent the bitmap from ever being created.

Just trace through the code and check what happens. It's probably something simple.
Use the source, Luke!
apoorv569
Super wx Problem Solver
Super wx Problem Solver
Posts: 426
Joined: Tue Oct 20, 2020 3:35 pm

Re: How to remove trailing effect when drawing on a panel?

Post by apoorv569 »

doublemax wrote: Fri Jul 30, 2021 11:28 am

Code: Select all

if (m_WaveformBitmap.IsNull())
I don't think this is correct. This check will prevent the bitmap from ever being created.

Just trace through the code and check what happens. It's probably something simple.
Looks like no matter what it is, it always stops at m_WaveformBitmap.IsNull(), and never seem to move forward. Its not even drawing the position marker now, which it was before.

Code: Select all

void MainFrame::OnPaint(wxPaintEvent& event)
{
    wxPaintDC dc(m_TopWaveformPanel);

    const wxSize size = m_TopWaveformPanel->GetClientSize();

    if (size.x < 1 || size.y < 1 )
        return;

    if (m_WaveformBitmap.IsNull())
        return;                               // <------- Stops here

    if(!m_WaveformBitmap.IsOk()
       || m_WaveformBitmap.GetWidth() != size.x
       || m_WaveformBitmap.GetHeight() != size.y)
    {
        m_WaveformBitmap.Create(size.x, size.y, 32);
        UpdateWaveformBitmap(dc);
    }

    dc.DrawBitmap(m_WaveformBitmap, 0, 0, true);

    OnRenderPlayhead(dc);
}
Running through debugger, just keeps triggering this condition and returns.
Post Reply