XMMS (empty) → 0.1
raw patch · 21 files changed
+2078/−0 lines, 21 filesdep +basedep +containerssetup-changed
Dependencies added: base, containers
Files
- LICENSE +462/−0
- Network/XMMS/Client.hs +130/−0
- Network/XMMS/Client/Glib.hs +38/−0
- Network/XMMS/Config.hs +90/−0
- Network/XMMS/Constants.hsc +23/−0
- Network/XMMS/Medialib.hs +34/−0
- Network/XMMS/Playback.hs +211/−0
- Network/XMMS/Playlist.hs +359/−0
- Network/XMMS/Result.hs +105/−0
- Network/XMMS/Types.hs +57/−0
- Network/XMMS/Utilities.hs +72/−0
- Network/XMMS/Value.hs +232/−0
- Setup.hs +2/−0
- XMMS.cabal +51/−0
- cbits/XMMSUtils.c +43/−0
- cbits/XMMSUtils.h +14/−0
- example/tut1.hs +20/−0
- example/tut2.hs +21/−0
- example/tut3.hs +33/−0
- example/tut4.hs +46/−0
- example/tut7.hs +35/−0
+ LICENSE view
@@ -0,0 +1,462 @@+ GNU LESSER GENERAL PUBLIC LICENSE+ Version 2.1, February 1999++ Copyright (C) 1991, 1999 Free Software Foundation, Inc.+ 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA+ Everyone is permitted to copy and distribute verbatim copies+ of this license document, but changing it is not allowed.++[This is the first released version of the Lesser GPL. It also counts+ as the successor of the GNU Library Public License, version 2, hence+ the version number 2.1.]++ Preamble++ The licenses for most software are designed to take away your+freedom to share and change it. By contrast, the GNU General Public+Licenses are intended to guarantee your freedom to share and change+free software--to make sure the software is free for all its users.++ This license, the Lesser General Public License, applies to some+specially designated software packages--typically libraries--of the+Free Software Foundation and other authors who decide to use it. You+can use it too, but we suggest you first think carefully about whether+this license or the ordinary General Public License is the better+strategy to use in any particular case, based on the explanations below.++ When we speak of free software, we are referring to freedom of use,+not price. Our General Public Licenses are designed to make sure that+you have the freedom to distribute copies of free software (and charge+for this service if you wish); that you receive source code or can get+it if you want it; that you can change the software and use pieces of+it in new free programs; and that you are informed that you can do+these things.++ To protect your rights, we need to make restrictions that forbid+distributors to deny you these rights or to ask you to surrender these+rights. These restrictions translate to certain responsibilities for+you if you distribute copies of the library or if you modify it.++ For example, if you distribute copies of the library, whether gratis+or for a fee, you must give the recipients all the rights that we gave+you. You must make sure that they, too, receive or can get the source+code. If you link other code with the library, you must provide+complete object files to the recipients, so that they can relink them+with the library after making changes to the library and recompiling+it. And you must show them these terms so they know their rights.++ We protect your rights with a two-step method: (1) we copyright the+library, and (2) we offer you this license, which gives you legal+permission to copy, distribute and/or modify the library.++ To protect each distributor, we want to make it very clear that+there is no warranty for the free library. Also, if the library is+modified by someone else and passed on, the recipients should know+that what they have is not the original version, so that the original+author's reputation will not be affected by problems that might be+introduced by others.++ Finally, software patents pose a constant threat to the existence of+any free program. We wish to make sure that a company cannot+effectively restrict the users of a free program by obtaining a+restrictive license from a patent holder. Therefore, we insist that+any patent license obtained for a version of the library must be+consistent with the full freedom of use specified in this license.++ Most GNU software, including some libraries, is covered by the+ordinary GNU General Public License. This license, the GNU Lesser+General Public License, applies to certain designated libraries, and+is quite different from the ordinary General Public License. We use+this license for certain libraries in order to permit linking those+libraries into non-free programs.++ When a program is linked with a library, whether statically or using+a shared library, the combination of the two is legally speaking a+combined work, a derivative of the original library. The ordinary+General Public License therefore permits such linking only if the+entire combination fits its criteria of freedom. The Lesser General+Public License permits more lax criteria for linking other code with+the library.++ We call this license the "Lesser" General Public License because it+does Less to protect the user's freedom than the ordinary General+Public License. It also provides other free software developers Less+of an advantage over competing non-free programs. These disadvantages+are the reason we use the ordinary General Public License for many+libraries. However, the Lesser license provides advantages in certain+special circumstances.++ For example, on rare occasions, there may be a special need to+encourage the widest possible use of a certain library, so that it becomes+a de-facto standard. To achieve this, non-free programs must be+allowed to use the library. A more frequent case is that a free+library does the same job as widely used non-free libraries. In this+case, there is little to gain by limiting the free library to free+software only, so we use the Lesser General Public License.++ In other cases, permission to use a particular library in non-free+programs enables a greater number of people to use a large body of+free software. For example, permission to use the GNU C Library in+non-free programs enables many more people to use the whole GNU+operating system, as well as its variant, the GNU/Linux operating+system.++ Although the Lesser General Public License is Less protective of the+users' freedom, it does ensure that the user of a program that is+linked with the Library has the freedom and the wherewithal to run+that program using a modified version of the Library.++ The precise terms and conditions for copying, distribution and+modification follow. Pay close attention to the difference between a+"work based on the library" and a "work that uses the library". The+former contains code derived from the library, whereas the latter must+be combined with the library in order to run.++ GNU LESSER GENERAL PUBLIC LICENSE+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION++ 0. This License Agreement applies to any software library or other+program which contains a notice placed by the copyright holder or+other authorized party saying it may be distributed under the terms of+this Lesser General Public License (also called "this License").+Each licensee is addressed as "you".++ A "library" means a collection of software functions and/or data+prepared so as to be conveniently linked with application programs+(which use some of those functions and data) to form executables.++ The "Library", below, refers to any such software library or work+which has been distributed under these terms. A "work based on the+Library" means either the Library or any derivative work under+copyright law: that is to say, a work containing the Library or a+portion of it, either verbatim or with modifications and/or translated+straightforwardly into another language. (Hereinafter, translation is+included without limitation in the term "modification".)++ "Source code" for a work means the preferred form of the work for+making modifications to it. For a library, complete source code means+all the source code for all modules it contains, plus any associated+interface definition files, plus the scripts used to control compilation+and installation of the library.++ Activities other than copying, distribution and modification are not+covered by this License; they are outside its scope. The act of+running a program using the Library is not restricted, and output from+such a program is covered only if its contents constitute a work based+on the Library (independent of the use of the Library in a tool for+writing it). Whether that is true depends on what the Library does+and what the program that uses the Library does.+ + 1. You may copy and distribute verbatim copies of the Library's+complete source code as you receive it, in any medium, provided that+you conspicuously and appropriately publish on each copy an+appropriate copyright notice and disclaimer of warranty; keep intact+all the notices that refer to this License and to the absence of any+warranty; and distribute a copy of this License along with the+Library.++ You may charge a fee for the physical act of transferring a copy,+and you may at your option offer warranty protection in exchange for a+fee.++ 2. You may modify your copy or copies of the Library or any portion+of it, thus forming a work based on the Library, and copy and+distribute such modifications or work under the terms of Section 1+above, provided that you also meet all of these conditions:++ a) The modified work must itself be a software library.++ b) You must cause the files modified to carry prominent notices+ stating that you changed the files and the date of any change.++ c) You must cause the whole of the work to be licensed at no+ charge to all third parties under the terms of this License.++ d) If a facility in the modified Library refers to a function or a+ table of data to be supplied by an application program that uses+ the facility, other than as an argument passed when the facility+ is invoked, then you must make a good faith effort to ensure that,+ in the event an application does not supply such function or+ table, the facility still operates, and performs whatever part of+ its purpose remains meaningful.++ (For example, a function in a library to compute square roots has+ a purpose that is entirely well-defined independent of the+ application. Therefore, Subsection 2d requires that any+ application-supplied function or table used by this function must+ be optional: if the application does not supply it, the square+ root function must still compute square roots.)++These requirements apply to the modified work as a whole. If+identifiable sections of that work are not derived from the Library,+and can be reasonably considered independent and separate works in+themselves, then this License, and its terms, do not apply to those+sections when you distribute them as separate works. But when you+distribute the same sections as part of a whole which is a work based+on the Library, the distribution of the whole must be on the terms of+this License, whose permissions for other licensees extend to the+entire whole, and thus to each and every part regardless of who wrote+it.++Thus, it is not the intent of this section to claim rights or contest+your rights to work written entirely by you; rather, the intent is to+exercise the right to control the distribution of derivative or+collective works based on the Library.++In addition, mere aggregation of another work not based on the Library+with the Library (or with a work based on the Library) on a volume of+a storage or distribution medium does not bring the other work under+the scope of this License.++ 3. You may opt to apply the terms of the ordinary GNU General Public+License instead of this License to a given copy of the Library. To do+this, you must alter all the notices that refer to this License, so+that they refer to the ordinary GNU General Public License, version 2,+instead of to this License. (If a newer version than version 2 of the+ordinary GNU General Public License has appeared, then you can specify+that version instead if you wish.) Do not make any other change in+these notices.++ Once this change is made in a given copy, it is irreversible for+that copy, so the ordinary GNU General Public License applies to all+subsequent copies and derivative works made from that copy.++ This option is useful when you wish to copy part of the code of+the Library into a program that is not a library.++ 4. You may copy and distribute the Library (or a portion or+derivative of it, under Section 2) in object code or executable form+under the terms of Sections 1 and 2 above provided that you accompany+it with the complete corresponding machine-readable source code, which+must be distributed under the terms of Sections 1 and 2 above on a+medium customarily used for software interchange.++ If distribution of object code is made by offering access to copy+from a designated place, then offering equivalent access to copy the+source code from the same place satisfies the requirement to+distribute the source code, even though third parties are not+compelled to copy the source along with the object code.++ 5. A program that contains no derivative of any portion of the+Library, but is designed to work with the Library by being compiled or+linked with it, is called a "work that uses the Library". Such a+work, in isolation, is not a derivative work of the Library, and+therefore falls outside the scope of this License.++ However, linking a "work that uses the Library" with the Library+creates an executable that is a derivative of the Library (because it+contains portions of the Library), rather than a "work that uses the+library". The executable is therefore covered by this License.+Section 6 states terms for distribution of such executables.++ When a "work that uses the Library" uses material from a header file+that is part of the Library, the object code for the work may be a+derivative work of the Library even though the source code is not.+Whether this is true is especially significant if the work can be+linked without the Library, or if the work is itself a library. The+threshold for this to be true is not precisely defined by law.++ If such an object file uses only numerical parameters, data+structure layouts and accessors, and small macros and small inline+functions (ten lines or less in length), then the use of the object+file is unrestricted, regardless of whether it is legally a derivative+work. (Executables containing this object code plus portions of the+Library will still fall under Section 6.)++ Otherwise, if the work is a derivative of the Library, you may+distribute the object code for the work under the terms of Section 6.+Any executables containing that work also fall under Section 6,+whether or not they are linked directly with the Library itself.++ 6. As an exception to the Sections above, you may also combine or+link a "work that uses the Library" with the Library to produce a+work containing portions of the Library, and distribute that work+under terms of your choice, provided that the terms permit+modification of the work for the customer's own use and reverse+engineering for debugging such modifications.++ You must give prominent notice with each copy of the work that the+Library is used in it and that the Library and its use are covered by+this License. You must supply a copy of this License. If the work+during execution displays copyright notices, you must include the+copyright notice for the Library among them, as well as a reference+directing the user to the copy of this License. Also, you must do one+of these things:++ a) Accompany the work with the complete corresponding+ machine-readable source code for the Library including whatever+ changes were used in the work (which must be distributed under+ Sections 1 and 2 above); and, if the work is an executable linked+ with the Library, with the complete machine-readable "work that+ uses the Library", as object code and/or source code, so that the+ user can modify the Library and then relink to produce a modified+ executable containing the modified Library. (It is understood+ that the user who changes the contents of definitions files in the+ Library will not necessarily be able to recompile the application+ to use the modified definitions.)++ b) Use a suitable shared library mechanism for linking with the+ Library. A suitable mechanism is one that (1) uses at run time a+ copy of the library already present on the user's computer system,+ rather than copying library functions into the executable, and (2)+ will operate properly with a modified version of the library, if+ the user installs one, as long as the modified version is+ interface-compatible with the version that the work was made with.++ c) Accompany the work with a written offer, valid for at+ least three years, to give the same user the materials+ specified in Subsection 6a, above, for a charge no more+ than the cost of performing this distribution.++ d) If distribution of the work is made by offering access to copy+ from a designated place, offer equivalent access to copy the above+ specified materials from the same place.++ e) Verify that the user has already received a copy of these+ materials or that you have already sent this user a copy.++ For an executable, the required form of the "work that uses the+Library" must include any data and utility programs needed for+reproducing the executable from it. However, as a special exception,+the materials to be distributed need not include anything that is+normally distributed (in either source or binary form) with the major+components (compiler, kernel, and so on) of the operating system on+which the executable runs, unless that component itself accompanies+the executable.++ It may happen that this requirement contradicts the license+restrictions of other proprietary libraries that do not normally+accompany the operating system. Such a contradiction means you cannot+use both them and the Library together in an executable that you+distribute.++ 7. You may place library facilities that are a work based on the+Library side-by-side in a single library together with other library+facilities not covered by this License, and distribute such a combined+library, provided that the separate distribution of the work based on+the Library and of the other library facilities is otherwise+permitted, and provided that you do these two things:++ a) Accompany the combined library with a copy of the same work+ based on the Library, uncombined with any other library+ facilities. This must be distributed under the terms of the+ Sections above.++ b) Give prominent notice with the combined library of the fact+ that part of it is a work based on the Library, and explaining+ where to find the accompanying uncombined form of the same work.++ 8. You may not copy, modify, sublicense, link with, or distribute+the Library except as expressly provided under this License. Any+attempt otherwise to copy, modify, sublicense, link with, or+distribute the Library is void, and will automatically terminate your+rights under this License. However, parties who have received copies,+or rights, from you under this License will not have their licenses+terminated so long as such parties remain in full compliance.++ 9. You are not required to accept this License, since you have not+signed it. However, nothing else grants you permission to modify or+distribute the Library or its derivative works. These actions are+prohibited by law if you do not accept this License. Therefore, by+modifying or distributing the Library (or any work based on the+Library), you indicate your acceptance of this License to do so, and+all its terms and conditions for copying, distributing or modifying+the Library or works based on it.++ 10. Each time you redistribute the Library (or any work based on the+Library), the recipient automatically receives a license from the+original licensor to copy, distribute, link with or modify the Library+subject to these terms and conditions. You may not impose any further+restrictions on the recipients' exercise of the rights granted herein.+You are not responsible for enforcing compliance by third parties with+this License.++ 11. If, as a consequence of a court judgment or allegation of patent+infringement or for any other reason (not limited to patent issues),+conditions are imposed on you (whether by court order, agreement or+otherwise) that contradict the conditions of this License, they do not+excuse you from the conditions of this License. If you cannot+distribute so as to satisfy simultaneously your obligations under this+License and any other pertinent obligations, then as a consequence you+may not distribute the Library at all. For example, if a patent+license would not permit royalty-free redistribution of the Library by+all those who receive copies directly or indirectly through you, then+the only way you could satisfy both it and this License would be to+refrain entirely from distribution of the Library.++If any portion of this section is held invalid or unenforceable under any+particular circumstance, the balance of the section is intended to apply,+and the section as a whole is intended to apply in other circumstances.++It is not the purpose of this section to induce you to infringe any+patents or other property right claims or to contest validity of any+such claims; this section has the sole purpose of protecting the+integrity of the free software distribution system which is+implemented by public license practices. Many people have made+generous contributions to the wide range of software distributed+through that system in reliance on consistent application of that+system; it is up to the author/donor to decide if he or she is willing+to distribute software through any other system and a licensee cannot+impose that choice.++This section is intended to make thoroughly clear what is believed to+be a consequence of the rest of this License.++ 12. If the distribution and/or use of the Library is restricted in+certain countries either by patents or by copyrighted interfaces, the+original copyright holder who places the Library under this License may add+an explicit geographical distribution limitation excluding those countries,+so that distribution is permitted only in or among countries not thus+excluded. In such case, this License incorporates the limitation as if+written in the body of this License.++ 13. The Free Software Foundation may publish revised and/or new+versions of the Lesser General Public License from time to time.+Such new versions will be similar in spirit to the present version,+but may differ in detail to address new problems or concerns.++Each version is given a distinguishing version number. If the Library+specifies a version number of this License which applies to it and+"any later version", you have the option of following the terms and+conditions either of that version or of any later version published by+the Free Software Foundation. If the Library does not specify a+license version number, you may choose any version ever published by+the Free Software Foundation.++ 14. If you wish to incorporate parts of the Library into other free+programs whose distribution conditions are incompatible with these,+write to the author to ask for permission. For software which is+copyrighted by the Free Software Foundation, write to the Free+Software Foundation; we sometimes make exceptions for this. Our+decision will be guided by the two goals of preserving the free status+of all derivatives of our free software and of promoting the sharing+and reuse of software generally.++ NO WARRANTY++ 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO+WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.+EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR+OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY+KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE+LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME+THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.++ 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN+WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY+AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU+FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR+CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE+LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING+RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A+FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF+SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH+DAMAGES.++ END OF TERMS AND CONDITIONS+++------------------------------------------------------------------------+
+ Network/XMMS/Client.hs view
@@ -0,0 +1,130 @@+-- Copyright 2010 Evgeniy Vodolazskiy (waterlaz@gmail.com)+--+-- This library is free software; you can redistribute it and/or+-- modify it under the terms of the GNU Lesser General Public+-- License as published by the Free Software Foundation; either+-- version 2.1 of the License, or (at your option) any later version.+--+-- This library is distributed in the hope that it will be useful,+-- but WITHOUT ANY WARRANTY; without even the implied warranty of+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU+-- Lesser General Public License for more details.++module Network.XMMS.Client (+ Connection,+ Result,+ XMMSCV(..),+ SeekMode(..),+ init,+ connect,+ getLastError,+ quit,+ broadcastQuit,+ userConfigDirGet,+ resultWait,+ propdictToDict,+ resultGetValue,+ resultNotifierSet,+ resultGetConnection+)where++import Network.XMMS.Constants+++import Network.XMMS.Types+import Network.XMMS.Utilities++import Foreign+import Foreign.Ptr+import Foreign.C.Types+import Foreign.C.String+import Foreign.ForeignPtr+import Foreign.Marshal.Alloc+import Prelude hiding (init)+import Network.XMMS.Result+import Network.XMMS.Value++++--xmmsc_connection_t *xmmsc_init (const char *clientname)+foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsc_init"+ xmmsc_init :: CString -> IO (Ptr C_xmmsc_connection)+-- |Initializes a connection. With the coresponding name+init :: String -> IO Connection+init name = do+ c_name <- newCString name+ ptr <- xmmsc_init c_name+ free c_name+ newForeignPtr xmmsc_unref ptr++++--int xmmsc_connect (xmmsc_connection_t *c, const char *ipcpath)+foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsc_connect" + xmmsc_connect :: Ptr C_xmmsc_connection -> CString -> IO CInt+-- | Connects to the XMMS server.+connect :: Connection -> String -> IO Int+connect connection ipcpath =+ withForeignPtr connection ( \ptrCon -> do+ res <- if ipcpath == ""+ then xmmsc_connect ptrCon nullPtr+ else do c_ipcpath <- newCString ipcpath+ xmmsc_connect ptrCon c_ipcpath+ return $ fromIntegral res)+++--Set the disconnect callback. +--void xmmsc_disconnect_callback_set (xmmsc_connection_t *c, xmmsc_disconnect_func_t callback, void *userdata)+--void xmmsc_disconnect_callback_set_full (xmmsc_connection_t *c, xmmsc_disconnect_func_t callback, void *userdata, xmmsc_user_data_free_func_t free_func)+++--char * xmmsc_get_last_error (xmmsc_connection_t *c)+foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsc_get_last_error" + xmmsc_get_last_error :: Ptr C_xmmsc_connection -> IO CString+-- |Returns a string that descibes the last error.+getLastError :: Connection -> IO String+getLastError connection =+ withForeignPtr connection ( \ptrCon -> do+ c_errorMsg <- xmmsc_get_last_error ptrCon+ safePeekCString c_errorMsg)++ ++++--Set locking functions for a connection.+--void xmmsc_lock_set (xmmsc_connection_t *c, void *lock, void(*lockfunc)(void *), void(*unlockfunc)(void *))++ ++--xmmsc_result_t * xmmsc_quit (xmmsc_connection_t *c)+foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsc_quit" + xmmsc_quit :: Ptr C_xmmsc_connection -> IO (Ptr C_xmmsc_result)+-- |Tell the server to quit.+quit :: Connection -> IO Result+quit = wrapCallResult xmmsc_quit+++--xmmsc_result_t * xmmsc_broadcast_quit (xmmsc_connection_t *c)+foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsc_broadcast_quit" + xmmsc_broadcast_quit :: Ptr C_xmmsc_connection -> IO (Ptr C_xmmsc_result)+-- |Request the quit broadcast.+broadcastQuit :: Connection -> IO Result+broadcastQuit = wrapCallResult xmmsc_broadcast_quit++++--const char * xmmsc_userconfdir_get (char *buf, int len)+foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsc_userconfdir_get" + xmmsc_userconfdir_get :: Ptr CChar -> CInt -> IO (Ptr CChar)+-- |Get the absolute path to the user config dir. +-- +-- /The Int parameter is the buffer length and should probably go away... /+userConfigDirGet :: Int -> IO String+userConfigDirGet len = do+ let c = (castCharToCChar 'c') :: CChar+ bufPtr <- mallocBytes (len * sizeOf c)+ xmmsc_userconfdir_get bufPtr (fromIntegral len)+ res <- safePeekCString bufPtr+ free bufPtr+ return res
+ Network/XMMS/Client/Glib.hs view
@@ -0,0 +1,38 @@+-- Copyright 2010 Evgeniy Vodolazskiy (waterlaz@gmail.com)+--+-- This library is free software; you can redistribute it and/or+-- modify it under the terms of the GNU Lesser General Public+-- License as published by the Free Software Foundation; either+-- version 2.1 of the License, or (at your option) any later version.+--+-- This library is distributed in the hope that it will be useful,+-- but WITHOUT ANY WARRANTY; without even the implied warranty of+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU+-- Lesser General Public License for more details.++module Network.XMMS.Client.Glib (+ mainLoopGmainInit+)where++import Network.XMMS.Constants++import Network.XMMS.Types+import Network.XMMS.Utilities++import Foreign+import Foreign.Ptr+import Foreign.C.Types+import Foreign.C.String+import Foreign.ForeignPtr+import Foreign.Marshal.Alloc+import Prelude hiding (init)+import Network.XMMS.Result+import Network.XMMS.Value+ ++--void xmmsc_mainloop_gmain_init (xmmsc_connection_t *connection)+foreign import ccall "xmmsclient/xmmsclient-glib.h xmmsc_mainloop_gmain_init" + xmmsc_mainloop_gmain_init :: Ptr C_xmmsc_connection -> IO ()+mainLoopGmainInit :: Connection -> IO ()+mainLoopGmainInit connection = do+ withForeignPtr connection xmmsc_mainloop_gmain_init
+ Network/XMMS/Config.hs view
@@ -0,0 +1,90 @@+{-# LANGUAGE ForeignFunctionInterface #-}++-- Copyright 2010 Evgeniy Vodolazskiy (waterlaz@gmail.com)+--+-- This library is free software; you can redistribute it and/or+-- modify it under the terms of the GNU Lesser General Public+-- License as published by the Free Software Foundation; either+-- version 2.1 of the License, or (at your option) any later version.+--+-- This library is distributed in the hope that it will be useful,+-- but WITHOUT ANY WARRANTY; without even the implied warranty of+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU+-- Lesser General Public License for more details.++module Network.XMMS.Config( + registerValue,+ setValue,+ getValue,+ listValues,+ broadcastValueChanged+)where++import Foreign+import Foreign.Ptr+import Foreign.C.Types+import Foreign.C.String+import Foreign.ForeignPtr+import Foreign.Marshal.Alloc++import Network.XMMS.Utilities+import Network.XMMS.Constants+import Network.XMMS.Types++++--xmmsc_result_t *xmmsc_config_register_value (xmmsc_connection_t *c, const char *key, const char *value)+foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsc_config_register_value" + xmmsc_config_register_value :: Ptr C_xmmsc_connection -> CString -> CString -> IO (Ptr C_xmmsc_result)+-- |Registers a configvalue in the server.+registerValue :: Connection -> String -> String -> IO Result+registerValue connection key value = do+ c_key <- newCString key+ c_value <- newCString value+ res <- wrapCallResult (\c -> xmmsc_config_register_value c c_key c_value) connection+ free c_key+ free c_value+ return res + + +--xmmsc_result_t *xmmsc_config_set_value (xmmsc_connection_t *c, const char *key, const char *val)+foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsc_config_set_value" + xmmsc_config_set_value :: Ptr C_xmmsc_connection -> CString -> CString -> IO (Ptr C_xmmsc_result)+-- |Sets a configvalue in the server.+setValue :: Connection -> String -> String -> IO Result+setValue connection key value = do+ c_key <- newCString key+ c_value <- newCString value+ res <- wrapCallResult (\c -> xmmsc_config_set_value c c_key c_value) connection+ free c_key+ free c_value+ return res +++--xmmsc_result_t * xmmsc_config_get_value (xmmsc_connection_t *c, const char *key)+foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsc_config_get_value" + xmmsc_config_get_value :: Ptr C_xmmsc_connection -> CString -> IO (Ptr C_xmmsc_result)+-- |Retrieves a configvalue from the server. +getValue :: Connection -> String -> IO Result+getValue connection key = do+ c_key <- newCString key+ res <- wrapCallResult (\c -> xmmsc_config_get_value c c_key) connection+ free c_key+ return res+++--xmmsc_result_t *xmmsc_config_list_values (xmmsc_connection_t *c)+foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsc_config_list_values" + xmmsc_config_list_values :: Ptr C_xmmsc_connection -> IO (Ptr C_xmmsc_result)+-- |Lists all configuration values. +listValues :: Connection -> IO Result+listValues = wrapCallResult xmmsc_config_list_values+++--xmmsc_result_t * xmmsc_broadcast_config_value_changed (xmmsc_connection_t *c)+foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsc_broadcast_config_value_changed" + xmmsc_broadcast_config_value_changed :: Ptr C_xmmsc_connection -> IO (Ptr C_xmmsc_result)+-- |Requests the config_value_changed broadcast. +broadcastValueChanged :: Connection -> IO Result+broadcastValueChanged = wrapCallResult xmmsc_broadcast_config_value_changed+
+ Network/XMMS/Constants.hsc view
@@ -0,0 +1,23 @@+{-# LANGUAGE CPP #-}+module Network.XMMS.Constants where ++import Foreign+import Foreign.C.Types+import Foreign.C.String++#include </usr/include/xmms2/xmmsclient/xmmsclient.h>++#{enum CInt ,,+ typeNone = XMMSV_TYPE_NONE,+ typeError = XMMSV_TYPE_ERROR,+ typeInt32 = XMMSV_TYPE_INT32,+ typeString = XMMSV_TYPE_STRING,+ typeColl = XMMSV_TYPE_COLL,+ typeBin = XMMSV_TYPE_BIN,+ typeList = XMMSV_TYPE_LIST,+ typeDict = XMMSV_TYPE_DICT,+ typeEnd = XMMSV_TYPE_END }++#{enum CInt ,,+ playbackSeekCur = XMMS_PLAYBACK_SEEK_CUR,+ playbackSeekSet = XMMS_PLAYBACK_SEEK_SET }
+ Network/XMMS/Medialib.hs view
@@ -0,0 +1,34 @@+{-# LANGUAGE ForeignFunctionInterface #-}++-- Copyright 2010 Evgeniy Vodolazskiy (waterlaz@gmail.com)+--+-- This library is free software; you can redistribute it and/or+-- modify it under the terms of the GNU Lesser General Public+-- License as published by the Free Software Foundation; either+-- version 2.1 of the License, or (at your option) any later version.+--+-- This library is distributed in the hope that it will be useful,+-- but WITHOUT ANY WARRANTY; without even the implied warranty of+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU+-- Lesser General Public License for more details.++module Network.XMMS.Medialib( + medialibGetInfo+)where++import Foreign+import Foreign.Ptr+import Foreign.C.Types+import Foreign.C.String+import Foreign.ForeignPtr+import Foreign.Marshal.Alloc++import Network.XMMS.Utilities+import Network.XMMS.Constants+import Network.XMMS.Types++--xmmsc_result_t *xmmsc_medialib_get_info (xmmsc_connection_t *, int)+foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsc_medialib_get_info" xmmsc_medialib_get_info :: Ptr C_xmmsc_connection -> CInt -> IO (Ptr C_xmmsc_result)+-- |Retrieve information about an entry from the medialib. +medialibGetInfo :: Connection -> Int -> IO Result+medialibGetInfo = flip $ wrapCallResult.(flip xmmsc_medialib_get_info).fromIntegral
+ Network/XMMS/Playback.hs view
@@ -0,0 +1,211 @@+{-# LANGUAGE ForeignFunctionInterface #-}++-- Copyright 2010 Evgeniy Vodolazskiy (waterlaz@gmail.com)+--+-- This library is free software; you can redistribute it and/or+-- modify it under the terms of the GNU Lesser General Public+-- License as published by the Free Software Foundation; either+-- version 2.1 of the License, or (at your option) any later version.+--+-- This library is distributed in the hope that it will be useful,+-- but WITHOUT ANY WARRANTY; without even the implied warranty of+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU+-- Lesser General Public License for more details.++module Network.XMMS.Playback (+ SeekMode(..),+ tickle,+ stop,+ pause,+ start,+ seekmsAbs,+ seekmsRel,+ seekms,+ seekSamplesAbs,+ seekSamplesRel, + seekSamples,+ broadcastStatus,+ status,+ broadcastCurrentID,+ currentID,+ signalPlaytime,+ playtime,+ volumeGet,+ volumeSet,+ broadcastVolumeChanged+) where++--import Network.XMMS+import Network.XMMS.Constants+import Network.XMMS.Types+import Network.XMMS.Utilities++import Foreign+import Foreign.Ptr+import Foreign.C.Types+import Foreign.C.String+import Foreign.ForeignPtr+import Foreign.Marshal.Alloc+++--xmmsc_result_t * xmmsc_playback_tickle (xmmsc_connection_t *c)+foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsc_playback_tickle" + xmmsc_playback_tickle :: Ptr C_xmmsc_connection -> IO (Ptr C_xmmsc_result)+-- |Stop decoding of current song. +-- /Usefull to implement things like next, prev etc/+tickle :: Connection -> IO Result+tickle = wrapCallResult xmmsc_playback_tickle+++--xmmsc_result_t * xmmsc_playback_stop (xmmsc_connection_t *c)+foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsc_playback_stop" + xmmsc_playback_stop :: Ptr C_xmmsc_connection -> IO (Ptr C_xmmsc_result)+-- |Stops the current playback. +stop :: Connection -> IO Result+stop = wrapCallResult xmmsc_playback_stop+++--xmmsc_result_t * xmmsc_playback_pause (xmmsc_connection_t *c)+foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsc_playback_pause" + xmmsc_playback_pause :: Ptr C_xmmsc_connection -> IO (Ptr C_xmmsc_result)+-- |Pause the current playback, will tell the output to not read nor write. +pause :: Connection -> IO Result+pause = wrapCallResult xmmsc_playback_pause++ +--xmmsc_result_t * xmmsc_playback_start (xmmsc_connection_t *c)+foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsc_playback_start" + xmmsc_playback_start :: Ptr C_xmmsc_connection -> IO (Ptr C_xmmsc_result)+-- |Starts playback if server is idle.+start :: Connection -> IO Result+start = wrapCallResult xmmsc_playback_start +++--xmmsc_result_t * xmmsc_playback_seek_ms_abs (xmmsc_connection_t *c, int milliseconds)+foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsc_playback_seek_ms_abs" + xmmsc_playback_seek_ms_abs :: Ptr C_xmmsc_connection -> CInt -> IO (Ptr C_xmmsc_result)+-- |Seek to an absolute time in the current playback.+seekmsAbs :: Connection -> Int -> IO Result+seekmsAbs = flip $ wrapCallResult.(flip xmmsc_playback_seek_ms_abs).fromIntegral+++--xmmsc_result_t * xmmsc_playback_seek_ms_rel (xmmsc_connection_t *c, int milliseconds)+foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsc_playback_seek_ms_rel" + xmmsc_playback_seek_ms_rel :: Ptr C_xmmsc_connection -> CInt -> IO (Ptr C_xmmsc_result)+-- |Seek to a time relative to the current position in the current playback. +seekmsRel :: Connection -> Int -> IO Result+seekmsRel = flip $ wrapCallResult.(flip xmmsc_playback_seek_ms_rel).fromIntegral+++--xmmsc_result_t * xmmsc_playback_seek_ms (xmmsc_connection_t *c, int milliseconds, xmms_playback_seek_mode_t whence)+foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsc_playback_seek_ms" + xmmsc_playback_seek_ms :: Ptr C_xmmsc_connection -> CInt -> CInt -> IO (Ptr C_xmmsc_result)+-- |Seek to a position given in milliseconds in the current playback. +seekms :: Connection -> Int -> SeekMode -> IO Result+seekms connection ms mode = + wrapCallResult (\c -> xmmsc_playback_seek_ms c + (fromIntegral ms) + (fromSeekMode mode)) connection+++--xmmsc_result_t * xmmsc_playback_seek_samples_abs (xmmsc_connection_t *c, int samples)+foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsc_playback_seek_samples_abs" + xmmsc_playback_seek_samples_abs :: Ptr C_xmmsc_connection -> CInt -> IO (Ptr C_xmmsc_result)+-- |Seek to a absoulte number of samples in the current playback.+seekSamplesAbs :: Connection -> Int -> IO Result+seekSamplesAbs = flip $ wrapCallResult.(flip xmmsc_playback_seek_samples_abs).fromIntegral+ ++--xmmsc_result_t * xmmsc_playback_seek_samples_rel (xmmsc_connection_t *c, int samples)+foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsc_playback_seek_samples_rel" + xmmsc_playback_seek_samples_rel :: Ptr C_xmmsc_connection -> CInt -> IO (Ptr C_xmmsc_result)+-- |Seek to a number of samples relative to the current position in the current playback.+seekSamplesRel :: Connection -> Int -> IO Result+seekSamplesRel = flip $ wrapCallResult.(flip xmmsc_playback_seek_samples_rel).fromIntegral+++--xmmsc_result_t * xmmsc_playback_seek_samples (xmmsc_connection_t *c, int samples, xmms_playback_seek_mode_t whence)+foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsc_playback_seek_samples" + xmmsc_playback_seek_samples :: Ptr C_xmmsc_connection -> CInt -> CInt -> IO (Ptr C_xmmsc_result)+-- |Seek to a position given in samples in the current playback. +seekSamples :: Connection -> Int -> SeekMode -> IO Result+seekSamples connection samples mode = + wrapCallResult (\c -> xmmsc_playback_seek_samples c + (fromIntegral samples) + (fromSeekMode mode)) connection+ ++--xmmsc_result_t * xmmsc_broadcast_playback_status (xmmsc_connection_t *c)+foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsc_broadcast_playback_status" + xmmsc_broadcast_playback_status :: Ptr C_xmmsc_connection -> IO (Ptr C_xmmsc_result)+-- |Requests the playback status broadcast.+broadcastStatus :: Connection -> IO Result+broadcastStatus = wrapCallResult xmmsc_broadcast_playback_status+ ++--xmmsc_result_t * xmmsc_playback_status (xmmsc_connection_t *c)+foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsc_playback_status" + xmmsc_playback_status :: Ptr C_xmmsc_connection -> IO (Ptr C_xmmsc_result)+-- |Make server emit the playback status.+status :: Connection -> IO Result+status = wrapCallResult xmmsc_playback_status+++--xmmsc_result_t * xmmsc_broadcast_playback_current_id (xmmsc_connection_t *c)+foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsc_broadcast_playback_current_id" + xmmsc_broadcast_playback_current_id :: Ptr C_xmmsc_connection -> IO (Ptr C_xmmsc_result)+-- |Request the current id broadcast. +broadcastCurrentID :: Connection -> IO Result+broadcastCurrentID = wrapCallResult xmmsc_broadcast_playback_current_id+++--xmmsc_result_t * xmmsc_playback_current_id (xmmsc_connection_t *c)+foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsc_playback_current_id" + xmmsc_playback_current_id :: Ptr C_xmmsc_connection -> IO (Ptr C_xmmsc_result)+-- |Make server emit the current id.+currentID :: Connection -> IO Result+currentID = wrapCallResult xmmsc_playback_current_id+++--xmmsc_result_t * xmmsc_signal_playback_playtime (xmmsc_connection_t *c)+foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsc_signal_playback_playtime" + xmmsc_signal_playback_playtime :: Ptr C_xmmsc_connection -> IO (Ptr C_xmmsc_result)+-- |Request the playback_playtime signal.+signalPlaytime :: Connection -> IO Result+signalPlaytime = wrapCallResult xmmsc_signal_playback_playtime+++--xmmsc_result_t * xmmsc_playback_playtime (xmmsc_connection_t *c)+foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsc_playback_playtime" + xmmsc_playback_playtime :: Ptr C_xmmsc_connection -> IO (Ptr C_xmmsc_result)+-- |Make server emit the current playtime.+playtime :: Connection -> IO Result+playtime = wrapCallResult xmmsc_playback_playtime+++--xmmsc_result_t * xmmsc_playback_volume_set (xmmsc_connection_t *c, const char *channel, int volume)+foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsc_playback_volume_set" + xmmsc_playback_volume_set :: Ptr C_xmmsc_connection -> CString -> CInt -> IO (Ptr C_xmmsc_result)+volumeSet :: Connection -> String -> Int -> IO Result+volumeSet connection name volume = do+ c_name <- newCString name+ res <- wrapCallResult (\c -> xmmsc_playback_volume_set c + c_name + (fromIntegral volume)) connection+ free c_name+ return res+++--xmmsc_result_t * xmmsc_playback_volume_get (xmmsc_connection_t *c)+foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsc_playback_volume_get" + xmmsc_playback_volume_get :: Ptr C_xmmsc_connection -> IO (Ptr C_xmmsc_result)+volumeGet :: Connection -> IO Result+volumeGet = wrapCallResult xmmsc_playback_volume_get+++--xmmsc_result_t * xmmsc_broadcast_playback_volume_changed (xmmsc_connection_t *c)+foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsc_broadcast_playback_volume_changed" + xmmsc_broadcast_playback_volume_changed :: Ptr C_xmmsc_connection -> IO (Ptr C_xmmsc_result)+broadcastVolumeChanged :: Connection -> IO Result+broadcastVolumeChanged = wrapCallResult xmmsc_broadcast_playback_volume_changed+
+ Network/XMMS/Playlist.hs view
@@ -0,0 +1,359 @@+{-# LANGUAGE ForeignFunctionInterface #-}++-- Copyright 2010 Evgeniy Vodolazskiy (waterlaz@gmail.com)+--+-- This library is free software; you can redistribute it and/or+-- modify it under the terms of the GNU Lesser General Public+-- License as published by the Free Software Foundation; either+-- version 2.1 of the License, or (at your option) any later version.+--+-- This library is distributed in the hope that it will be useful,+-- but WITHOUT ANY WARRANTY; without even the implied warranty of+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU+-- Lesser General Public License for more details.+++module Network.XMMS.Playlist( + currentPos,+ currentActive,+ list,+ create,+ shuffle,+ sort,+ clear,+ remove,+ listEntries,+ insertID,+ insertURL,+ rInsert,+ rInsertEncoded,+ insertEncoded,+ addID,+ addURL,+ rAdd,+ rAddEncoded,+ addEncoded,+ moveEntry,+ removeEntry,+ broadcastChanged,+ broadcastCurrentPos,+ setNext,+ setNextRel,+ load+)where++import Foreign+import Foreign.Ptr+import Foreign.C.Types+import Foreign.C.String+import Foreign.ForeignPtr+import Foreign.Marshal.Alloc++import Network.XMMS.Utilities+import Network.XMMS.Constants+import Network.XMMS.Types+import Network.XMMS.Result+import Network.XMMS.Value+++--xmmsc_result_t * xmmsc_playlist_current_pos (xmmsc_connection_t *c, const char *playlist)+foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsc_playlist_current_pos" + xmmsc_playlist_current_pos :: Ptr C_xmmsc_connection -> CString -> IO (Ptr C_xmmsc_result)+-- |Retrive the current position in the playlist.+currentPos :: Connection -> String -> IO Result+currentPos connection name = + withString name (\ c_name -> + wrapCallResult (\c -> xmmsc_playlist_current_pos c c_name) connection)+ + +--xmmsc_result_t * xmmsc_playlist_current_active (xmmsc_connection_t *c)+foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsc_playlist_current_active" + xmmsc_playlist_current_active :: Ptr C_xmmsc_connection -> IO (Ptr C_xmmsc_result)+-- |Retrive the name of the active playlist.+currentActive :: Connection -> IO Result+currentActive = wrapCallResult xmmsc_playlist_current_active+++--xmmsc_result_t * xmmsc_playlist_list (xmmsc_connection_t *c)+foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsc_playlist_list" + xmmsc_playlist_list :: Ptr C_xmmsc_connection -> IO (Ptr C_xmmsc_result)+-- |List the existing playlists.+list :: Connection -> IO Result+list = wrapCallResult xmmsc_playlist_list+++--xmmsc_result_t * xmmsc_playlist_create (xmmsc_connection_t *c, const char *playlist)+foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsc_playlist_create" + xmmsc_playlist_create :: Ptr C_xmmsc_connection -> CString -> IO (Ptr C_xmmsc_result)+-- |Create a new empty playlist.+create :: Connection -> String -> IO Result+create connection name = + withString name (\ c_name ->+ wrapCallResult (\c -> xmmsc_playlist_create c c_name) connection)+++--xmmsc_result_t * xmmsc_playlist_shuffle (xmmsc_connection_t *c, const char *playlist)+foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsc_playlist_shuffle" + xmmsc_playlist_shuffle :: Ptr C_xmmsc_connection -> CString -> IO (Ptr C_xmmsc_result)+-- |Shuffles the current playlist.+shuffle :: Connection -> String -> IO Result+shuffle connection name = + withString name (\ c_name ->+ wrapCallResult (\c -> xmmsc_playlist_shuffle c c_name) connection)+ ++--xmmsc_result_t * xmmsc_playlist_sort (xmmsc_connection_t *c, const char *playlist, xmmsv_t *properties)+foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsc_playlist_sort" + xmmsc_playlist_sort :: Ptr C_xmmsc_connection -> CString -> Ptr C_xmmsc_value -> IO (Ptr C_xmmsc_result)+-- |Sorts the playlist according to the list of properties +sort :: Connection -> String -> [String] -> IO Result+sort connection name properties = + withString name (\ c_name -> do+ let xmmsProperties = XMMSList $ map XMMSString properties+ c_properties <- convertValueHstoC xmmsProperties+ withForeignPtr c_properties (\c_properties_ptr -> + wrapCallResult (\c -> xmmsc_playlist_sort c c_name c_properties_ptr) connection))+++--xmmsc_result_t *xmmsc_playlist_clear (xmmsc_connection_t *c, const char *playlist)+foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsc_playlist_clear" + xmmsc_playlist_clear :: Ptr C_xmmsc_connection -> CString -> IO (Ptr C_xmmsc_result)+-- |Clears the current playlist.+clear :: Connection -> String -> IO Result+clear connection name = + withString name (\ c_name ->+ wrapCallResult (\c -> xmmsc_playlist_clear c c_name) connection)++--xmmsc_result_t * xmmsc_playlist_remove (xmmsc_connection_t *c, const char *playlist)+foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsc_playlist_remove" + xmmsc_playlist_remove :: Ptr C_xmmsc_connection -> CString -> IO (Ptr C_xmmsc_result)+-- |Remove the given playlist.+remove :: Connection -> String -> IO Result+remove connection name = + withString name (\ c_name ->+ wrapCallResult (\c -> xmmsc_playlist_remove c c_name) connection)+ + +--xmmsc_result_t * xmmsc_playlist_list_entries (xmmsc_connection_t *c, const char *playlist)+foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsc_playlist_list_entries" + xmmsc_playlist_list_entries :: Ptr C_xmmsc_connection -> CString -> IO (Ptr C_xmmsc_result)+-- |List current playlist.+listEntries :: Connection -> String -> IO Result+listEntries connection name = + withString name (\ c_name ->+ wrapCallResult (\c -> xmmsc_playlist_list_entries c c_name) connection)+ + +--xmmsc_result_t *xmmsc_playlist_insert_id (xmmsc_connection_t *c, const char *playlist, int pos, int id)+foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsc_playlist_insert_id" + xmmsc_playlist_insert_id :: Ptr C_xmmsc_connection -> CString -> CInt -> CInt -> IO (Ptr C_xmmsc_result)+-- |Insert a medialib id at given position in playlist.+insertID :: Connection -> String -> Int -> Int -> IO Result+insertID connection name pos id = + withString name (\ c_name ->+ wrapCallResult (\c -> xmmsc_playlist_insert_id c c_name (fromIntegral pos) (fromIntegral pos)) connection)+++--xmmsc_result_t * xmmsc_playlist_insert_url (xmmsc_connection_t *c, const char *playlist, int pos, const char *url)+foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsc_playlist_insert_url" + xmmsc_playlist_insert_url :: Ptr C_xmmsc_connection -> CString -> Int -> CString -> IO (Ptr C_xmmsc_result)+-- |Insert entry at given position in playlist.+insertURL :: Connection -> String -> Int -> String -> IO Result+insertURL connection name pos url = + withString name (\ c_name -> do+ c_url <- newCString url+ res <- wrapCallResult (\c -> xmmsc_playlist_insert_url c c_name (fromIntegral pos) c_url) connection+ free c_url+ return res)+ + +--xmmsc_result_t * xmmsc_playlist_rinsert (xmmsc_connection_t *c, const char *playlist, int pos, const char *url)+foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsc_playlist_rinsert" + xmmsc_playlist_rinsert :: Ptr C_xmmsc_connection -> CString -> Int -> CString -> IO (Ptr C_xmmsc_result)+-- |Insert a directory recursivly at a given position in the playlist.+rInsert :: Connection -> String -> Int -> String -> IO Result+rInsert connection name pos url = + withString name (\ c_name -> do+ c_url <- newCString url+ res <- wrapCallResult (\c -> xmmsc_playlist_rinsert c c_name (fromIntegral pos) c_url) connection+ free c_url+ return res)++ +--xmmsc_result_t * xmmsc_playlist_rinsert_encoded (xmmsc_connection_t *c, const char *playlist, int pos, const char *url)+foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsc_playlist_rinsert_encoded" + xmmsc_playlist_rinsert_encoded :: Ptr C_xmmsc_connection -> CString -> Int -> CString -> IO (Ptr C_xmmsc_result)+-- |Insert a directory recursivly at a given position in the playlist.+rInsertEncoded :: Connection -> String -> Int -> String -> IO Result+rInsertEncoded connection name pos url = do+ withString name (\ c_name -> do+ c_url <- newCString url+ res <- wrapCallResult (\c -> xmmsc_playlist_rinsert_encoded c c_name (fromIntegral pos) c_url) connection+ free c_url+ return res)+++{-xmmsc_result_t * xmmsc_playlist_insert_args (xmmsc_connection_t *c, const char *playlist, int pos, const char *url, int numargs, const char **args)+ Insert entry at given position in playlist with args.+xmmsc_result_t * xmmsc_playlist_insert_full (xmmsc_connection_t *c, const char *playlist, int pos, const char *url, xmmsv_t *args)+ Insert entry at given position in playlist with args. +xmmsc_result_t * xmmsc_playlist_insert_collection (xmmsc_connection_t *c, const char *playlist, int pos, xmmsv_coll_t *coll, xmmsv_t *order)+ Queries the medialib for media and inserts the matching ones to the current playlist at the given position. +xmmsc_result_t * xmmsc_playlist_add_args (xmmsc_connection_t *c, const char *playlist, const char *url, int nargs, const char **args)+ Add the url to the playlist with arguments.+xmmsc_result_t * xmmsc_playlist_add_full (xmmsc_connection_t *c, const char *playlist, const char *url, xmmsv_t *args)+ Add the url to the playlist with arguments. +xmmsc_result_t * xmmsc_playlist_add_idlist (xmmsc_connection_t *c, const char *playlist, xmmsv_coll_t *coll)+ Adds media in idlist to a playlist.+xmmsc_result_t * xmmsc_playlist_add_collection (xmmsc_connection_t *c, const char *playlist, xmmsv_coll_t *coll, xmmsv_t *order)+ Queries the medialib for media and adds the matching ones to the current playlist.++-}+ +--xmmsc_result_t * xmmsc_playlist_insert_encoded (xmmsc_connection_t *c, const char *playlist, int pos, const char *url)+foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsc_playlist_insert_encoded" + xmmsc_playlist_insert_encoded :: Ptr C_xmmsc_connection -> CString -> Int -> CString -> IO (Ptr C_xmmsc_result)+-- |Insert entry at given position in playlist.+insertEncoded :: Connection -> String -> Int -> String -> IO Result+insertEncoded connection name pos url = + withString name (\ c_name -> do+ c_url <- newCString url+ res <- wrapCallResult (\c -> xmmsc_playlist_insert_encoded c c_name (fromIntegral pos) c_url) connection+ free c_url+ return res)+ ++--xmmsc_result_t * xmmsc_playlist_add_id (xmmsc_connection_t *c, const char *playlist, int id)+foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsc_playlist_add_id" + xmmsc_playlist_add_id :: Ptr C_xmmsc_connection -> CString -> Int -> IO (Ptr C_xmmsc_result)+-- |Add a medialib id to the playlist.+addID :: Connection -> String -> Int -> IO Result+addID connection name id = + withString name (\ c_name ->+ wrapCallResult (\c -> xmmsc_playlist_add_id c c_name (fromIntegral id)) connection)+ + + + +--xmmsc_result_t * xmmsc_playlist_add_url (xmmsc_connection_t *c, const char *playlist, const char *url)+foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsc_playlist_add_url" + xmmsc_playlist_add_url :: Ptr C_xmmsc_connection -> CString -> CString -> IO (Ptr C_xmmsc_result)+-- |Add the url to the playlist.+addURL :: Connection -> String -> String -> IO Result+addURL connection name url = + withString name (\ c_name -> do+ c_url <- newCString url+ res <- wrapCallResult (\c -> xmmsc_playlist_add_url c c_name c_url) connection+ free c_url+ return res)+ ++--xmmsc_result_t * xmmsc_playlist_radd (xmmsc_connection_t *c, const char *playlist, const char *url)+foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsc_playlist_radd" + xmmsc_playlist_radd :: Ptr C_xmmsc_connection -> CString -> CString -> IO (Ptr C_xmmsc_result)+-- |Adds a directory recursivly to the playlist.+rAdd :: Connection -> String -> String -> IO Result+rAdd connection name url = + withString name (\ c_name -> do+ c_url <- newCString url+ res <- wrapCallResult (\c -> xmmsc_playlist_radd c c_name c_url) connection+ free c_url+ return res)+ +--xmmsc_result_t *xmmsc_playlist_radd_encoded (xmmsc_connection_t *c, const char *playlist, const char *url)+foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsc_playlist_radd_encoded" + xmmsc_playlist_radd_encoded :: Ptr C_xmmsc_connection -> CString -> CString -> IO (Ptr C_xmmsc_result)+-- |Adds a directory recursivly to the playlist.+rAddEncoded :: Connection -> String -> String -> IO Result+rAddEncoded connection name url = + withString name (\ c_name -> do+ c_url <- newCString url+ res <- wrapCallResult (\c -> xmmsc_playlist_radd_encoded c c_name c_url) connection+ free c_url+ return res)++++--xmmsc_result_t* xmmsc_playlist_add_encoded (xmmsc_connection_t *c, const char *playlist, const char *url)+foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsc_playlist_add_encoded" + xmmsc_playlist_add_encoded :: Ptr C_xmmsc_connection -> CString -> CString -> IO (Ptr C_xmmsc_result)+-- |Add the url to the playlist.+addEncoded :: Connection -> String -> String -> IO Result+addEncoded connection name url = + withString name (\ c_name -> do+ c_url <- newCString url+ res <- wrapCallResult (\c -> xmmsc_playlist_add_encoded c c_name c_url) connection+ free c_url+ return res)+++--xmmsc_result_t *xmmsc_playlist_move_entry (xmmsc_connection_t *c, const char *playlist, int cur_pos, int new_pos)+foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsc_playlist_move_entry" + xmmsc_playlist_move_entry :: Ptr C_xmmsc_connection -> CString -> CInt -> CInt -> IO (Ptr C_xmmsc_result)+-- |Move a playlist entry to a new position (absolute move).+moveEntry :: Connection -> String -> Int -> Int -> IO Result+moveEntry connection name curPos newPos = + withString name (\ c_name ->+ wrapCallResult (\c -> xmmsc_playlist_move_entry c c_name (fromIntegral curPos) (fromIntegral newPos)) connection)+++--xmmsc_result_t * xmmsc_playlist_remove_entry (xmmsc_connection_t *c, const char *playlist, int pos)+foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsc_playlist_remove_entry" + xmmsc_playlist_remove_entry :: Ptr C_xmmsc_connection -> CString -> CInt -> IO (Ptr C_xmmsc_result)+-- |Remove an entry from the playlist.+removeEntry :: Connection -> String -> Int -> IO Result+removeEntry connection name pos = + withString name (\ c_name ->+ wrapCallResult (\c -> xmmsc_playlist_remove_entry c c_name (fromIntegral pos)) connection)+ + +--xmmsc_result_t *xmmsc_broadcast_playlist_changed (xmmsc_connection_t *c)+foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsc_broadcast_playlist_changed" + xmmsc_broadcast_playlist_changed :: Ptr C_xmmsc_connection -> IO (Ptr C_xmmsc_result)+-- |Request the playlist changed broadcast from the server.+broadcastChanged :: Connection -> IO Result+broadcastChanged = wrapCallResult xmmsc_broadcast_playlist_changed+ ++--xmmsc_result_t * xmmsc_broadcast_playlist_current_pos (xmmsc_connection_t *c)+foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsc_broadcast_playlist_current_pos" + xmmsc_broadcast_playlist_current_pos :: Ptr C_xmmsc_connection -> IO (Ptr C_xmmsc_result)+-- |Request the playlist current pos broadcast.+broadcastCurrentPos :: Connection -> IO Result+broadcastCurrentPos = wrapCallResult xmmsc_broadcast_playlist_current_pos+++--xmmsc_result_t *xmmsc_playlist_set_next (xmmsc_connection_t *c, int pos)+foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsc_playlist_set_next" + xmmsc_playlist_set_next :: Ptr C_xmmsc_connection -> CInt -> IO (Ptr C_xmmsc_result)+-- |Set next entry in the playlist.+setNext :: Connection -> Int -> IO Result+setNext connection pos = do+ wrapCallResult (\c -> xmmsc_playlist_set_next c (fromIntegral pos)) connection+++--xmmsc_result_t * xmmsc_playlist_set_next_rel (xmmsc_connection_t *c, int pos)+foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsc_playlist_set_next_rel" + xmmsc_playlist_set_next_rel :: Ptr C_xmmsc_connection -> CInt -> IO (Ptr C_xmmsc_result)+-- |Same as setNextRel but relative to the current postion.+setNextRel :: Connection -> Int -> IO Result+setNextRel connection pos = do+ wrapCallResult (\c -> xmmsc_playlist_set_next_rel c (fromIntegral pos)) connection+++--xmmsc_result_t *xmmsc_playlist_load (xmmsc_connection_t *c, const char *name)+foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsc_playlist_load" + xmmsc_playlist_load :: Ptr C_xmmsc_connection -> CString -> IO (Ptr C_xmmsc_result)+-- |Load a playlist as the current active playlist.+load :: Connection -> String -> IO Result+load connection name = + withString name (\ c_name ->+ wrapCallResult (\c -> xmmsc_playlist_load c c_name) connection)+ ++--xmmsc_result_t *xmmsc_broadcast_playlist_loaded (xmmsc_connection_t *c)+foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsc_broadcast_playlist_loaded" + xmmsc_broadcast_playlist_loaded :: Ptr C_xmmsc_connection -> IO (Ptr C_xmmsc_result)+-- |Request the playlist_loaded broadcast. +broadcastLoaded :: Connection -> IO Result+broadcastLoaded = wrapCallResult xmmsc_broadcast_playlist_loaded
+ Network/XMMS/Result.hs view
@@ -0,0 +1,105 @@+{-# LANGUAGE ForeignFunctionInterface #-}++-- Copyright 2010 Evgeniy Vodolazskiy (waterlaz@gmail.com)+--+-- This library is free software; you can redistribute it and/or+-- modify it under the terms of the GNU Lesser General Public+-- License as published by the Free Software Foundation; either+-- version 2.1 of the License, or (at your option) any later version.+--+-- This library is distributed in the hope that it will be useful,+-- but WITHOUT ANY WARRANTY; without even the implied warranty of+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU+-- Lesser General Public License for more details.++module Network.XMMS.Result where++import Foreign+import Foreign.Ptr+import Foreign.C.Types+import Foreign.C.String+import Foreign.ForeignPtr+import Foreign.Marshal.Alloc++import Network.XMMS.Constants+import Network.XMMS.Types+import Network.XMMS.Value+import Network.XMMS.Utilities++++--Get the class of the result (default, signal, broadcast).+--xmmsc_result_type_t xmmsc_result_get_class (xmmsc_result_t *res)+++--void xmmsc_result_disconnect (xmmsc_result_t *res)+foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsc_result_disconnect" + xmmsc_result_disconnect :: Ptr C_xmmsc_result -> IO ()+-- |Disconnect a signal or a broadcast.+resultDisconnect :: Result -> IO ()+resultDisconnect result = withForeignPtr result xmmsc_result_disconnect++++--return the cookie of a resultset.+--uint32_t xmmsc_result_cookie_get (xmmsc_result_t *res)+ +--void xmmsc_result_visc_set (xmmsc_result_t *res, xmmsc_visualization_t *visc)++--xmmsc_visualization_t * xmmsc_result_visc_get (xmmsc_result_t *res)++--xmmsv_t *value, void *userdata+foreign import ccall "wrapper"+ wrapper :: (Ptr C_xmmsc_value -> Ptr () -> IO CInt) -> IO (FunPtr (Ptr C_xmmsc_value -> Ptr () -> IO CInt))+ +xmmsCallback :: (XMMSCV -> IO Bool) -> IO (FunPtr (Ptr C_xmmsc_value -> Ptr () -> IO CInt))+xmmsCallback f = do+ let c_f valuePtr ptr = do+ value <- convertValueCtoHs valuePtr+ --result <- newForeignPtr xmmsc_result_unref resultPtr+ keepAlive <- f value+ if keepAlive then return 1 else return 0+ wrapper c_f+ + + ++--void xmmsc_result_notifier_set (xmmsc_result_t *res, xmmsc_result_notifier_t func, void *user_data)+-- |Set up a callback for the result retrival. This callback Will be called when the answers arrives. +foreign import ccall safe "xmmsclient/xmmsclient.h xmmsc_result_notifier_set" + xmmsc_result_notifier_set :: Ptr C_xmmsc_result -> FunPtr (Ptr C_xmmsc_value -> Ptr () -> IO CInt) -> Ptr () -> IO ()+resultNotifierSet :: Result -> (XMMSCV -> IO Bool) -> IO ()+resultNotifierSet result f = do+ xmmsF <- xmmsCallback f+ withForeignPtr result (\ptr -> xmmsc_result_notifier_set ptr xmmsF nullPtr)+++--Set up a callback for the result retrieval.+--void xmmsc_result_notifier_set_full (xmmsc_result_t *res, xmmsc_result_notifier_t func, void *user_data, xmmsc_user_data_free_func_t free_func)+ + +--void xmmsc_result_wait (xmmsc_result_t *res)+foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsc_result_wait" + xmmsc_result_wait :: Ptr C_xmmsc_result -> IO ()+-- |Block for the reply.+resultWait :: Result -> IO ()+resultWait result = withForeignPtr result xmmsc_result_wait+++--xmmsc_connection_t * xmmsc_result_get_connection (xmmsc_result_t *res)+foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsc_result_get_connection" + xmmsc_result_get_connection :: Ptr C_xmmsc_result -> IO (Ptr C_xmmsc_connection)+resultGetConnection :: Result -> IO (Connection)+resultGetConnection result = do+ conPtr <- withForeignPtr result xmmsc_result_get_connection+ xmmsc_ref conPtr+ newForeignPtr xmmsc_unref conPtr+ +++--Get the value from a result. +--xmmsv_t * xmmsc_result_get_value (xmmsc_result_t *res)+--This function is not used here and gets imported elsewhere+++
+ Network/XMMS/Types.hs view
@@ -0,0 +1,57 @@+-- Copyright 2010 Evgeniy Vodolazskiy (waterlaz@gmail.com)+--+-- This library is free software; you can redistribute it and/or+-- modify it under the terms of the GNU Lesser General Public+-- License as published by the Free Software Foundation; either+-- version 2.1 of the License, or (at your option) any later version.+--+-- This library is distributed in the hope that it will be useful,+-- but WITHOUT ANY WARRANTY; without even the implied warranty of+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU+-- Lesser General Public License for more details.++module Network.XMMS.Types where++import Foreign+import Foreign.Ptr+import Foreign.C.Types+import Foreign.C.String+import Foreign.ForeignPtr+import Foreign.Marshal.Alloc+import Data.Map (Map)++import Network.XMMS.Constants++++--xmmsc_connection_t*+type C_xmmsc_connection = ()+type Connection = ForeignPtr C_xmmsc_connection++--xmmsc_result_t*+type C_xmmsc_result = ()+type Result = ForeignPtr C_xmmsc_result++--xmmsv_t*+type C_xmmsc_value = ()+data XMMSCV = XMMSNothing+ | XMMSError { xmmsError :: String }+ | XMMSInt { xmmsInt :: Int }+ | XMMSString { xmmsString :: String }+ | XMMSDict { xmmsDict :: (Map String XMMSCV) }+ | XMMSList { xmmsList :: [XMMSCV] }+-- deriving (Show)++instance Show XMMSCV where+ show XMMSNothing = "XMMSNothing"+ show (XMMSError e) = "Error: " ++ e+ show (XMMSInt i) = show i+ show (XMMSString s) = s+ show (XMMSList l) = show l+ show (XMMSDict d) = show d++data SeekMode = SeekCur+ | SeekSet++fromSeekMode SeekCur = playbackSeekCur+fromSeekMode SeekSet = playbackSeekSet
+ Network/XMMS/Utilities.hs view
@@ -0,0 +1,72 @@+{-# LANGUAGE ForeignFunctionInterface #-}++-- Copyright 2010 Evgeniy Vodolazskiy (waterlaz@gmail.com)+--+-- This library is free software; you can redistribute it and/or+-- modify it under the terms of the GNU Lesser General Public+-- License as published by the Free Software Foundation; either+-- version 2.1 of the License, or (at your option) any later version.+--+-- This library is distributed in the hope that it will be useful,+-- but WITHOUT ANY WARRANTY; without even the implied warranty of+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU+-- Lesser General Public License for more details.++module Network.XMMS.Utilities where++import Foreign+import Foreign.Ptr+import Foreign.C.Types+import Foreign.C.String+import Foreign.ForeignPtr+import Foreign.Marshal.Alloc++import Network.XMMS.Constants+import Network.XMMS.Types++------------------++--Help Functions+safePeekCString cstring = if cstring == nullPtr+ then return ""+ else peekCString cstring++withString :: String -> (CString -> IO (a)) -> IO (a)+withString s action |s == "" = action nullPtr+ |otherwise = do+ c_s <- newCString s+ res <- action c_s+ free c_s+ return res++----------------------+++wrapCallResult :: (Ptr C_xmmsc_connection -> IO (Ptr C_xmmsc_result)) -> (Connection -> IO Result)+wrapCallResult c_function =+ flip withForeignPtr + ( \ptrCon -> do+ result <- c_function ptrCon+ newForeignPtr xmmsc_result_unref result) + +++--Decreases the references for the xmmsc_result_t When the number of references reaches 0 it will be freed.+--void xmmsc_result_unref (xmmsc_result_t *res)+foreign import ccall "xmmsclient/xmmsclient.h &xmmsc_result_unref" + xmmsc_result_unref :: FunPtr (Ptr C_xmmsc_result -> IO ())++--References the xmmsc_result_t.+--xmmsc_result_t *xmmsc_result_ref (xmmsc_result_t *res)+foreign import ccall "xmmsclient/xmmsclient.h xmmsc_result_ref" + xmmsc_result_ref :: Ptr C_xmmsc_result -> IO ()+ + +--References the xmmsc_connection_t.+--xmmsc_connection_t * xmmsc_ref (xmmsc_connection_t *c)+foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsc_ref" + xmmsc_ref :: Ptr C_xmmsc_connection -> IO (Ptr C_xmmsc_connection)+ +--void xmmsc_unref (xmmsc_connection_t *connection)+foreign import ccall "xmmsclient/xmmsclient.h &xmmsc_unref" + xmmsc_unref :: FunPtr (Ptr C_xmmsc_connection -> IO ())
+ Network/XMMS/Value.hs view
@@ -0,0 +1,232 @@+{-# LANGUAGE ForeignFunctionInterface #-}++-- Copyright 2010 Evgeniy Vodolazskiy (waterlaz@gmail.com)+--+-- This library is free software; you can redistribute it and/or+-- modify it under the terms of the GNU Lesser General Public+-- License as published by the Free Software Foundation; either+-- version 2.1 of the License, or (at your option) any later version.+--+-- This library is distributed in the hope that it will be useful,+-- but WITHOUT ANY WARRANTY; without even the implied warranty of+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU+-- Lesser General Public License for more details.++module Network.XMMS.Value where++import Foreign+import Foreign.Ptr+import Foreign.C.Types+import Foreign.C.String+import Foreign.ForeignPtr+import Foreign.Marshal.Alloc+import Data.Map (Map)+import Data.Map as Map++import Network.XMMS.Utilities+import Network.XMMS.Constants+import Network.XMMS.Types+++--xmmsv_t* xmmsc_result_get_value(xmmsc_result_t *result)+foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsc_result_get_value" + xmmsc_result_get_value :: Ptr C_xmmsc_result -> IO (Ptr C_xmmsc_value)+resultGetValue :: Result -> IO XMMSCV+resultGetValue result =+ withForeignPtr result (\ptrRes -> do+ value <- xmmsc_result_get_value ptrRes+ convertValueCtoHs value+ )++{-propdictToDict :: [(String, XMMSCV)] -> [(String, XMMSCV)]+propdictToDict dict = concat $ Map.map cleanSource dict+ where cleanSource (key, XMMSDict dict) = zip (repeat key) (map snd dict)+ cleanSource x = [x] -}++propdictToDict :: (Map String XMMSCV) -> (Map String XMMSCV)+propdictToDict dict = Map.map cleanSource dict+ where cleanSource (XMMSDict dict) = head $ elems dict+ cleanSource _ = error "the dictionary is not a propdict"+++--void xmmsv_unref (xmmsv_t *val)+foreign import ccall unsafe "xmmsclient/xmmsclient.h &xmmsv_unref" + xmmsv_unref :: FunPtr (Ptr C_xmmsc_value -> IO ())++--xmmsv_t* xmmsv_new_int (int32_t i) +foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsv_new_int" + xmmsv_new_int :: CInt -> IO (Ptr C_xmmsc_value)++--xmmsv_t* xmmsv_new_string(const char *s) +foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsv_new_string" + xmmsv_new_string :: CString -> IO (Ptr C_xmmsc_value)++--xmmsv_t* xmmsv_new_list (void ) +foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsv_new_list" + xmmsv_new_list :: IO (Ptr C_xmmsc_value)++--int xmmsv_list_append(xmmsv_t *listv, xmmsv_t *val) +foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsv_list_append" + xmmsv_list_append :: Ptr C_xmmsc_value -> Ptr C_xmmsc_value -> IO CInt++convertValueHstoC :: XMMSCV -> IO (ForeignPtr C_xmmsc_value)+convertValueHstoC (XMMSInt i) = do+ ptrValue <- xmmsv_new_int (fromIntegral i)+ newForeignPtr xmmsv_unref ptrValue++convertValueHstoC (XMMSString s) = do+ cStr <- newCString s+ ptrValue <- xmmsv_new_string cStr+ free cStr+ newForeignPtr xmmsv_unref ptrValue ++convertValueHstoC (XMMSList l) = do+ ptrList <- xmmsv_new_list+ mapM_ (\v -> do + fPtr <- convertValueHstoC v+ withForeignPtr fPtr (\ptrValue -> xmmsv_list_append ptrList ptrValue))+ l+ newForeignPtr xmmsv_unref ptrList+ ++convertValueCtoHs :: Ptr C_xmmsc_value -> IO XMMSCV+convertValueCtoHs value = do+ vType <- xmmsv_get_type value+ convertValueType' vType value+ where convertValueType' vType value + |vType==typeError = do+ errorMsg <- xmmsVGetError value+ return $ XMMSError errorMsg+ |vType==typeInt32 = do+ maybeIntValue <- xmmsVGetInt value+ case maybeIntValue of+ Just intValue -> return $ XMMSInt $ fromIntegral intValue+ Nothing -> return $ XMMSError "failed to get int value"+ |vType==typeString = do+ maybeValue <- xmmsVGetString value+ case maybeValue of+ Just stringValue -> return $ XMMSString stringValue+ Nothing -> return $ XMMSError "failed to get string value"+ + |vType==typeList = do+ maybeValue <- xmmsVGetList value+ case maybeValue of+ Just listValue -> return $ XMMSList listValue+ Nothing -> return $ XMMSError "failed to get list value"+ + |vType==typeDict = do+ count <- xmmsv_dict_get_size value+ keys <- allocate_keys count+ values <- allocate_values count+ xmmsv_get_dict keys values value+ dictValue <- marshallDict keys values+ free_keys keys+ free_values values+ return $ XMMSDict dictValue+ |vType==typeString = do+ maybeValue <- xmmsVGetString value+ case maybeValue of+ Just stringValue -> return $ XMMSString stringValue+ Nothing -> return $ XMMSError "failed to get string value"+ |otherwise = return XMMSNothing++marshallDict :: Ptr CString -> Ptr (Ptr C_xmmsc_value) -> IO (Map String XMMSCV)+marshallDict keys values = do+ key <- peek keys+ value <- peek values+ if key==nullPtr || value==nullPtr+ then return Map.empty+ else do+ rest <- marshallDict (plusPtr keys (sizeOf key)) (plusPtr values (sizeOf value))+ keyString <- safePeekCString key+ valueHS <- convertValueCtoHs value+ return $ Map.insert keyString valueHS rest+++--int xmmsv_list_get_size(xmmsv_t* listv) +foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsv_list_get_size" + xmmsv_list_get_size :: Ptr C_xmmsc_value -> IO CInt+xmmsVListGetSize :: Ptr C_xmmsc_value -> IO Int+xmmsVListGetSize value = do+ size <- xmmsv_list_get_size value+ return $ fromIntegral size++-- int xmmsv_list_get (xmmsv_t *listv, int pos, xmmsv_t **val)+foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsv_list_get" + xmmsv_list_get :: Ptr C_xmmsc_value -> CInt -> Ptr (Ptr C_xmmsc_value) -> IO Int+xmmsVGetList :: Ptr C_xmmsc_value -> IO(Maybe [XMMSCV])+xmmsVGetList value = do+ size <- xmmsVListGetSize value+ let retrieve k |k==size = return []+ |otherwise = do+ buf <- malloc+ xmmsv_list_get value (fromIntegral k) buf+ bufValue <- peek buf+ current <- convertValueCtoHs bufValue+ rest <- retrieve (k+1)+ return (current:rest)+ res <- retrieve 0+ return (Just res)+++--void xmmsv_get_dict(char **key, xmmsv_t **value, xmmsv_t *dict)+foreign import ccall unsafe "XMMS/XMMSUtils.h xmmsv_get_dict" + xmmsv_get_dict :: Ptr CString -> Ptr (Ptr C_xmmsc_value) -> Ptr C_xmmsc_value -> IO ()++foreign import ccall unsafe "XMMS/XMMSUtils.h allocate_keys" allocate_keys :: CInt -> IO (Ptr CString)+foreign import ccall unsafe "XMMS/XMMSUtils.h free_keys" free_keys :: Ptr CString -> IO ()+foreign import ccall unsafe "XMMS/XMMSUtils.h allocate_values" allocate_values :: CInt -> IO (Ptr (Ptr C_xmmsc_value))+foreign import ccall unsafe "XMMS/XMMSUtils.h free_values" free_values :: Ptr (Ptr C_xmmsc_value) -> IO ()++++--int xmmsv_dict_get_size (xmmsv_t *dictv)+foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsv_dict_get_size" + xmmsv_dict_get_size :: Ptr C_xmmsc_value -> IO CInt++--int xmmsv_get_error (xmmsv_t *return_value, char *err_buf)+foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsv_get_error" + xmmsv_get_error :: Ptr C_xmmsc_value -> Ptr CString -> IO CInt+xmmsVGetError :: Ptr C_xmmsc_value -> IO String+xmmsVGetError value = do+ bufPtr <- malloc+ res <- xmmsv_get_error value bufPtr+ if res==0 then return ""+ else do+ buf <- peek bufPtr+ free bufPtr+ safePeekCString buf++--int xmmsv_get_int (xmmsv_t *return_value, int *v)+foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsv_get_int" + xmmsv_get_int :: Ptr C_xmmsc_value -> Ptr CInt -> IO CInt+xmmsVGetInt :: Ptr C_xmmsc_value -> IO (Maybe Int)+xmmsVGetInt value = do+ v <- malloc+ res <- xmmsv_get_int value v+ intValue <- peek v+ free v+ if res==0 then return Nothing+ else return $ Just $ fromIntegral intValue++--int xmmsv_get_string (xmmsv_t *return_value, int *v)+foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsv_get_string" + xmmsv_get_string :: Ptr C_xmmsc_value -> Ptr CString -> IO CInt+xmmsVGetString :: Ptr C_xmmsc_value -> IO (Maybe String)+xmmsVGetString value = do+ bufPtr <- malloc+ res <- xmmsv_get_string value bufPtr+ if res==0 then return Nothing+ else do+ buf <- peek bufPtr+ res <- safePeekCString buf+ free bufPtr+ return $ Just res+++++--xmmsv_type_t xmmsv_get_type (xmmsv_t* value)+foreign import ccall unsafe "xmmsclient/xmmsclient.h xmmsv_get_type" + xmmsv_get_type :: Ptr C_xmmsc_value -> IO CInt+
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ XMMS.cabal view
@@ -0,0 +1,51 @@+Name: XMMS+Version: 0.1+Description: Provides the haskell client lib for XMMS2+Synopsis: XMMS2 client library.+License: LGPL+License-file: LICENSE+Author: Vodolazskiy Evgeniy+Maintainer: waterlaz@gmail.com+Build-Type: Simple+Cabal-Version: >=1.2+Category: Network, Sound+++Build-depends: base >= 1.0 && < 5,+ containers+Build-Type: Simple+Tested-with: GHC==6.12.1++Exposed-modules:+ Network.XMMS.Client, Network.XMMS.Playback, + Network.XMMS.Playlist, Network.XMMS.Config,+ Network.XMMS.Medialib,+ Network.XMMS.Client.Glib++Other-modules:+ Network.XMMS.Constants, Network.XMMS.Result, + Network.XMMS.Value, Network.XMMS.Types,+ Network.XMMS.Utilities++C-sources:+ cbits/XMMSUtils.c++Extra-libraries: xmmsclient, xmmsclient-glib++Extra-source-files:+ Network/XMMS/Utilities.hs,+ Network/XMMS/Result.hs, + Network/XMMS/Value.hs,+ Network/XMMS/Types.hs,+ Network/XMMS/Constants.hsc,+ cbits/XMMSUtils.c, cbits/XMMSUtils.h++Data-files:+ example/tut1.hs, example/tut2.hs,+ example/tut3.hs, example/tut4.hs,+ example/tut7.hs++Extensions: CPP, ForeignFunctionInterface++Include-dirs: cbits . /usr/include/xmms2 +
+ cbits/XMMSUtils.c view
@@ -0,0 +1,43 @@+#include <xmmsclient/xmmsclient.h>+#include <stdlib.h>++struct pass_value{+ char **keys;+ xmmsv_t **values;+ int count;+};++void unfold_dict_foreach (const char *key, xmmsv_t *value, void *keys_values_void){+ struct pass_value *keys_values;+ keys_values = (struct pass_value *) keys_values_void;+ keys_values->keys[keys_values->count] = (char*) key;+ keys_values->values[keys_values->count] = value;+ keys_values->count++;+ +}++char** allocate_keys(int n){+ return malloc(sizeof(char*) * (n + 1));+}++void free_keys(char** keys){+ free(keys);+}++xmmsv_t** allocate_values(int n){+ return malloc(sizeof(xmmsv_t *) * (n + 1));+}++void free_values(xmmsv_t** values){+ free(values);+}++extern void xmmsv_get_dict(char **key, xmmsv_t **value, xmmsv_t *dict){+ struct pass_value keys_values;+ keys_values.keys = key;+ keys_values.values = value;+ keys_values.count = 0;+ xmmsv_dict_foreach (dict, unfold_dict_foreach, (void*)(&keys_values));+ key[keys_values.count]=NULL;+ value[keys_values.count]=NULL;+}
+ cbits/XMMSUtils.h view
@@ -0,0 +1,14 @@+#ifndef XMMSUTILS+#define XMMSUTILS++extern void xmmsv_get_dict(char **key, xmmsv_t **value, xmmsv_t *dict);++extern char** allocate_keys(int n);++extern void free_keys(char** keys);++extern xmmsv_t** allocate_values(int n);++extern void free_values(xmmsv_t** values);++#endif
+ example/tut1.hs view
@@ -0,0 +1,20 @@+import System+import Network.XMMS.Playback+import Network.XMMS.Client+import Prelude hiding (init)++main = do+ connection <- init "tutorial1"+ xmmsPath <- catch (getEnv "XMMS_PATH") + (\e -> return "")+ connectRes <- connect connection xmmsPath+ if connectRes == 0 then do+ errorMsg <- getLastError connection+ putStrLn $ "Connection failed: " ++ errorMsg+ else do + result <- start connection+ resultWait result+ returnValue <- resultGetValue result+ case returnValue of+ XMMSError msg -> putStrLn $ "playback start returned error: " ++ msg+ _ -> return ()
+ example/tut2.hs view
@@ -0,0 +1,21 @@+import System+import Network.XMMS.Playback+import Network.XMMS.Client+import Prelude hiding (init)++main = do+ connection <- init "tutorial2"+ xmmsPath <- catch (getEnv "XMMS_PATH") + (\e -> return "")+ connectRes <- connect connection xmmsPath+ if connectRes == 0 then do+ errorMsg <- getLastError connection+ putStrLn $ "Connection failed: " ++ errorMsg+ else do+ result <- currentID connection+ resultWait result+ returnValue <- resultGetValue result+ case returnValue of+ XMMSError msg -> putStrLn $ "playback start returned error: " ++ msg+ XMMSInt id -> putStrLn $ "playing track with ID:" ++ show id+ _ -> return ()
+ example/tut3.hs view
@@ -0,0 +1,33 @@+import System+import Network.XMMS.Playback+import Network.XMMS.Client+import Network.XMMS.Medialib+import Data.Map (Map)+import Data.Map as Map+import Prelude hiding (init)++main = do+ connection <- init "tutorial3"+ xmmsPath <- catch (getEnv "XMMS_PATH") + (\e -> return "")+ connectRes <- connect connection xmmsPath+ if connectRes == 0 then do+ errorMsg <- getLastError connection+ putStrLn $ "Connection failed: " ++ errorMsg+ else do+ result <- currentID connection+ resultWait result+ returnValue <- resultGetValue result+ case returnValue of+ XMMSError msg -> putStrLn $ "playback start returned error: " ++ msg+ XMMSInt id -> do + putStrLn $ "playing track with ID:" ++ show id+ result <- medialibGetInfo connection id+ resultWait result+ returnValue <- resultGetValue result+ case returnValue of+ XMMSDict dict -> mapM_ (\(key, value) -> putStrLn (key ++ " : " ++ show value)) (assocs $ propdictToDict dict)+ _ -> error "not a dictionary"+ + return ()+ _ -> return ()
+ example/tut4.hs view
@@ -0,0 +1,46 @@+import System+import Prelude hiding (init)+import qualified Network.XMMS.Playlist as Playlist+import Network.XMMS.Playback+import Network.XMMS.Medialib+import Network.XMMS.Client+import Control.Monad+import Data.Maybe+import Data.Map (Map)+import qualified Data.Map as Map++ +printInfo connection id = do+ result <- medialibGetInfo connection id+ resultWait result+ infoOnId <- resultGetValue result+ case infoOnId of+ XMMSDict dict -> do+ let info = propdictToDict dict+ artist = liftM xmmsString $ Map.lookup "artist" info+ title = liftM xmmsString $ Map.lookup "title" info+ bitrate = liftM (show.xmmsInt) $ Map.lookup "bitrate" info+ + when (isJust artist) (putStrLn $ "artist = " ++ fromJust artist)+ when (isJust title) (putStrLn $ "title = " ++ fromJust title)+ when (isJust bitrate) (putStrLn $ "bitrate = " ++ fromJust bitrate)+ + _ -> error "not a dictionary"++main = do++ connection <- init "tutorial4"+ xmmsPath <- catch (getEnv "XMMS_PATH")+ (\e -> return "")+ connectRes <- connect connection xmmsPath+ if connectRes == 0 then do+ errorMsg <- getLastError connection+ putStrLn $ "Connection failed: " ++ errorMsg+ else do+ result <- Playlist.listEntries connection ""+ resultWait result+ returnValue <- resultGetValue result+ case returnValue of+ XMMSError msg -> putStrLn $ "Couldn't retrieve playlist entries: " ++ msg+ XMMSList ids -> mapM_ (\(XMMSInt id) -> printInfo connection id) ids+ _ -> return ()
+ example/tut7.hs view
@@ -0,0 +1,35 @@+import System+import Data.IORef+import Prelude hiding (init)+import Network.XMMS.Playback+import Network.XMMS.Client+import Network.XMMS.Client.Glib+import Network.XMMS.Playlist as Playlist+import System.Glib.MainLoop++main = do+ connection <- init "tutorial4"+ xmmsPath <- catch (getEnv "XMMS_PATH")+ (\e -> return "")+ connectRes <- connect connection xmmsPath+ if connectRes == 0 then do+ errorMsg <- getLastError connection+ putStrLn $ "Connection failed: " ++ errorMsg+ else do+ loop <- mainLoopNew Nothing False+ result <- broadcastCurrentID connection+ count <- newIORef 0+ resultNotifierSet + result + (\(XMMSInt pos) -> do+ putStrLn $ "playing ID: " ++ (show pos)+ modifyIORef count (+1)+ countV <- readIORef count+ if countV<5 then do+ return True+ else do + putStrLn $ "Playback has been called " ++ (show countV) ++ " times. Exiting..."+ mainLoopQuit loop+ return False)+ mainLoopGmainInit connection+ mainLoopRun loop