handmade.network » Forums » Work-in-Progress » Tune.sh: Simple music player on Windows
miked
Michael Dodis
12 posts / 1 project
#16932 Tune.sh: Simple music player on Windows
7 months, 1 week ago Edited by Michael Dodis on Dec. 9, 2018, 4:09 p.m. Reason: Initial post

Hello everyone! I'm new on the forums, but I've been following Handmade Hero and the network for about half year, and the projects on here are just amazing!
I was half confident about posting this, but I thought that maybe somebody would appreciate something like this.

I'd written a cross platform terminal based music player, with fmod, and ncurses (pdcurses on Windows), and it was very clunky, so I decided to do a complete re-write with the idea of Handmade Hero (low-level and performance oriented and what not), on Windows for the time being.
The old project git repo is here if you want to take a look at the mess I'd made.

Right now, the new one is still in heavy development (paused until I have more spare time; university progress tests and all that). It allows you to scroll and select stuff with the mouse, and it implements resizing as well.
Here's the link to the executable (in a zip file), and the virustotal result. It should open up with just double clicking on the executable, and it should show a list of "tracks", which you can scroll through with the mouse wheel. Pressing Y on the keyboard adds a new track (for testing purposes), and Escape quits.

Right now I'll be using fmod to open all the different audio files, but the rest is plain Win32 API code.

I wanted to add functionality for the WM_DROPFILES message, but since the console window doesn't belong to the program's process, I can't access it. Should you have any way around that I'll be glad to know!

My main goal, is for the application to open up quickly, and play music files without silly graphical sugar (not only because it slows down the process, but also because I don't want to have to implement it :) ).

If anybody has any suggestions please tell me! I'm certainly not an experienced programmer and anything helps! Thank you for reading this post! Sorry for any bad English btw
mrmixer
Simon Anciaux
633 posts
#16958 Tune.sh: Simple music player on Windows
7 months, 1 week ago

Why exactly do you want to make a terminal application if you want to have mouse support ? Wouldn't it be better to make a lightweight GUI ?
miked
Michael Dodis
12 posts / 1 project
#16973 Tune.sh: Simple music player on Windows
7 months ago Edited by Michael Dodis on Dec. 16, 2018, 6:21 p.m.

mrmixer
Why exactly do you want to make a terminal application if you want to have mouse support ? Wouldn't it be better to make a lightweight GUI ?

It certainly would lead to something that would be a lot prettier, and a lot more robust. But I would have to either use the Win32 drawing API, or initialize and handle something like OpenGL, and the API for the Console is just less functions to think about. Now it's not always good thing, but for me it's good enough for starting off.

If it all goes well maybe I will convert it into an actual GUI rather than console functions.
For instance in OpenGL, besides handling resize events and all that, I would have to implement font rendering, along with loading TrueType fonts, maybe blending later on for highlighting something...
It would take too much time to build the GUI, even with a library like Dear Imgui to help me.

Using The Console functions in Win32 all I have to do, is maintain 2 buffers: a character buffer, and an attribute buffer. I check for events, using the Input Record struct, meaning I don't have to handle the traditional Window procedure, I write the characters and the attributes I need to my buffers, then I just write them to the console with WriteConsoleOutputCharacter
and WriteConsoleOutputAttribute.

I decided to use the console just to first figure out what functionality I want, the layout of the UI, generally what works and what doesn't.
But I don't believe that this applies to everyone. I'm not very good or experienced at building GUI applications in general, and I like something that is more straight-forward (but only for experimentation!). Someone with a richer background on gui programming, or with experience with a certain library might be better off than using the console's api.
mrmixer
Simon Anciaux
633 posts
#16974 Tune.sh: Simple music player on Windows
7 months ago

I'm fine with a console UI, it's the mouse handling part that I find odd. I generally don't use the mouse if I use a console application.
If you want to support the mouse (drag'n drop...) maybe you could do a windowed application that looks like a console ? If you only render ASCII characters with a bitmap font it's not that much work, and you can do software rendering for that so you won't need OpenGL on Direct3D.
miked
Michael Dodis
12 posts / 1 project
#16975 Tune.sh: Simple music player on Windows
7 months ago

mrmixer
I'm fine with a console UI, it's the mouse handling part that I find odd. I generally don't use the mouse if I use a console application.
If you want to support the mouse (drag'n drop...) maybe you could do a windowed application that looks like a console ? If you only render ASCII characters with a bitmap font it's not that much work, and you can do software rendering for that so you won't need OpenGL on Direct3D.


Yeah that makes sense. But what about showing letters that aren't in english? I thought about re-watching the first 10 or so handmade hero episodes to see how to do software rendering, but I didn't think about it as much as I should have, I guess.

I do plan to also add keyboard support (I only had keyboard support the first time around), and after it's functional maybe some way to change the keys and re-compile. I implemented the mouse first, just to see if it was possible in the command prompt.

I really wanted full utf-8 support, because a lot of my files aren't in english (I'm greek), and having suffered through the handling of utf-8 and window's strings, I feel commited to it now😂
mrmixer
Simon Anciaux
633 posts
#16976 Tune.sh: Simple music player on Windows
7 months ago

I suggested ascii and bitmap fonts because it's easy to start with. If you want be able to display any codepoint, you can look at stb_truetype or FreeType to render the any codepoint glyph. I don't know what you were referring to exactly but Windows uses utf-16 to encode strings. But it's probably better to use utf-8 in your applications.
miked
Michael Dodis
12 posts / 1 project
#16978 Tune.sh: Simple music player on Windows
7 months ago Edited by Michael Dodis on Dec. 17, 2018, 9:41 a.m.

mrmixer
I suggested ascii and bitmap fonts because it's easy to start with. If you want be able to display any codepoint, you can look at stb_truetype or FreeType to render the any codepoint glyph.


Now that I think about it, maybe using stb truetype, and legacy opengl or something similar, would have been better, especially regarding the hassle I had to get through to render Unicode on the console. But my initial thought was: "I wanna render lines of unicode text, and highlight them whenever the mouse is over them (or whatever). Since I know I'm gonna re-write it eventually, especially if I plan to treat it as a serious application, why not use a system that's already in place (and works, more or less), to figure out how it should behave first?

Admittedly, it did kind of come back to bite me in the ass a few times, mainly due to the weird design of the console API and some of its caveats. But I get what you mean, and in retrospect, it's a much better path to follow, now that you pointed it out for me.

mrmixer
I don't know what you were referring to exactly but Windows uses utf-16 to encode strings. But it's probably better to use utf-8 in your applications.


Yeah Windows uses UTF-16, but I had to use UFT-8 for anything other than English so that the console outputs correctly (I couldn't really get it to work with Unicode on wide strings).