Sunday, November 29, 2009

Tut 3: JACK Audio Connections!

Hey all,

Today its Audio Input time. Lets get to it:

1. Start a new project, I named mine JackGtkmm
2. Download my main.cpp file from here

Link the jack library, and the Gtkmm library to your project.
Click compile, should work without any bother..?!

The code should be ok, read through it, i can update it if theres
any criticism, or I should explain something better.

There's a couple of small exercises in the comments, or hints as to
how to improve the code. There's one way to learn programming,
learn by doing. Enjoy!

PS: The current version only connects the Left input and output ports automatically. See if you can get the right ones to "Auto-Connect" too.

Monday, November 2, 2009

Tut 2: Simple Gtkmm Window

Ok guys, I'm jumping straight to the chase, no program design tutorial, no "basics" of anything, were going to display a simple "hi" box.

GTK+ is a GUI toolkit. That means you build Graphical User Interfaces with it, and that's what were going to do. If you don't understand a certain aspect of this code/tutorial, please let me know so I can improve the content.

#include <gtkmm/main.h>
#include <gtkmm/window.h>
#include <gtkmm/button.h>

int main (int argc,char *argv[])
{
Gtk::Main kit(argc, argv);
Gtk::Window window;
Gtk::Button button;

button.set_label("This is a GTK+ GUI");

window.add(button);
window.set_border_width(10);
window.set_default_size(300,150);
window.set_position(Gtk::WIN_POS_CENTER);

window.show_all();

kit.run(window);

return 0;
}


I'm assuming that you can set up the enviroment as per the "Hello World" tutorial. Then put that code into your main.cpp file. If you try running now, MonoDevelop will probably tell you this:


Why does this not work? That has to do with how C++ works. When we compile code, we transform the code into something called an Object file. These files end in .o These .o files are then "linked" with libraries that we've used, to create an "executable" which we can then run on the computer.

What's going wrong here, is that we have used GTKmm in our code, (see the #includes), but we havent told MonoDevelop that we want it to link to GTKmm for our exectuable. So that's all we've got to do.

On the left, there should be "pane" showing this:

If that's not there on your left, make sure that the "solution" tab is selected (bottom left).

Now right click on the "Packages" item (as per 2 pictures up), select "Edit Packages" from the right-click menu, and a popup box should appear:


If the "gtkmm" item isnt in your list, that's ok! That means you don't have the gtkmm-dev packages installed. Lets go to Synaptic (or your favorite package manager), and search for GTKmm. The following are my results, if yours are a bit different that's ok. If gtkmm-dev isnt in that list either, get in contact with somebody that knows your setup or email me!



Just install that package (& its dependencies), go back to MonoDevelop, try to add the package and this time it should be there. Now click Debug in MonoDevelop (or hit F5), and it should pop up a little box with a button in the middle..! Kinda like this one:


Now the colours might be different, it might have a different name on top, but it should run!
Any problems, please comment! Congrats on your Gtkmm GUI app!
Till next post, -Harry

Tut 1: (Optional) Setting up a C++ IDE: MonoDevelop

Hey all,

In this tutorial I'm hoping to get a fully working "Hello World" program set up, and working from scratch. So for this tutorial to work 100% you'll need to be using the same version of Linux. I'm currently using AvLinux, which is based on Debian.

All
derivates of Debian should work without any hassle, however as everyone has a different version of a piece of software, there will be small differences! Any version of linux should work, you might just need to adjust certain things.

So to install MonoDevelop, lets go to the Synaptic Package Manager, search for MonoDevelop,

and tick the monodevelop entry. Allow it to install all dependencies if it needs any. Let it download & install, it should just install as any other software does on your system.

*Launch MonoDevelop, just like any other program from the menu.

*This should bring you to the main MonoDevelop screen.
*In the center of the Welcome Page, click on "Start a new Solution".
*The following should appear,
fill in any Solution name you want.

*Create a new File (Top left: there's a "new" icon), and enter the following cod
e:
#include <iostream>

int main ()
{

std::cout << "Hello World" << std::endl;
return 0;

}

* Now press F5, or else click on the Button with the pop-up "Debug (F5)".
This should show Hello World in the "Application Output" window at the bottom of the MonoDevelop Window.

Congrats, you've set up your enviroment & compiled C++. Now for the fun stuff..!
Till next time, -Harry

Linux Audio Programming - C++

Hey all,

Just thought I'd let everyone know that I intend to do a "basics" programming tutorial set, using mainly C++ and the GTK+ toolkit. I'm not a pro by any means, I'm self thought so there are definatly some aspects of the code I write that I couldnt explain properly. Despite this, due to the lack of C++ Linux audio programming tutorials for Beginners, I'm going to try my hand at explaining some core concepts & putting them to use.

So far, I've coded in Python which is quite a nice introductory language, and now I've moved on to C++. This is a bit of a step regarding data types & variables, and compiling.

I'm going to assume basic knowledge of C++. Ie: You can write a "Hello World" program yourself, compile & run it successfully. If you havent reached this stage yet, learnCpp.com should get you set!

Cheers & Till next time, -Harry