cedlemo / ocaml-libmpdclient Goto Github PK
View Code? Open in Web Editor NEWmpd client library implementation in OCaml.
License: GNU General Public License v3.0
mpd client library implementation in OCaml.
License: GNU General Public License v3.0
finish the playback_options commands in bin/Ompdc
Use Connexion instead of Connection
when the lib is used in a synchrone way, a classical connection works like this:
in an asynchrone way:
if at this line,
OCaml-libmpdclient/lib/Connection_lwt.ml
Line 104 in 2dfea67
It would be better to add a Buffer in the connection record and use bigger maxlen.
Unix
and Lwt_unix
functions for uncaugth exceptionnext :
./_build/default/bin/ompdc.exe status -p 20
Connection refused connect
ompdc: internal error, uncaught exception:
Unix.Unix_error(Unix.ENOTCONN, "recv", "")
⟩ ./_build/default/bin/ompdc.exe playback_options --mixrampdelay 1
Mpd server : OK MPD 0.20.0
~/Projets/OCaml/ocaml-libmpdclient · (master±)
⟩ ./_build/default/bin/ompdc.exe status --mixrampdelay
Mpd server : OK MPD 0.20.0
ompdc: internal error, uncaught exception:
Failure("int_of_string")
Use:
t
for the main type of the module. (ie. Client.t
and not Client.c
)https://www.musicpd.org/doc/html/protocol.html#binary-responses
The MPD server can send binary data.
How to implement it ?
The Mpd specifications have been updated:
https://www.musicpd.org/doc/html/protocol.html#general-protocol-syntax
what is the form of the request that is recognized at the Connection
level ?
what is the form of the request returned to the Client
level ?
what is the form of the request recognized at the Client
level ?
Do it both for the non-Lwt and Lwt connexion and client.
Use Notty in order to display information and clean terminal (could be used for futur consol mpd client like ncmpcpp)
create 2 threads and run them with Lwt.join
Notty.term
for the first one thread, implementation idea :
Lwt_timeout
?Lwt_unix
(https://github.com/pqwy/notty/blob/master/examples/life.ml#L81) seems to be the good choicefor the second thread how to present data to the first thread ?
Display error message when a command returns an Mpd error response.
In travis, use docker and install mpd server in order to test all the commands.
Write test cases for Connection_lwt
regexes
The interface does not seem to redrawn as expected when resize events occur.
Create a new branch where all the unix or others exceptions are transformed to classical Error
.
2 pbs:
In docker the tests for playback fail because the mpd server can not play any songs.
And it can not play because after
docker run --interactive --tty ocaml-libmpdclient/ubuntu-17.04
mpd
Jan 06 17:11 : server_socket: bind to '[::1]:6600' failed: Cannot assign requested address (continuing anyway, because binding to '127.0.0.1:6600' succeeded)
Jan 06 17:11 : errno: Failed to open /home/ocaml-libmpdclient/mpd/tag_cache: No such file or directory
ocaml-libmpdclient@422228ad13e0:~/ocaml-libmpdclient$ ./_build/default/samples/try_mpd_queries.exe "load bach"
received: OK MPD 0.19.0
received: OK
ocaml-libmpdclient@422228ad13e0:~/ocaml-libmpdclient$ ./_build/default/samples/try_mpd_queries.exe "playlist"
received: OK MPD 0.19.0
received: 0:file: kunst01.mp3
1:file: kunst02.mp3
2:file: kunst03.mp3
3:file: kunst04.mp3
4:file: kunst05.mp3
5:file: kunst06.mp3
6:file: kunst07.mp3
7:file: kunst08.mp3
8:file: kunst09.mp3
9:file: kunst10.mp3
10:file: kunst11.mp3
OK
When I try to play something and check the status:
ocaml-libmpdclient@422228ad13e0:~/ocaml-libmpdclient$ ./_build/default/samples/try_mpd_queries.exe "play"
received: OK MPD 0.19.0
received: OK
ocaml-libmpdclient@422228ad13e0:~/ocaml-libmpdclient$ ./_build/default/samples/try_mpd_queries.exe "status"
received: OK MPD 0.19.0
received: volume: -1
repeat: 0
random: 0
single: 0
consume: 0
playlist: 2
playlistlength: 11
mixrampdb: 0.000000
state: pause
song: 0
songid: 1
time: 0:230
elapsed: 0.000
bitrate: 0
audio: 22050:24:2
error: Failed to open audio output
nextsong: 1
nextsongid: 2
OK
How to configure mpd ? is the current mpd.conf is enough ? is there any audio ouput in the default docker image ? should I create a dummy audio output (/dev/null)?
How to create a fake audio ouput?
A request to mpd returns something like "one or multiple lines" + "\nOK\n".
they are identified in https://github.com/cedlemo/OCaml-libmpdclient/blob/master/lib/Connection_lwt.ml#L152
with
let request_response mpd_data =
let pattern = "\\(\\(\n\\|.\\)*OK\n\\)" in
check_full_response mpd_data pattern 1 0
more globaly a request is done via https://github.com/cedlemo/OCaml-libmpdclient/blob/master/lib/Client_lwt.ml#L66
let request client cmd =
let {connection = c; _} = client in
Connection_lwt.write c (cmd ^ "\n")
>>= fun _ ->
Connection_lwt.read_request_response c
>>= fun response ->
let parsed_response = Protocol.parse_response response in
Lwt.return parsed_response
And the request is parsed in order to see if Mpd returned an Error or an Ok response with:
https://github.com/cedlemo/OCaml-libmpdclient/blob/master/lib/Protocol.ml#L81
let parse_response mpd_response =
let ok_response_reg = Str.regexp "\\(\\(\n\\|.\\)*\\)OK$" in
if (Str.string_match ok_response_reg mpd_response 0 == true) then
let str = Str.matched_group 1 mpd_response in
if str = "" then Ok (None) else Ok (Some str)
else
Error (parse_error_response mpd_response)
which means that the response returned by parse_response can possibly have a "\n" at the end which when parsed by Music_database_lwt.list
can generate for example an album name like "an_album\n".
This new line char break further request to mpd.
from
type response = Ok of string | Error of (ack_error * int * string * string)
to
type response = Ok of string option | Error of (ack_error * int * string * string)
The way Client.status return when there is an error is really bad. use something like the result type and remove the empty Status type.
The functions of the API should :
when, an exception occurs,
Lwt.return_none
on success.
It is then up to the user of the Api to exit with an error code in the thread launched in Lwt_main.run
The functions of the API should :
when, an exception occurs,
Lwt.fail
on success.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.