2012-07-11 07:36:45 +00:00
|
|
|
--assert(package.loadlib(MY_PATH .. "./mpdc.so", "luaopen_mpdc"))
|
|
|
|
require "mpdc"
|
2012-03-15 23:52:06 +00:00
|
|
|
local M = {}
|
|
|
|
local type = ""
|
2013-04-13 15:17:09 +00:00
|
|
|
local conf = conf
|
2012-03-15 23:52:06 +00:00
|
|
|
|
|
|
|
-- local functions
|
2012-07-11 07:36:45 +00:00
|
|
|
local show, mpc_play_search, notify
|
2012-03-15 23:52:06 +00:00
|
|
|
|
|
|
|
local conn = nil
|
|
|
|
|
|
|
|
local defaults = {}
|
|
|
|
local settings = {}
|
|
|
|
|
|
|
|
defaults.host = "127.0.0.1"
|
|
|
|
defaults.port = 6600
|
|
|
|
defaults.replace_on_search = true
|
|
|
|
|
|
|
|
for key, value in pairs(defaults) do
|
|
|
|
settings[key] = value
|
|
|
|
end
|
|
|
|
|
|
|
|
-- {{{ basic functions
|
|
|
|
|
|
|
|
M.connect = function ()
|
|
|
|
print("Connecting to mpd")
|
2012-07-11 07:36:45 +00:00
|
|
|
conn = mpdc.open(settings.host, settings.port)
|
2012-03-15 23:52:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
M.disconnect = function()
|
|
|
|
if conn ~= nil then conn:close() end
|
|
|
|
conn = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
M.ensure_connection = function()
|
2012-07-11 07:36:45 +00:00
|
|
|
-- connect on first call
|
|
|
|
if conn == nil then M.connect() end
|
2012-03-15 23:52:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
-- }}}
|
|
|
|
|
|
|
|
-- {{{ mpd.ctrl submodule
|
|
|
|
|
|
|
|
M.ctrl = {}
|
|
|
|
|
|
|
|
M.ctrl.toggle = function ()
|
2012-07-11 07:36:45 +00:00
|
|
|
M.ensure_connection()
|
|
|
|
conn:toggle()
|
2012-03-15 23:52:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
M.ctrl.play = function ()
|
2012-07-11 07:36:45 +00:00
|
|
|
M.ensure_connection()
|
|
|
|
conn:play()
|
2012-03-15 23:52:06 +00:00
|
|
|
-- TODO widget updating
|
|
|
|
end
|
|
|
|
|
|
|
|
M.ctrl.pause = function ()
|
2012-07-11 07:36:45 +00:00
|
|
|
M.ensure_connection()
|
|
|
|
conn:pause()
|
2012-03-15 23:52:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
M.ctrl.next = function ()
|
2012-07-11 07:36:45 +00:00
|
|
|
M.ensure_connection()
|
|
|
|
conn:next()
|
2012-03-15 23:52:06 +00:00
|
|
|
-- TODO widget updating
|
|
|
|
end
|
|
|
|
|
|
|
|
M.ctrl.prev = function ()
|
2012-07-11 07:36:45 +00:00
|
|
|
M.ensure_connection()
|
|
|
|
conn:prev()
|
2012-03-15 23:52:06 +00:00
|
|
|
-- TODO widget updating
|
|
|
|
end
|
|
|
|
|
|
|
|
-- }}}
|
|
|
|
|
|
|
|
-- {{{ mpd.prompt submodule
|
|
|
|
|
2013-04-13 15:17:09 +00:00
|
|
|
local clear_before = conf.mpd_prompt_clear_before == nil and
|
2012-03-15 23:52:06 +00:00
|
|
|
true or
|
2013-04-13 15:17:09 +00:00
|
|
|
conf.mpd_prompt_clear_before
|
2012-03-15 23:52:06 +00:00
|
|
|
|
|
|
|
M.prompt = {}
|
|
|
|
|
|
|
|
M.prompt.artist = function()
|
|
|
|
type = "artist"
|
|
|
|
show()
|
|
|
|
end
|
|
|
|
|
|
|
|
M.prompt.album = function()
|
|
|
|
type = "album"
|
|
|
|
show()
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
M.prompt.title = function()
|
|
|
|
type = "title"
|
|
|
|
show()
|
|
|
|
end
|
|
|
|
M.prompt.title = title
|
|
|
|
|
|
|
|
M.prompt.replace_on_search = function(bool)
|
|
|
|
clear_before = bool
|
|
|
|
end
|
|
|
|
|
|
|
|
M.prompt.toggle_replace_on_search = function()
|
|
|
|
clear_before = not clear_before
|
|
|
|
notify("MPD prompts now " ..(
|
|
|
|
clear_before and "replace" or "add to"
|
|
|
|
).. " the playlist")
|
|
|
|
end
|
|
|
|
|
|
|
|
function show()
|
|
|
|
obvious.popup_run_prompt.set_prompt_string("Play ".. type .. ":")
|
|
|
|
obvious.popup_run_prompt.set_cache("/mpd_ ".. type);
|
|
|
|
obvious.popup_run_prompt.set_run_function(mpc_play_search)
|
|
|
|
obvious.popup_run_prompt.run_prompt()
|
|
|
|
end
|
|
|
|
|
|
|
|
function mpc_play_search(s)
|
2012-07-11 07:36:45 +00:00
|
|
|
if clear_before then conn:clear() end
|
|
|
|
local result, num = conn:isearch(type, s)
|
|
|
|
notify("Found " .. (num) .. " matches");
|
|
|
|
conn:iadd(result)
|
|
|
|
conn:play()
|
2012-03-15 23:52:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
-- }}}
|
|
|
|
|
|
|
|
-- {{{ notify wrapper
|
|
|
|
notify = function(stext)
|
|
|
|
if not (naughty == nil) then
|
|
|
|
naughty.notify({
|
|
|
|
text= stext
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
--}}}
|
|
|
|
|
|
|
|
return M
|
|
|
|
|
|
|
|
-- vim: set fenc=utf-8 tw=80 foldmethod=marker :
|