Close

Software documentation

A project log for eXaDrums

Electronic drums for Linux

jeremyJeremy 10/15/2016 at 15:160 Comments

This project log is a brief software documentation and will be completed regularly until a user manual has been written.

eXaDrums Library

The eXaDrums library, or libeXaDrums, is a shared library (.so). It contains all the functions that are needed to run and control the drum module, kits manager, and more. As it will be explained in this section, if you can compile the library, it's really easy for you to use it in your own C++ program.

Dependencies

In order to compile and use libeXaDrums, you need to install some other libraries first. Don't worry, only one of them isn't included in Raspbian/Ubuntu. To install the dependencies that are part of your linux distribution, you need to execute this command line:

sudo apt-get install libasound2-dev libtinyxml2-dev

Now you need to install the bcm2835 library. It's relatively easy, you just have to download the library, and type the following into a terminal:

cd bcm2835-1.50 
./configure 
make 
sudo make install

If you want to run the software on your laptop or PC instead of the Raspberry Pi, you need to patch the library first. To do so, you first need to download this patch (which works for version 1.46), and type the following into the terminal (replace path/to/patch by the patch's folder):

cd bcm2835-1.50 
cp path/to/patch/bcm2835.patch src/ 
./configure 
cd src 
patch Makefile bcm2835.patch 
cd .. 
make 
sudo make install

Get source code, and compile the library

The source code has been written in C++11, and compiled using Eclipse CDT. However, you don't need Eclipse to compile the library. So, first of all, you need to get the code. It's available on Github, where you can download the whole project as a zip file. Unzip the file, and open a terminal in the library's directory. Then, type this to compile the release version:

cd Release 
make clean 
make -j4 all

Alternatively, you can replace the first line by cd Debug, to compile the debug version. The -j4 option specifies how many threads should be used to compile the project, if you have a dual core CPU, it's usually 4, if it's a quad core, it probably is 8.

Now in the Release directory (or Debug if you built the debug version), you should see a file named libeXaDrums.so. That's the library that contains all the functions of the eXaDrums software.

Use the library

It's a good thing to be able to compile the library, but it's even better to be able to use it. In order to use the Api, you need to compile the library, but also to get the eXaDrums.h file that contains the definition of the eXaDrums Api. This file is located in the Api folder, and needs to be included in your source code. By doing so, you get the namespace eXaDrumsApi that contains the class eXaDrums. You then just need to use that class. For more details, please refer to the Api Documentation section. There's one more thing that you need to do. At compile time you have to link libeXaDrums to your program. Example:

g++ -o "YourProgram" ./Source/file1.o ./Source/file2.o ./Source/file3.o -leXaDrums 

The '-leXaDrums' is where your link the library. That means that your linux distribution know where to find the library. So you have to add it to the path, or to copy 'libeXaDrums.so' to a known location. I usually do the following:

sudo cp libeXaDrums.so /usr/lib/

Api Documentation

If you were able to compile the library, you can use it in your C++ programs. However, there are a few things that you need to know to use the library. These things are described below.

How to use the class

So, like I said before, the class in defined in the eXaDrumsApi namespace. It is actually pretty easy to use, but I recommend you declare the class as a private member of one of your classes, and you wrap it in a smart pointer. In the GUI, eXaDrums is a private member of the Gui class, and it is defined like that:

std::shared_ptr drumKit;

To instantiate the class, you need to specify the 'Data' folder's location which leads us to something like that:

std::string moduleLocation("./Data/"); 
drumKit = std::shared_ptr(new eXaDrums(moduleLocation.c_str()));

Start and stop drum module

Once you've loaded the drum kit, it's pretty easy, you just need to use the start and stop functions of the Api: drumKit->Start(); starts the drum kit, and drumKit->Stop(); stops it.

Graphical User Interface

Because eXaDrums is a shared library, it's a lot easier to reuse in any other C++11 program. The Gui is also developed in C++11 and uses Gtkmm 3. That makes it compatible with a lot of linux distributions.

Dependencies

In addition to the eXaDrums library dependencies, you also need to install gtkmm developer's package:

sudo apt-get install libgtkmm-3.0-dev

And that's all you need. You can now compile the software.

Compile and use with the library

In order to compile the eXaDrums Gui, you need to have eXaDrums library compiled and installed. Once again, you can get the source code on Github. The program needs eXaDrums library, which you can download from Github as well. If you put both projects folders in the same directory, compiling eXaDrums is fairly easy. For instance, here's the script that I use to compile eXaDrums in release mode:

git clone https://github.com/SpintroniK/libeXaDrums.git 
git clone https://github.com/SpintroniK/eXaDrums.git

cd libeXaDrums/Release/ 
make clean 
make -j4 all 
sudo cp libeXaDrums.so /usr/lib/ 
cd ../.. 
cd eXaDrums/Release/ 
make clean 
make -j4 all

The executable file is then located in eXaDrums/Release.

Discussions