.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "pods::SDLx::Music 3pm" .TH pods::SDLx::Music 3pm 2024-01-10 "perl v5.38.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME SDLx::Music \- A powerful, convenient interface to "SDL::Mixer::Music" .SH CATEGORY .IX Header "CATEGORY" Extension .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 2 \& use SDL; \& use SDLx::Music; \& \& my $music = SDLx::Music\->new; \& \& #define music data with just a name and file path \& $music\->data( \& fast => \*(Aqmusic/fast.ogg\*(Aq, \& slow => \*(Aqmusic/slow.ogg\*(Aq, \& magical => \*(Aqmusic/magic/cake.ogg\*(Aq, \& ); \& \& #define more the long way with a parameter hash \& $music\->data( \& squelch => { \& file => \*(Aqmusic/squelch.ogg\*(Aq, \& loops => 3, \& fade_in => 0.5, \& volume => 72, \& } \& splurge => { \& file => \*(Aqmusic/splurge.ogg\*(Aq, \& finished => sub { print \*(AqSplurged!\*(Aq }, \& }, \& ); \& \& #instead, do it the short way with the help of defaults \& \& #clobber everything \& $music\->clear; \& \& #specify the class\-wide default for file extension \& SDLx::Music\->default\->ext(\*(Aq.ogg\*(Aq); \& \& #specify the object\-wide default for file directory \& $music\->default\->dir(\*(Aqmusic/\*(Aq); \& \& #redefine squelch and splurge \& $music\->data( \& squelch => { \& #file defaults to the data name, so the path becomes \& #\*(Aqmusic/squelch.ogg\*(Aq, which is what we wanted \& loops => 3, \& fade_in => 0.5, \& volume => 72, \& } \& splurge => { \& finished => sub { print \*(AqSplurged!\*(Aq }, \& }, \& ); \& \& #and we can redefine the others like this \& $music\->data_for( \& \*(Aqfast\*(Aq, \& \*(Aqslow\*(Aq, \& )\->data( \& magical => \*(Aqmagic/cake\*(Aq, \& ); \& \& #get to that named data \& my $splurge = $music\->data(\*(Aqsplurge\*(Aq); \& \& #and add to/modify it without clobbering existing data \& $splurge \& \->volume(55) \& \->file(\*(Aqdata/\*(Aq . $splurge\->file) \& ; \& \& #play it once, fading in for 2 seconds \& $music\->play($splurge, loops => 1, fade_in => 2); \& #(it will be loaded automatically and played with its specified params) \& \& sleep 5; \& \& #pause it \& $music\->pause if $music\->playing; \& \& #load everything else \& $music\->load; \& \& #resume playing it at a lower volume \& $music\->volume(44); \& $music\->play; \& \& #get the names for all music \& my @names = keys %{ $music\->data }; \& \& for my $name (@names) { \& #play it in an infinite loop \& $music\->play($name, loops => 0); \& warn "Cake!" if $music\->playing eq "magical"; \& sleep 10; \& } \& \& #fade out the last song \& $music\->fade_out(5); \& \& sleep 4; \& \& die "CAKE!" if $music\->fading\->name eq "magical"; \& \& sleep 1; .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" This class provides a powerful and convenient interface to SDL::Mixer::Music. The main goal was to make music code neater and clearer. Among the things that help this, this class provides class-wide and object-wide defaults and it automatically shares duplicate use of the same files. .PP The following document is intended for reference. For a more beginner-friendly description of this class, see chapter X of the SDL Perl Manual (when it is written). .PP \&\fBPlease note:\fR do not mix use of this class with SDL::Mixer::Music if you want everything to work right. .SH METHODS .IX Header "METHODS" .SS new .IX Subsection "new" .Vb 3 \& SDLx::Music\->new; \& #Option arguments showing the default parameters \& SDLx::Music\->new( freq => 44100, format => SDL::Audio::AUDIO_S16SYS, channels => 2, chunksize => 4096); .Ve .PP Creates the new music object. Inits audio with a call to SDLx::Mixer::init, if it isn't already (if you want more precise control over what is initialized, make sure you call SDLx::Mixer::init before you call this method). Creates an empty default data object for object-wide defaults. If arguments are supplied, calls "data" with them to set up any initial data objects. Returns the new music object. .SS data .IX Subsection "data" .Vb 4 \& $music\->data; \& $music\->data( $name ); \& $music\->data( $data ); \& $music\->data( %args ); .Ve .PP With no arguments: returns a reference to the data hash. This hash has data names as keys and the associated data objects as values. .PP With a name: creates the data name if it doesn't already exist. Does this with a call to SDLx::Music::Data\-new|SDLx::Music::Data/new> with \f(CW\*(C`name =\*(C'\fR \f(CW$name\fR> and puts that new object in the data hash under the key of \f(CW$name\fR. Returns the data object for that name. .PP With a hash of arguments: for each pair, and returns a SDLx::Music::Data. Returns \f(CW$music\fR. .SS data_for .IX Subsection "data_for" .Vb 1 \& $music\->data_for( @names_or_data_objects ); .Ve .PP Calls "data" repeatedly, passing it one element of the list at a time, to initialise multiple empty names and/or add data objects. Returns \f(CW$music\fR. .SS has_data .IX Subsection "has_data" .Vb 3 \& $music\->has_data; \& $music\->has_data( $name ); \& $music\->has_data( $data ); .Ve .PP Without arguments: returns how many data objects the class has. .PP With a name: returns the data object for \f(CW$name\fR. If there is no data object for \f(CW$name\fR it is not created and undef is returned instead. .PP With a data object: does a (slowish) reverse of the data hash to see if the data object belongs to \f(CW$music\fR. Returns it or undef. .SS default .IX Subsection "default" .Vb 2 \& $music\->default; \& SDLx::Music\->default; .Ve .PP Returns the default data object belonging to \f(CW$music\fR (created in "new"), or to the class. See SDLx::Music::Data for information on how defaults work. .SS load .IX Subsection "load" .Vb 3 \& $music\->load; \& $music\->load( @names_or_data_objects ); \& SDLx::Music\->load( @data_objects ); .Ve .PP Without arguments: for every data object belonging to \f(CW$music\fR, if the data object doesn't already have a loaded file, loads the file named by dir, file and ext if it hasn't been loaded already. Sets the data object's loaded parameter to this. Two or more objects that use the same file will use the same loaded file. Reference counting is respected, so if two data objects use the same loaded file it will be removed from memory only after both are destroyed. Returns <$music>. .PP With arguments: does the same, but only for the names or data objects in the list. If there isn't a data object for any name, it will be created. .SS unload .IX Subsection "unload" .Vb 3 \& $music\->unload; \& $music\->unload( @names_or_data_objects ); \& SDLx::Music\->unload( @data_objects ); .Ve .PP Without arguments: clears the loaded parameter for all of the data objects in \f(CW$music\fR. The loaded file is removed from memory if it loses its last reference to it. Returns <$music>. .PP With arguments: does the same, but only for the names or data objects in the list. Doesn't create a data object for a name that doesn't exist. .SS clear .IX Subsection "clear" .Vb 2 \& $music\->clear; \& $music\->clear( @names ); .Ve .PP Without arguments: empties \f(CW$music\fR's data hash of all of its objects. The objects will be destroyed only if the last reference to them is removed, and no parameters will be cleared if this is not the case. Returns \f(CW$music\fR. .PP With arguments: does the same, but only deletes the values of the data hash for the names in the list. .SS real_clear .IX Subsection "real_clear" .Vb 3 \& $music\->real_clear; \& $music\->real_clear( @names_or_data_objects ); \& SDLx::Music\->real_clear( @data_objects ); .Ve .PP The full, brute force version of "clear". .PP Without arguments: empties out the parameters of every data object in \f(CW$music\fR (including "unload"ing them) and then removes them from the data hash. This may not remove the objects from memory if there are still remaining references to them, but it is the closest thing to it. Returns \f(CW$music\fR. .PP With arguments: does the same, but only clears out the names or data objects in the list. .SS play .IX Subsection "play" .Vb 3 \& $music_or_class\->play; \& $music\->play( $name, $params ); \& $music_or_class\->play( $data, %params ); .Ve .PP Without arguments: resumes any paused music. Returns the object or class. .PP With arguments: plays the sound found in \f(CW$music\fR's \f(CW$name\fR, or in \f(CW$data\fR (depending on which is specified). "load"s it if it needs to be loaded (which in turn creates the name if it needs to be created). The \f(CW%params\fR are all optional and, if defined, are used instead of the values returned by the data object's parameter methods. The accepted parameters here are: .IP loops 4 .IX Item "loops" Plays the music file \f(CW\*(C`loops\*(C'\fR times. If \f(CW\*(C`loops\*(C'\fR is 0, loops it infinitely. .IP fade_in 4 .IX Item "fade_in" Fades the music in for its first \f(CW\*(C`fade_in\*(C'\fR milliseconds, if \f(CW\*(C`fade_in\*(C'\fR is defined. .IP vol 4 .IX Item "vol" Sets the music volume to \f(CW\*(C`vol\*(C'\fR. .IP vol_portion 4 .IX Item "vol_portion" Multiplies the \f(CW\*(C`vol\*(C'\fR by \f(CW\*(C`vol_portion\*(C'\fR (values from 0 to 1 are encouraged) before setting the volume. .IP pos 4 .IX Item "pos" Sets the music position to \f(CW\*(C`pos\*(C'\fR if \f(CW\*(C`pos\*(C'\fR is defined. .PP Returns the object or class. .SS pause .IX Subsection "pause" .Vb 1 \& $music_or_class\->pause; .Ve .PP Pauses any playing music. Returns the object or class. .SS stop .IX Subsection "stop" .Vb 1 \& $music_or_class\->stop; .Ve .PP Stops any playing music. Returns the object or class. .SS last_played .IX Subsection "last_played" .Vb 1 \& my $last_played = $music_or_class\->last_played; .Ve .PP Returns the data object that was "play"ed last. .SS playing .IX Subsection "playing" .Vb 1 \& my $playing = $music\->playing; .Ve .PP If there is something playing, returns the data object that was "play"ed last. Otherwise, returns undef. .SS paused .IX Subsection "paused" If there is something paused, returns the data object that was "play"ed last. Otherwise, returns undef. .SS fading .IX Subsection "fading" If there is something fading, returns the data object that was "play"ed last. Otherwise, returns undef. .SS volume .IX Subsection "volume" .Vb 2 \& my $volume = $music_or_class\->volume; \& $music_or_class\->volume( $volume ); .Ve .PP Without arguments: returns the current music volume .PP With arguments: Sets the music volume to \f(CW$volume\fR. Returns the object or class. .SS fade_out .IX Subsection "fade_out" .Vb 1 \& $music_or_class\->fade_out( $fade_out ); .Ve .PP Fades the music out for its next \f(CW\*(C`fade_in\*(C'\fR milliseconds. Returns the object or class. .SS rewind .IX Subsection "rewind" .Vb 1 \& $music_or_class\->rewind; .Ve .PP Rewinds the music to its start. Returns the object or class. .SS pos .IX Subsection "pos" .Vb 1 \& $music_or_class\->pos( $pos ); .Ve .PP Sets the music position to \f(CW$pos\fR milliseconds. It does different things for different file types, so see SDL::Mixer::Music::set_music_position for details. Note that this method divides \f(CW$pos\fR by 1000 to pass it to that function, which uses seconds. Returns the object or class. .SH "SEE ALSO" .IX Header "SEE ALSO" SDLx::Music::Data SDLx::Mixer SDL::Mixer::Music SDL::Mixer .SH AUTHORS .IX Header "AUTHORS" See "AUTHORS" in SDL. .SH "COPYRIGHT & LICENSE" .IX Header "COPYRIGHT & LICENSE" This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.