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: 19115
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

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

Post by doublemax »

Yes, I noticed that pos.x is only showing up to the panel width, while line_pos is calculated according to the sample length. Maybe I just pass line_pos here?
You need to do the reverse calculation of what you did here:

Code: Select all

    int length = tags.GetAudioInfo().length;
    double position = m_MediaCtrl.Tell();

    int panel_width = this->GetSize().GetWidth();
    double line_pos = panel_width * (position / length);
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: Sun Aug 01, 2021 7:30 am
Yes, I noticed that pos.x is only showing up to the panel width, while line_pos is calculated according to the sample length. Maybe I just pass line_pos here?
You need to do the reverse calculation of what you did here:

Code: Select all

    int length = tags.GetAudioInfo().length;
    double position = m_MediaCtrl.Tell();

    int panel_width = this->GetSize().GetWidth();
    double line_pos = panel_width * (position / length);
Okay, this seems to work,

Code: Select all

void WaveformViewer::OnReleasePlayhead(wxMouseEvent& event)
{
    Database db(m_InfoBar);

    int selected_row = m_Library.GetSelectedRow();

    if (selected_row < 0)
        return;

    wxString selected = m_Library.GetTextValue(selected_row, 1);
    std::string path = db.GetSamplePathByFilename(m_DatabaseFilepath, selected.BeforeLast('.').ToStdString());

    Tags tags(path);

    int length = tags.GetAudioInfo().length;
    // wxLogDebug("Sample length: %d", length);

    double position = m_MediaCtrl.Tell();
    // wxLogDebug("Current Sample Position: %f", position);

    int panel_width = this->GetSize().GetWidth();
    double line_pos = panel_width * (position / length);

    wxPoint pos = event.GetPosition();

    double seek_to = ((double)pos.x / panel_width) * length;    // <--------

    wxWindow::ReleaseMouse();
    SetCursor(wxCURSOR_ARROW);
    wxLogDebug("Mouse released playhead..");

    m_MediaCtrl.Seek(seek_to, wxFromCurrent);      // <----------
    m_MediaCtrl.Play();
    event.Skip();
}
But the cursor when left is down, doesn't change still.

Also I get assert messages when I try to click and release the button on a section of panel that is not satisfied by the if condition, but a else return should fix it, I suppose?

Also in the MainFrame class for all play methods, I have set it push status text, in the statusbar showing now playing, and pop the text when media state is stopped. But here in the WaveformViewer class I get an assert for this as well, saying no text to pop.

Also I noticed, position indicator only moves forward, if I try to drag it back, it still moves forward.
[Image
Post Reply