ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I'm hacking alsaplayer, changing the interface, adding features, etc. Yesterday it was working, today it's not, and I'm trying to figure out what I did to break it it. *shrug* This is how you learn.
I've been programming C as a hobby for quite a number of years now, but only dabbled in C++.
It no longer loads playlists, or anything for that matter.
The printf's are mine. That's how I tracked it down fairly fast.
Why is there 2 nearly identical routines?
By the way, I never modified this file before I started trying to find this problem. I was hacking away in interface/gtk2 when it broke.
queue.size() always returns 0 now, and cbinsert() never gets called. OK, fair enough. Let's have a look at queue.size()... I cannot find it. queue takes me to
Code:
Playlist.h:
class Playlist
{
(...)
AlsaNode *our_node; // Node
CorePlayer *coreplayer; // Core player - set this
std::vector<PlayItem> queue; // List of files to play
// ^^^^^
unsigned curritem; // Position of next file to play
std::set<PlaylistInterface *> interfaces; // Things to tell when things change
std::set<playlist_interface *> cinterfaces; // C version
(...)
std::vector<PlayItem>& GetQueue() { return queue; }
};
If you posted the changes you made to the original code, likely one of the C++ experts here would spot the bug you introduced. But here are some of the basics that might help you understand it yourself:
You have implied there exists at least one object of type Playlist. Inside each object of type Playlist, there is a member named queue, which is a std::vector of PlayItem's.
Unless forced otherwise (in the construction of queue inside the constructor of Playlist) that vector would be initially empty (so its size is correctly zero).
The code seems to depend on that size not being zero, and I think you said that is not part of your change, so you assume it is not incorrect to depend on the size being nonzero, so it is incorrect that the size is still zero when that part of the code is reached. So before you broke it, some part of the code inserted at least one PlayItem into the queue member of that Playlist. So the next step is find the place in the original code where that happened and figure out why, in your version, it does not.
Another thing that's useful to use, when you are "hacking anything," is: git
Git is a "server-less" version control system. You could cd to the directory where you are hacking the source code, run git init, and, presto! now it's "a repository." (You should start with the unmodified code.)
Do a git branch to describe your brainchild, then start making changes and as you go along, git commit. Exact details of every change are immediately recorded, and you can utterly-reliably go back to any of them. (And, furthermore, since "git always goes forward," you can even un-do "going back."
Nope, you'll never git push that repo anywhere else. But, now you have a way to avoid shooting yourself in the foot. (Or, if you prefer, "an absolutely reliable way to un-shoot it.") If you had done this, not only could you now see exactly what you did, but you also could have un-done it.
Last edited by sundialsvcs; 07-07-2015 at 06:04 PM.
Those links to cplusplus.com are great. I'm already poking around there checking out the std::stuff. Huge library.
re git: I have git installed and I played with it a bit. I should use it more often. Thanks for reminding me.
re fflush(): I use it when needed. Here the sequence is what's important and I just need to see that the points are being reached. I have certainly done what you say in situations where the timing is critical.
re backups: yeah, I always have backups. I never hack the originals. This subtree is called alsaplayer-0.99.81-hack2 hack7 is usually where it starts getting good, and I pretty much know the code in & out.
So std::vector is a data type, like int or char, except that it's fancier and comes with a bunch of handy utilities. Kinda like declaring a GList *list and then using g_list_length(list), but you can do list.length() instead. So when I see those std::things they are from trusted external library. That means queue.size() is *completely* separate from the program and cannot be part of the issue. Hmm. I can see the playlist loading, but they aren't getting into the queue somehow. This helps me greatly.
This puzzles me:
Code:
Playlist .h:
std::set<PlaylistInterface *> interfaces; // Things to tell when things change
std::set<playlist_interface *> cinterfaces; // C version
What? Why 2 versions? How is it decided which to use? Shouldn't these be in a union or something? Maybe this is issue, because interfaces is a bunch of callbacks that are obviously not getting called.
In alsaplayer here, we have hybrid. Some files are .c, and some are .cpp. It's good opportunity to learn something, and I certainly need to learn C++ better. I don't really care if my hacks turn into something great, I'm just trying to learn by doing (and breaking) things.
Thanks again for the replies. Now I'm not looking in the wrong place.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.