Monday, September 21, 2009

Reading RSS feeds in GNU screen

As a lot of system administrator I use GNU screen most of the time.

GNU screen is a really wonderfull tool to keep your working sessions along days.

Screen can be configured to have a status line witch can display various standard format strings. A particularly useful configuration directive is the backtick directive. This directive allows to run a custom command and update the hardstatus line each time the command emit a new line.

Using this features I developped screenfeeder: an rss reader witch can display rss feed into my harstatus line.

Configuring your ~/.screenrc

Here is my hardstatus and backtick configuration:

#Run the rss reader as #42 backtick 
backtick 42 0 0 "/home/fv/.screenfeeder/screenfeeder" "/home/fv/.screenfeeder/feeds"
# CTRL+A f open the webbrowser to the current feed entry url
bind f screen -t 'rss_feed' 10 /home/fv/.screenfeeder/screenfeeder
# display the #42 backtick in the hardstatus line 
hardstatus alwayslastline "%{+b kw}%H%{kg}|%c|%42`|%{ky}%d.%m.%Y|%{kr}(load:%l)%-0=%{kw}"

Copy the screenfeeder script into ~/.screenfeeder/screenfeeder
Put your favorits feeds into ~/.screenfeeder/feeds like this (one feed per line):

http://www.openframeworks.cc/forum/rss.php
http://www.lemonde.fr/rss/une.xml
http://linuxfr.org/backend/news/rss20.rss

The script works by saving the current url into a file named ~/currenturl-. The pid of the parent process id (the current screen process id). When screenfeeder is invoked without arguments from the same screen process it calls the webborowser module to open the url stored in this file by gessing the parent process id.

As a result. When you use CRTL-a f shortcut, the browser should open the current item.


screenfeeder demo:


Screenfeeder from dopuskh3 on Vimeo.


References:
screen manual page
screenfeeder project page on github

Saturday, September 19, 2009

Building OpenFrameworks with CMake

Why ?

Openframework programs can be hard to build particulary when you are not using XCode or Code::Blocks.

I personally use linux (ubuntu) and prefer to use my favorite editor (vim) to program.


I decided a long time ago to create a CMake skeleton to be able to build openframeworks easily. I choosed to use CMake because i thought it could be useful - one day - for the ofx community where most of people are using XCode or Code::blocks. CMake can generate C::B and Xcode project files.

Prerequist

You can download OpenFrameworks CMake skelton on my github page.


git clone git://github.com/dopuskh3/ofx-cmake-build.git  
  

Edit CMakeBase.txt

This file provides all necessary checks to build openframeworks source code:

  • finds necessary include files
  • finds libraries (fmodex, poco, unicap...)
Edit this file to reflect your system configuration an openframworks sourcecode. Here is my configuration:
#######################################################################################################
########### Configuration Vars #########################################################################
########################################################################################################

# The path where stants openFrameworks's sources
set ( ofx_sources_directory "/home/fv/Dev/openFrameworks/ofx-dev/libs/openFrameworks" )

# Additional include directories 
set ( custom_include_dirs "/usr/include/libavformat;/usr/include/libavcodec;/usr/include/libswscale")

# Poco include path where to find Poco/Poco.h and libPocoFoundation                                                            
set (poco_includes "/usr/include" )
set (poco_libdir " ")

# GLee include path 
set (glee_includes "/home/fv/Dev/openFrameworks/ofx-dev/libs/GLee/include" )
set (glee_libdir   "/home/fv/Dev/openFrameworks/ofx-dev/libs/GLee/lib" )

# FModex 
set (fmodex_includes "/home/fv/Dev/openFrameworks/ofx-dev/libs/fmodex/inc" )
set (fmodex_libdir   "/home/fv/Dev/openFrameworks/ofx-dev/libs/fmodex/lib/linux/" )

# RtAudio
set (rtaudio_includes "/home/fv/Dev/openFrameworks/ofx-dev/libs/rtAudio/include")
set (rtaudio_libdir   "/home/fv/Dev/openFrameworks/ofx-dev/libs/rtAudio/lib")

# FreeImage 
set ( freeimage_includes "/home/fv/Dev/openFrameworks/ofx-dev/libs/freeimage/include" )
set ( freeimage_libdir   "/home/fv/Dev/openFrameworks/ofx-dev/libs/freeimage/lib" )

# For linux only 
set (unicap_includes "/home/fv/Dev/openFrameworks/ofx-dev/libs/unicap/include")
set (unicap_libdir   "/home/fv/Dev/openFrameworks/ofx-dev/libs/unicap/lib")

set (asound_includes "")
set (asound_libdir "")

set (raw1394_includes "")
set (raw1394_libdir "")

....
  

Creating a project from scratch

Create a subdirectory to store your project:
cd ofx-cmake-build/
mkdir myOfxProject/
mkdir myOfxProject/src
  
Copy the provided CMakeFiles.txt into your project root directory. Edit this file to change the project name and add some dependencies:
cd myOfxProject/
cp /path/to/ofx-cmake-build/sampleProgram/CMakeFiles.txt . 
 
Edit your CMakeFiles.txt to suit your freshly created project.

CMakeFiles.txt:
cmake_minimum_required(VERSION 2.6)                                                                                            

# project name
project(myOfxProject)

# path to CMakeBase.txt file
include ( ../CMakeBase.txt ) 

# add ofx includes directories for dependencies defined in CMakeBase.txt
include_directories ( ${ofx_includes} ) 

file ( GLOB_RECURSE app_sources_files src/*)

add_executable( myOfxProject
    ${app_sources_files}
    ${OFX_SOURCE_FILES} ) # Defined in CMakeBase.txt

set ( libs ${ofx_libs}) # Defined in CMakeBase.txt

target_link_libraries(manoProut ${libs} )
  
You're now ready to build your project.
mkdir build
cd build
cmake ../
make 
  
By default cmake generate unix makefiles. You can use the -G switch to use another generator (Xcode, code::blocks...)

A more complicated example: Using addons

You may want to use available addons to build more complicated projects. I personally use ofxOpenCv for one of my project. ofxOpenCv addon depends on ofxVectorMath addon. You can copy both ofxOpenCv and ofxVectorMath addons sourcecodes in your project root. Your project layout should be like this:
ofxSampleProjectWithAddons
|-- ofxOpenCv
|   `-- src
|       |-- ofxCvBlob.h
|       |-- ofxCvColorImage.cpp
|       |-- ofxCvColorImage.h
|       |-- ofxCvConstants.h
|       |-- ofxCvContourFinder.cpp
|       |-- ofxCvContourFinder.h
|       |-- ofxCvFloatImage.cpp
|       |-- ofxCvFloatImage.h
|       |-- ofxCvGrayscaleImage.cpp
|       |-- ofxCvGrayscaleImage.h
|       |-- ofxCvImage.cpp
|       |-- ofxCvImage.h
|       |-- ofxCvMain.h
|       |-- ofxCvShortImage.cpp
|       |-- ofxCvShortImage.h
|       `-- ofxOpenCv.h
|-- ofxVectorMath
|   `-- src
|       |-- ofxMatrix3x3.cpp
|       |-- ofxMatrix3x3.h
|       |-- ofxPoint2f.cpp
|       |-- ofxPoint2f.h
|       |-- ofxPoint3f.cpp
|       |-- ofxPoint3f.h
|       |-- ofxPoint4f.cpp
|       |-- ofxPoint4f.h
|       |-- ofxVec2f.cpp
|       |-- ofxVec2f.h
|       |-- ofxVec3f.cpp
|       |-- ofxVec3f.h
|       |-- ofxVec4f.cpp
|       |-- ofxVec4f.h
|       `-- ofxVectorMath.h
`-- src
    |-- main.cpp
    |-- testApp.cpp
    `-- testApp.h

  


You can had your includes and library checks into the project.

CMakeFiles.txt:
cmake_minimum_required(VERSION 2.6)                                                                                            

project(ofxSampleProjectWithAddons)

include ( ../CMakeBase.txt ) 

# add ofx includes directories for dependencies 
include_directories ( ${ofx_includes} ) 

file ( GLOB_RECURSE app_sources_files src/*)

# VectorMath addon ##############################
# add VectorMath addon sourcecode
file ( GLOB_RECURSE ofxVectorMath ofxVectorMath/src/* )
# add includes path for this addon
include_directories ( ofxVectorMath/src/ )

# OpenCv addon ##################################
# add ofxOpenCv source code
file ( GLOB_RECURSE ofxOpenCv ofxOpenCv/src/* )
# add include path for this addon
include_directories ( ofxOpenCv/src/ )

# search for opencv library and includes using pkg-config 
include(FindPkgConfig)
pkg_search_module(cv opencv)
include_directories ( ${cv_INCLUDE_DIRS} )
#################################################

# create an executable with all source files
add_executable( ofxSampleProjectWithAddons
    ${app_sources_files}
    ${ofxOpenCv}
    ${ofxVectorMath}
    ${OFX_SOURCE_FILES} )

# link with cv libraries and openFrameworks dependencies
set ( libs ${ofx_libs} ${cv_LIBRARIES})
target_link_libraries(manoProut ${libs} )