MultimediaBigloo provides various facilities for programming multimedia applications. It provides functions for parsing images and sounds and functions for controlling music players. All the functions, variables, and classes presented in the document are accessible via the
multimedialibrary. Here is an example of module that uses this library:
;; Extract the thumbnail of a digital photography. (module thumbnail (library multimedia) (main main)) (define (main argv) (when (and (pair? (cdr argv)) (file-exists? (cadr argv))) (let ((ex (jpeg-exif (cadr argv)))) (when (exif? ex) (display (exif-thumbnail ex))))))
PhotographyThe multimedia library provides functions for accessing the metadata generated by digital camera.
jpeg-exif file-namebigloo multimedia procedureThe function
jpeg-exifextracts the EXIF (http://en.wikipedia.org/wiki/Exif) metadata of a JPEG file as created by digital camera. The argument file-name is the name of the JPEG file. If the file contains an EXIF section it is returned as an instance of the
exifclass. Otherwise, this function returns
jpeg-exif-comment-set! file-name textbigloo multimedia procedureSet the comment of the EXIF metadata section of the file file-name to text.
exifbigloo multimedia class
(class exif (version (default #f)) (jpeg-encoding (default #f)) (jpeg-compress (default #f)) (comment (default #f)) (commentpos (default #f)) (commentlen (default #f)) (date (default #f)) (make (default #f)) (model (default #f)) (orientation (default 'landscape)) (width (default #f)) (height (default #f)) (ewidth (default #f)) (eheight (default #f)) (xresolution (default #f)) (yresolution (default #f)) (resolution-unit (default #f)) (focal-length (default #f)) (flash (default #f)) (fnumber (default #f)) (iso (default #f)) (shutter-speed-value (default #f)) (exposure-time (default #f)) (exposure-bias-value (default #f)) (aperture (default #f)) (metering-mode (default #f)) (cdd-width (default #f)) (focal-plane-xres (default #f)) (focal-plane-units (default #f)) (thumbnail (default #f)) (thumbnail-path (default #f)) (thumbnail-offset (default #f)) (thumbnail-length (default #f)))The instance of the
exifclass maps the EXIF metadata found in JPEG files into Bigloo objects. Since all fields are optional they are untyped.
exif-date->datebigloo multimedia procedureParses an exif date, i.e., a string of characters, and returns corresponding date. Raises an &io-parse-error if the string does not represents an exif date whose syntax is given by the following regular expression:
MusicThe multimedia library provides an extensive set of functions for dealing with music. It provides functions for accessing the metadata of certain music file formats, it provides functions for controlling the volume of the hardware mixers and it provides functions for playing and controlling music playback.
Metadata and Playlist
read-m3u input-portbigloo multimedia procedure
write-m3u list output-portbigloo multimedia procedureThe function
read-m3ureads a playlist expressed in the M3U format from input-port and returns a list of songs. The function
write-m3uencode such a list encoded in the M3U format to an output port.
file-musictag file-namebigloo multimedia procedure
mp3-musictag file-namebigloo multimedia procedure
ogg-musictag file-namebigloo multimedia procedure
flac-musictag file-namebigloo multimedia procedureThese functions extract the metadata of a music file named file-name. The function
mp3-musictagreturns the ID3 tag section if it exists. Otherwise, it returns
#f. The function
flac-musictagreturns the vorbis comment if it exists.
musictagbigloo multimedia class
(abstract-class musictag (title::bstring read-only) (artist::bstring read-only) (orchestra::obj read-only (default #f)) (interpret::obj read-only (default #f)) (album::bstring read-only) (year::int read-only) (comment::bstring read-only) (genre::bstring read-only) (track::int (default -1)))This class is used as the base class of music tag formats.
id3::musictagbigloo multimedia class
(class id3::musictag version::bstring (orchestra::obj read-only (default #f)) (conductor::obj read-only (default #f)) (recording read-only (default #f)) (cd::obj (default #f)))This class is used to reify the ID3 metadata used in the MP3 format.
vorbis::musictagbigloo multimedia class
(class vorbis::musictag)This class is used to reify the Vorbis comments of OGG and Flac files.
MixerBigloo proposes various functions and classes for controlling the audio volume of sound cards.
mixerbigloo multimedia class
(class mixer (devices::pair-nil (default '())))The field devices is a list of available channels.
mixer-close mixbigloo multimedia procedureCloses a mixer. The argument mix must be an instance of the
mixer-volume-get mix channelbigloo multimedia procedure
mixer-volume-set! mix channel leftv rightvbigloo multimedia procedureThe function mixer-volume-get returns the left and right volume levels (two values) of the channel of the mixer mix. The channel is denoted by its name and is represented as a string of characters. The argument mix is an instance of the
mixerclass. The function mixer-volume-set! changes the audio level of a mixer channel.
soundcard::mixerbigloo multimedia class
(class soundcard::mixer (device::bstring read-only))The instances of the class
soundcard, a subclass of the
mixerclass, are used to access physical soundcard as supported by operating systems. The class field device stands for the name of the system device (e.g.,
"/dev/mixer"for the Linux OS). During the initialization of the instance, the device is opened and initialized.
PlaybackBigloo supports various functions for playing music. These functions rely on two data structure: music players and music status. The first ones are used to control player back-ends. The second ones are used to get information about the music being played. The following example shows how a simple music player using either MPlayer, MPG123, or MPC can be programmed with Bigloo.
(module musicplay (library multimedia) (main main)) (define (main args) (let ((files '()) (backend 'mplayer) (command #f)) (args-parse (cdr args) (("--mpg123" (help "Select the mpg123 back-end")) (set! backend 'mpg123)) (("--mpc" (help "Select the mpc back-end")) (set! backend 'mpc)) (("--mplayer" (help "Select the mplayer back-end")) (set! backend 'mplayer)) (("--command" ?cmd (help "Set the command path")) (set! command cmd)) (("--help" (help "This help")) (print "usage: music [options] file ...") (args-parse-usage #f) (exit 0)) (else (set! files (cons else files)))) ;; create a music player (let ((player (case backend ((mpg123) (if command (instantiate::mpg123 (path command)) (instantiate::mpg123))) ((mplayer) (if command (instantiate::mplayer (path command)) (instantiate::mplayer))) ((mpc) (instantiate::mpc))))) ;; fill the music play list (for-each (lambda (p) (music-playlist-add! player p)) (reverse files)) ;; start playing (music-play player) ;; run an event loop with call-backs associated to some events (music-event-loop player :onstate (lambda (status) (with-access::musicstatus status (state song volume) (print "state : " state) (print "song : " song))) :onmeta (lambda (meta) (print "meta : " meta)) :onvolume (lambda (volume) (print "volume : " volume))))))
musicbigloo multimedia abstract class
(abstract-class music (frequency::long (default 2000000))This abstract class is the root class of all music players.
musicproc::musicbigloo multimedia class
(class musicproc::music (charset::symbol (default 'ISO-LATIN-1)))This class is used to reify player that are run in an external process.
mplayer::musicprocbigloo multimedia class
(class mplayer::musicproc (path::bstring read-only (default "mplayer")) (args::pair-nil read-only (default '("-vo" "null" "-quiet" "-slave" "-idle"))) (ao::obj read-only (default #unspecified)) (ac::obj read-only (default #unspecified)))A player based on the external software
MPlayer. Creating such a player spawns in background a MPlayer process.
mpg123::musicprocbigloo multimedia class
(class mpg123::musicproc (path::bstring read-only (default "mpg123")) (args::pair-nil read-only (default '("--remote"))))A player based on the external software
mpc::musicbigloo multimedia class
(class mpc::music (hello read-only (default #f)) (host read-only (default "localhost")) (port read-only (default 6600)) (timeout read-only (default 10008993)) (prefix (default #f)))A MPC client.
hello: an optional string written when the connection is establish with the MPD server.
prefix: an optional path prefix to be removed from music playlist. This is needed because MPD can only play music files registered
in is private database. The file names used by MPD are relative a
root directory used to fill the database. The
prefixfield allows programmer to write portable code that manages play list file names independently of the player selected.
musicstatusbigloo multimedia class
(class musicstatus (state::symbol (default 'stop)) (volume::obj (default -1)) (repeat::bool (default #f)) (random::bool (default #f)) (playlistid::int (default -1)) (playlistlength::int (default 0)) (xfade::int (default 0)) (song::int (default 0)) (songid::int (default 0)) (songpos (default 0)) (songlength::int (default 0)) (bitrate::int (default 0)) (khz::int (default 0)) (err::obj (default #f)))The instances of the class
musicstatusdenote that state of a player.
music-close musicbigloo multimedia procedure
music-reset! musicbigloo multimedia procedure
music-closed? musicbigloo multimedia procedureCloses, resets, and tests the state of a music player.
music-playlist-get musicbigloo multimedia procedure
music-playlist-add! music songbigloo multimedia procedure
music-playlist-delete! music intbigloo multimedia procedure
music-playlist-clear! musicbigloo multimedia procedureThese functions controls the playlist used by a player. Note: The song argument is an UTF8 encoded string (see Section Unicode (UCS-2) Strings) whatever the local file system encoding is. The function
music-playlist-getreturns a list of UTF8 encoded names.
music-playlist-get: returns the list of songs (UTF8 names) of the current playlist.
music-playlist-add!: adds an extra song (UTF8 name) at the end of the playlist.
music-delete!: removes the song number int from the playlist.
music-clear!: erases the whole playlist.
music-play music [song]bigloo multimedia procedure
music-seek music time [song]bigloo multimedia procedure
music-stop musicbigloo multimedia procedure
music-pause musicbigloo multimedia procedure
music-next musicbigloo multimedia procedure
music-prev musicbigloo multimedia procedureThese functions changes the state of the music player. The function
music-seekseeks the playback position to the position time, which is an integer denoting a number of seconds.
music-crossfade music intbigloo multimedia procedure
music-random-set! music boolbigloo multimedia procedure
music-repeat-set! music boolbigloo multimedia procedureThese functions controls how songs playback should follow each other.
music-volume-get musicbigloo multimedia procedure
music-volume-set! music volbigloo multimedia procedureGet and set the audio volume of a player. Some player use the native mixer supported by the operating system some others use a software mixer unrelated to the hardware.
music-status musicbigloo multimedia procedure
music-update-status! music statusbigloo multimedia procedureThe function
music-statusreturns an instance of the
musicstatusclass which denotes the state of the player. The function
music-update-status!updates this status.
music-song musicbigloo multimedia procedure
music-songpos musicbigloo multimedia procedureThese two functions return the number of the song being played and the position in the song. These functions are somehow redundant with the function
music-statusbecause the status also contains information about the playback song and playback position. However, for some players getting the music song and the playback position is cheaper than getting the whole player status.
music-meta musicbigloo multimedia procedureReturns the metadata the current song.
music-reset-error! musicbigloo multimedia procedureReset the previous errors detected by a player.
music-event-loop music [:onstate] [:onmeta] [:onerror] [:onvolume]bigloo multimedia procedureThe function
music-event-loopenable event notifications when the state of a player changes. The keyword arguments are:
:onstate, a function of one parameter. When the player state changes, this function is called with an instance of
:onmeta, a function of two parameters. This function is called when a metadata is detected in the music currently played.
:onerror, a function of one parameter, invoked when an error is detected.
:onvolume, a function of one parameter, invoked when the volume changes.
musicstatusas first actual parameter.
Music Player DaemonMusic Player Daemon (MPD in short) allows remote access for playing music http://www.musicpd.org. MPD is designed for integrating a computer into a stereo system that provides control for music playback over a local network. The Bigloo class
mpdclient. All Bigloo players can be access via the MPD protocol, using the The following example shows how to access a MPlayer music player using the MPD protocol with a simple Bigloo program:
(module mpd (library multimedia pthread) (main main)) (define (main argv) (let ((db (instantiate::mpd-database (directories (cdr argv)))) (serv (make-server-socket 6600)) (music (instantiate::mplayer))) (let loop () (thread-start! (make-mpd-connection-thread music db sock)) (loop)))) (define (make-mpd-connection-thread music db sock) (instantiate::pthread (body (lambda () (let ((pi (socket-input sock)) (po (socket-output sock))) (input-timeout-set! pi 10000) (output-timeout-set! po 10000) (unwind-protect (mpd music pi po db) (socket-close sock)))))))
mpd music input-port output-port database [:log]bigloo multimedia procedureThe function
mpdimplements a MPD server. It reads commands from the input-port and write results to output-port. The argument database, an instance of the
mpd-databaseclass, describes the music material that can be delivered by this player.
mpd-databasebigloo multimedia class
(class mpd-database (directories::pair-nil read-only)The field
directoriescontains the list of the directories that contains music files.
ColorThe multimedia library provides functions for dealing with colors.
hsv->rgb h s vbigloo multimedia procedure
hsl->rgb h s lbigloo multimedia procedure
rgb-hsv r g bbigloo multimedia procedure
rgb-hsl r g bbigloo multimedia procedureThese procedures converts from and to HSV, HSL, and RGB representations. The argument h is an integer in the range
[0..360], the arguments s, v, and l in the range
[0..100]. The arguments r, g, and b are in the range
[0..255]. These procedures returns multiple-values.
(multiple-value-bind (r g b) (hsv->rgb 340 34 56) (list r g b)) ⇒ (143 94 110) (multiple-value-bind (h s v) (rgb->hsv 255 0 0) (list h s v)) ⇒ (0 100 100)