doublemax wrote: ↑Thu Jan 14, 2021 12:22 pm
Forgot SampleListView is not a local variable in your case. Try this:
Code: Select all
SampleListView->Bind(wxEVT_DATAVIEW_SELECTION_CHANGED, [this](wxDataViewEvent &e) {
wxLogDebug("dataviewevent row %d", SampleListView->ItemToRow(e.GetItem()));
});
I think I might have found the bug in my code, today while experimenting again with the application, I noticed that all buttons and everything that I'm catching event for stops working after I add a single entry to the wxDataViewListCtrl, so I investigated further and in the function which I'm using to add data to wxDataViewListCtrl, I'm inserting all that data to Sqlite3 database also, I noticed that If I comment that line, that inserts data to Sqlite3 database, everything works fine.
Code: Select all
void Browser::OnClickDirCtrl(wxCommandEvent& event)
{
TagLib::FileRef File (DirCtrl->GetFilePath());
TagLib::String Artist = File.tag()->artist();
TagLib::String Album = File.tag()->album();
TagLib::String Genre = File.tag()->genre();
TagLib::String Title = File.tag()->title();
TagLib::String Comment = File.tag()->comment();
int Bitrate = File.audioProperties()->bitrate();
int Channels = File.audioProperties()->channels();
int Length = File.audioProperties()->lengthInMilliseconds();
int LengthSec = File.audioProperties()->lengthInSeconds();
int SampleRate = File.audioProperties()->sampleRate();
std::string Path = DirCtrl->GetFilePath().ToStdString();
char c = '/';
std::string Filename = DirCtrl->GetFilePath().AfterLast(c).ToStdString();
wxVector<wxVariant> Data;
Data.clear();
Data.push_back(false);
Data.push_back(Filename);
Data.push_back(TagLibTowx(Artist));
Data.push_back(wxString::Format("%d",Channels));
Data.push_back(wxString::Format("%d",LengthSec));
Data.push_back(wxString::Format("%d",SampleRate));
Data.push_back(wxString::Format("%d",Bitrate));
Data.push_back(TagLibTowx(Comment));
SampleListView->AppendItem(Data);
// db.InsertSample(0, Filename, Artist.to8Bit(), Channels, Length,
// SampleRate, Bitrate, Comment.to8Bit(), Path);
wxString sample = db.GetSamplePathByFilename(std::string(Filename));
std::cout << "Sample: " << sample << std::endl;
}
As you can see above I have commented out the line which inserts data to Sqlite3 database which is `db.InsertSample()` which looks like this
Code: Select all
void Database::InsertSample(int Favorite, std::string Filename,
std::string SamplePack, int Channels, int Length,
int SampleRate, int Bitrate, std::string Comment,
std::string Path)
{
try
{
rc = sqlite3_open("Samples.db", &DB);
sql = "INSERT INTO SAMPLES (FAVORITE, FILENAME, SAMPLEPACK, CHANNELS, \
LENGTH, SAMPLERATE, BITRATE, BITSPERSAMPLE, PATH) \
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);";
rc = sqlite3_prepare_v2(DB, sql.c_str(), sql.size(), &stmt, NULL); // create the prepared statement
rc = sqlite3_bind_int(stmt, 1, Favorite);
rc = sqlite3_bind_text(stmt, 2, Filename.c_str(), Filename.size(), SQLITE_STATIC);
rc = sqlite3_bind_text(stmt, 3, SamplePack.c_str(), SamplePack.size(), SQLITE_STATIC);
rc = sqlite3_bind_int(stmt, 4, Channels);
rc = sqlite3_bind_int(stmt, 5, Length);
rc = sqlite3_bind_int(stmt, 6, SampleRate);
rc = sqlite3_bind_int(stmt, 7, Bitrate);
rc = sqlite3_bind_text(stmt, 8, Comment.c_str(), Comment.size(), SQLITE_STATIC);
rc = sqlite3_bind_text(stmt, 9, Path.c_str(), Path.size(), SQLITE_STATIC);
if (sqlite3_step(stmt) != SQLITE_DONE)
{
std::cout << "Not inserted data." << "\n";
}
rc = sqlite3_finalize(stmt);
if (rc != SQLITE_OK)
{
std::cerr << "Error! Cannot insert data into table." << std::endl;
sqlite3_free(ErrorMessage);
}
else if (rc == SQLITE_BUSY)
{
std::cout << "BUSY" << std::endl;
}
else if (rc == SQLITE_DONE)
{
std::cout << "DONE" << std::endl;
}
else if (rc == SQLITE_ERROR)
{
std::cout << "ERROR" << std::endl;
}
else if (rc == SQLITE_MISUSE)
{
std::cout << "MISUSE" << std::endl;
}
else
{
std::cout << "Data inserted successfully." << ErrorMessage << std::endl;
}
sqlite3_close(DB);
}
catch (const std::exception &exception)
{
std::cerr << exception.what();
}
}
I can't say if something is wrong with the database or what at this point, I'm still looking, please if you see anything wrong let me know.
Link to the Database.cpp file -
https://gitlab.com/apoorv569/cpp-projec ... se.cpp#L45