r3dux.org

A number-pimping side project from the valleys in *NEW* upside-down flavour.

  • Home
  • ABOUT
  • OLD SITE
  • SEARCH
  • FEEDBACK

Lady Sovereign – Bang Bang

r3dux | June 22, 2011

I’ve been playing a bunch of Fight Night Round 4 recently and this track from Lady Sovereign‘s 2009 album Jigsaw is in the soundtrack.

Lady Sovereign - Jigsaw Album

Audio clip: Adobe Flash Player (version 9 or above) is required to play this audio clip. Download the latest version here. You also need to have JavaScript enabled in your browser.

How catchy is that?! Big fan of the track production, too – there’s a lot of nice little bits and pieces hidden in the background which help give it a detailed, crisp sound. Good stuff =D

Comments
No Comments »
Categories
Music
Tags
Bang Bang, Jigsaw, Lady Sovereign
Comments rss Comments rss
Trackback Trackback

How to: Compile Qt projects which use the Q_OBJECT macro in Code::Blocks

r3dux | June 18, 2011

I need to write some C++ cross-platform GUI code soon, and after umming-and-ahhing about whether to use GTK or Qt, I’ve decided to try out the latter despite the recent Microsoft buy-out. However, as soon as I started to get into it and write some simple GUI code, I hit a snag; Qt uses what it calls slots to bind buttons to functions, where a function that can be executed as an action is defined as being a slot. To give an example, if you had a integer counter and you wanted to add five to the counter when you clicked the “Plus Five” button, then your onPlusFive function which actually increments the counter would be considered a slot.

This is all well and good, until you write the code and it won’t compile – instead giving you errors about vtables and such. To fix this, you need to do two things, the first of which is to add the Q_OBJECT macro definition to your QWidget-extending class.

Q_WHATNOW?

I’m really new to Qt, so any experienced coders might roll their eyes at this – but I expected to be able to just write some code that creates a window, some buttons, layouts, menu options etc, and then just compile it and we’re good to go a-la Java’s AWT/Swing interface kits. But no, unfortunately not. Instead, you have to add the Q_OBJECT macro to your class like this, and then do some pre-processing:

#ifndef COMMUNICATE_H
#define COMMUNICATE_H
 
#include <QtGui/QWidget>
#include <QtGui/QApplication>
#include <QtGui/QPushButton>
#include <QtGui/QLabel>
 
class Communicate : public QWidget
{
	Q_OBJECT // Define our class to use the Q_OBJECT macros (required for adding new slots)
 
	public:
		Communicate(QWidget *parent = 0); // Constructor
 
	private slots: // Functions for buttons
		void onPlusFive();
		void onMinusFive();
 
	private:
		QLabel *label;
};
#endif

That doesn’t seem too bad, right? You just plonk the word Q_OBJECT at the top of your class, and list all slots (functions that get executed as button actions) under the private slots: label. Well, yeah – it’s not so bad, but it’s not going to work that easily either. For this to work properly, we also need to do some pre-processing with a Qt utility called moc…

Moc Pre-processing Steps

AFAIK, the pre-processing that needs to occur must happen on all header files (and header files only) that utilise Qt in your project. You can do it by hand like this:

moc <some-class>.h -o moc_<some-class>.cpp

For example, if you had a MainWindow class separated into .h and .cpp files, you might run:

moc MainWindow.h -o moc_MainWindow.cpp

Once that’s done, you need to add the newly generated moc_MainWindow.cpp file (for this example) to your Code::Blocks project, and it’ll all compile and work as expected.

So good so far, but what happens when you add a new slot? Yup, you have to go and manually re-run the command on all header files to generate the new moc_<some-class>.cpp files before it’ll play ball again – well sod that, let’s automate it!

Quick & Dirty Pre-Processing via Bash

I’m sure there are better ways of invoking the moc as a pre-build script, but I don’t know enough about pre-processing scripts to get it working (however, you might like to read this and have more luck than I did) – so I knocked together a quick bash script to generate all the moc files for us, like this:

genQtMoc Script

# Script to generate Qt moc files for all headers in the current directory | 16/06/2011 | r3dux
#
# For each header file in the current directory...
for file in ./*.h; do
 
	# If a file exists with a given extension...
	if [ -e "$file" ]; then
 
		fileWithoutPath=$(basename $file)
 
		nameWithoutExtension=${fileWithoutPath%.*}
 
		mocName=moc_$nameWithoutExtension.cpp
 
		moc "$file" -o "$mocName"
 
	fi # End of if file exists condition				
 
done # End of for each file loop

This is fine if all your .cpp and .h files are in the same folder like the project root, but if you’ve split them off into include and src directories you’ll have to twiddle the script a little to take that into account.

Putting it to work

Once you’ve put the script into a file called genQtMoc or such, and made it executable with chmod +x genQtMoc, sling it somewhere in the path like /usr/local/bin/ and we can then call for it to be executed as a pre-build script in Code::Blocks by going to Project | Build options… | Pre/post build steps and just putting the name of the script to call in the pre section, like this:

Code::Blocks Pre-Build Script

All sorted – the only other thing to re-iterate is that you need to have each moc_<some-file>.cpp file attached to your project, and that if you have the file open for editing in Code::Blocks, it’ll moan that “the file has been changed externally, would you like to reload it?” each time its contents change. You can get around this by simply not having the file open for editing (but still included in your project), which stops the annoying pop-up from occurring and is fine as it’s an auto-generated file that shouldn’t really be hand-edited anyway.

Anyways, I hope this helps anyone stuck in a similar situation – and please, if you do know a better of way of going about this, I’d love to hear about it. Cheers!

Comments
2 Comments »
Categories
Coding, Linux
Tags
C++, Macro, moc, pre-process, Qt, Q_OBJECT, script, Slot
Comments rss Comments rss
Trackback Trackback

Child of Eden

r3dux | June 17, 2011

New on-rails-rhythm-shooter-thingy Child of Eden (from Tetsuya Mizuguchi the same guy who designed Rez, no less) is looking pretty darn nifty, especially with Kinect controls. Though quite how long you’ll last without your arms getting tired is quite another matter.

YouTube Preview Image

If you’ve never played or heard of Rez – it has to be one of the most beautiful and original games ever made. Originally for the Dreamcast, it has a HD remake on the 360 (via XBox Live Arcade), and is just great. Also, it has one of the easiest control schemes ever, meaning pretty much anyone can play it even if they’re not used to game controllers. You move the targeting reticule around (up/down/left/right), and hold down or hammer the fire button. If you’re holding the button down, anything that passes through the reticule is targeted (up to 8 things, or 8 shots on the same thing, or any combination), and when you release the button, up to eight shots shoot off and hit stuff. All perfectly timed to each levels unique techno/house/ambient soundtrack. Brilliant!

YouTube Preview Image

See? If Child of Eden is Rez 2.0, then I definitely want some :)

Also, and I only just noticed this – but I posted about the track California Soul by Marlena Shaw (or a remix thereof) the other day – and guess what the music in the latter half of the Rez video samples? I knew I’d heard it somewhere before! How’s that for serendipity?

Comments
No Comments »
Categories
Gaming, Imagery
Tags
Child of Eden, Kinect, Rez, Tetsuya Mizuguchi, Trippy
Comments rss Comments rss
Trackback Trackback

How to: Get absolute/relative file paths, filenames and extensions from a Bash script

r3dux | June 16, 2011

I’ve been learning some Qt stuff today, and the resulting code requires pre-processing of header files to work correctly, which I thought I’d try to automate. As part of this, I needed to find out how to get at all the different elements of a file from a bash script, so I did some googling and got all the info I needed :)

The script itself isn’t particularly useful, but the component parts of how to get at paths, extensions, and plain filenames without extensions definitely is – check it out:

fileParts Shell Script

# Bash script to get filename details | 16-06-2011 | r3dux
# Usage: fileParts <extension-with-no-dot> i.e. fileParts cpp
 
# For each file with the given extension in the current directory...
for file in ./*.$1; do
 
	# If a file exists with a given extension...
	if [ -e "$file" ]; then
 
		fullPath=$(readlink -f "$file")
		echo "Full path and filename          is: " $fullPath
 
		echo "Relative path and filename      is: " $file
 
		fileWithoutPath=$(basename $file)
		echo "Filename only                   is: " $fileWithoutPath
 
		extension=${fileWithoutPath##*.}
		echo "File extension only             is: " $extension
 
		fileWithoutExtension=${fileWithoutPath%.*}
		echo "Filename only without extension is: " $fileWithoutExtension
 
		echo
	else
		echo "No files of type $1 found!"
		exit 0
 
	fi # End of if file exists condition				
 
done # End of for each file loop

I created two dummy “.h” files in my home folder and ran the script – this is what it outputs:

r3d2@r3dux-Aspire-8920:~$ ./fileParts h
Full path and filename          is:  /home/r3d2/a-simple-test-file.h
Relative path and filename      is:  ./a-simple-test-file.h
Filename only                   is:  a-simple-test-file.h
File extension only             is:  h
Filename only without extension is:  a-simple-test-file
 
Full path and filename          is:  /home/r3d2/file.with.lots.of.dots.h
Relative path and filename      is:  ./file.with.lots.of.dots.h
Filename only                   is:  file.with.lots.of.dots.h
File extension only             is:  h
Filename only without extension is:  file.with.lots.of.dots

That’s gotta come in useful, right? =D

Comments
No Comments »
Categories
Coding, How-To
Tags
Absolute, Bash, Extension, Filename, Path, Relative, script, Shell
Comments rss Comments rss
Trackback Trackback

Gillian Welch and David Rawlings – Black Star (Radiohead Cover @ Bonnaroo 2007)

r3dux | June 12, 2011
YouTube Preview Image

Fair play, I think they really find the inner beauty of the song. Just brilliant.

Here’s a version with better quality audio from 2004 (live in Minneapolis) which I can’t find on YouTube – just thought the version with the video was something worth seeing…

Audio clip: Adobe Flash Player (version 9 or above) is required to play this audio clip. Download the latest version here. You also need to have JavaScript enabled in your browser.

Comments
No Comments »
Categories
Music
Tags
Acoustic, Black Star, Cover, David Rawlings, Gillian Welch, Radiohead
Comments rss Comments rss
Trackback Trackback

« Previous Entries Next Entries »

Translate

Categories

Archives

Tags

3D ActionScript ActionScript 3.0 Adobe AI Ballarat Bash C++ Class Convert CS4 Effect Error Film Flash GLSL Gnome Hack How-To install Jaunty Java Kinect Linkage Linux Mash-Up Microsoft Motion OpenGL Particle Problem PS3 Remix Retro script Slides Sound Systems Texture Ubuntu Video VirtualBox Wii Windows XBox

Gamercard

OpenR3dux

Misc.

Flattr this

RSS Feed

r3dux twitter feed



“Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.”

 - Scott Adams

rss Comments rss valid xhtml 1.1 design by jide powered by Wordpress get firefox