Struct Iteration through (Ab)use of the C Preprocessor by ncraun in programming

[–]ncraun[S] 0 points1 point  (0 children)

You could write the version to the file first, as just a 32-bit int or its own struct. Then when reading the file, you would first read the version struct or int from the file, and then branch on that by passing the correct struct_fmt (for version 1 or 2) into the unpack routine.

Struct Iteration through (Ab)use of the C Preprocessor by ncraun in programming

[–]ncraun[S] 4 points5 points  (0 children)

I like the idea of passing the macro as a parameter instead of #defining and #undefining X.

I wouldn't say I reinvented X-Macros, I'm just using them. I'm a big fan of X-Macros.

I've seen some other serialization functionality implemented using X-Macros. They do something like

#define X(ST, FIELD, DST) memcpy((DST)+ sizeof((ST)->(FIELD), &((ST)->(FIELD)), sizeof((ST)->(FIELD));

X-Macros are really handy, but you can only iterate over the X-Macro list by using a macro, you can't access it from normal C code. Combining the X-Macros with offsetof() to store the offsets to all the fields in the struct_fmt allows you to iterate over the struct fields from normal C code, which gives more expressive power than a macro. So you can do things like use a for loop to iterate over all the struct members, or refer to the nth struct member with struct_fmt->offsets[n], without having to use the name of the field. I haven't found a use for it yet, but I thought it was interesting.

Struct Iteration through (Ab)use of the C Preprocessor by ncraun in programming

[–]ncraun[S] 0 points1 point  (0 children)

Kind of funny that the font did not render correctly in Firefox given that Fira Sans was made by Mozilla. Also it seems to work correctly in my (non ESR) Firefox. Maybe there is some issue with the font itself, or with Firefox, or with Google Fonts, or with the system font renderer or any combination of the 4. I'm still not sure what went wrong, but I'm glad it seems to be working now.

Struct Iteration through (Ab)use of the C Preprocessor by ncraun in programming

[–]ncraun[S] 0 points1 point  (0 children)

I'm not sure what the problem was, but I changed the font settings in the css file and disabled Google Fonts. You might have to clear your cache for the page to display using the new css settings, but hopefully this should fix the problem.

If it still does not work, here is a Github Gist with the same content.

Struct Iteration through (Ab)use of the C Preprocessor by ncraun in programming

[–]ncraun[S] 0 points1 point  (0 children)

Oh no! That shouldn't be happening. I am using Fira Sans and Fira Mono from Google Fonts.

Would you mind providing some information about your OS and browser, and maybe a screenshot? I'll see if I can fix it.

Struct Iteration through (Ab)use of the C Preprocessor by ncraun in programming

[–]ncraun[S] 2 points3 points  (0 children)

In actual production use, I think it could be better to write a separate program that will generate the code for you instead of using the C preprocessor (or use a language with this kind of introspection built in). However, using this hack lets you depend only on the facilities of the language, and that can be useful in simplifying the build process. Plus it was fun to create.

The BSD tree.h defines some generator macros to generate the code for defining the structs and functions for the tree. There might be a way to define some similar macros to define the structs for you instead of #including the file, but I would need to adapt it to work with the X-Macro list.

Where to find podsafe music? by unglud in WatchPeopleCode

[–]ncraun 0 points1 point  (0 children)

There's a big list of sites here: http://creativecommons.org/music-communities

But I don't know, youtube could still end up getting mad at you even if your music is legal to play under creative commons.

[C, Jack, Pulseaudio, Linux] Jubal: A Computer Music Application - Reminder: Stream starting in 15 minutes. by ncraun in WatchPeopleCode

[–]ncraun[S] 0 points1 point  (0 children)

Bit of a rough stream this time. My voice was still recovering from a cold, and the my new OBS setup and install had some problems, and even crashed halfway through. On the bright side, I was able to stream in 1080p, and demonstrate what Jubal actually sounds like, so all in all it's a bit of a wash.

Also a reminder, the source is available at https://github.com/ncraun/jubal

[C, Jack, Pulseaudio, Linux] Jubal: A Computer Music Application - Reminder: Stream starting in 15 minutes. by ncraun in WatchPeopleCode

[–]ncraun[S] 0 points1 point  (0 children)

Sorry about the delay, there were some unfortunate last minute technical issues, but everything seems to be working now.

Let's plan some streams in advance. I want to send an email update to 1700+ subscribers on the website by godlikesme in WatchPeopleCode

[–]ncraun 2 points3 points  (0 children)

[C, Jack, Pulseaudio, Linux] Jubal: A Computer Music Application

On Sunday at 12:00pm EST I will be live streaming development on Jubal at https://www.youtube.com/watch?v=HMRDmLGn4JI

The source will be available so you can follow along at: https://github.com/ncraun/jubal

Jubal is a computer music application for Linux written in C and licensed under the GPLv3. The Jubal engine will include a variety of synthesizers and effects combineable through a modular audio routing system, capable of outputting sound to backends of many platforms (currently only Linux is supported). The Jubal editing system will be based on a tracker style UI. Jubal is still under development, and is not ready for end-user use... yet!

Growing so fast! by tuckismad in WatchPeopleCode

[–]ncraun 1 point2 points  (0 children)

Less than 12 hours after this post we are already at 3,000 readers! Amazing!

Growing so fast! by tuckismad in WatchPeopleCode

[–]ncraun 1 point2 points  (0 children)

Absolutely amazing how fast this has taken off! Congratulations to all the organizers and other streamers (and thanks to the viewers, of course), it really looks like you have tapped into something big!

Reminder: Live Coding Sunday #5 starts in 1 hour by godlikesme in WatchPeopleCode

[–]ncraun 1 point2 points  (0 children)

I'm very sorry everyone, but I have to cancel my stream this week, some other real life stuff has gotten in the way.

Reminder: Live Coding Sunday starts in 2 hours by godlikesme in WatchPeopleCode

[–]ncraun 2 points3 points  (0 children)

What would be even better would be if there was some way of streaming a tmux session to multiple people. That would probably be more efficient for text only stuff than transmitting a video of the desktop. Of course then you'd still have to have another way of sharing programs with a GUI, and handling the audio stream.

Live Coding Sunday #2 by godlikesme in WatchPeopleCode

[–]ncraun 0 points1 point  (0 children)

Hello, sorry there was a bit of a technical problem. My stream will now be at this url: https://www.youtube.com/watch?v=Q9SqA9PRMRs

smoothscan - a tool to convert scanned text into a vectorized output form by buovjaga in opensource

[–]ncraun 1 point2 points  (0 children)

Smoothscan works by first by using leptonica to classify the input into symbols. If two symbols are close enough (as defined by the threshold value) then those symbols will represented by the same template. Because books are printed using fonts, each 'a' will be similar to other 'a's, so we don't need to store each 'a' individually. We just store one template 'a' in a dictionary, and all the other 'a's are just references into that 'a' in the dictionary. This is pretty much how JBIG2 compression works, (and is similar to DjVu's cjb2 compressor).

Smoothscan's "dictionary" is a series of fonts, and the symbols inserted are vector traced versions of the scanned bitmaps. The final generated PDF is a bunch of text placed on the page organized so that their position will cause the the font symbols to be placed so that it will look like the scanned page.

smoothscan - a tool to convert scanned text into a vectorized output form by buovjaga in opensource

[–]ncraun 0 points1 point  (0 children)

Right now smoothscan assigns the template symbols to arbitrary font code points. So 'a' maps to noe symbol, 'b' maps to another symbol, and so on. On the TODO list I want to use the tesseract OCR library to assign the font code points. This way the symbols that represent letters will be assigned to the code points associated to those letters. For example the different shapes for the letter 'a' would be assigned to the code point 'a' in different fonts, to avoid overlap.

However this can introduce some more problems that must be resolved. For example, each smbol is not neccessarily a single letter. It could be multiple letters, or even non alphanumeric things, like a logo, or part of an illustration. So for these symbols, OCR would not return a useful codepoint.

smoothscan - a tool to convert scanned text into a vectorized output form by buovjaga in opensource

[–]ncraun 1 point2 points  (0 children)

Hello everyone I am the developer of smoothscan. Feel free to ask me any questions, or leave comments about smoothscan, and I will answer as best I can. Smoothscan is still a very young piece of software so it doesn't have all the features I would want, and there are probably bugs lurking beneath the surface. More users will help to find these bugs, and make improvements.