No need to use globals as a separate package to avoid import cycles
This commit is contained in:
parent
49c691e04e
commit
4ae005cbe7
@ -4,34 +4,28 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/aditya-K2/fuzzy"
|
||||
"github.com/aditya-K2/gomp/notify"
|
||||
"github.com/fhs/gompd/mpd"
|
||||
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
CONN *mpd.Client
|
||||
Conn *mpd.Client
|
||||
ArtistTree map[string]map[string]map[string]string
|
||||
NotificationServer interface {
|
||||
Send(string)
|
||||
}
|
||||
WHITE_AND_BOLD string = "[white::b]"
|
||||
WHITE_AND_BOLD string = "[white::b]"
|
||||
DirTree *FileNode
|
||||
Matches fuzzy.Matches
|
||||
SearchContentSlice []interface{}
|
||||
)
|
||||
|
||||
func SetNotificationServer(n interface{ Send(string) }) {
|
||||
NotificationServer = n
|
||||
}
|
||||
|
||||
func SetConnection(c *mpd.Client) {
|
||||
CONN = c
|
||||
}
|
||||
|
||||
func TogglePlayBack() error {
|
||||
status, err := CONN.Status()
|
||||
status, err := Conn.Status()
|
||||
if status["state"] == "play" && err == nil {
|
||||
CONN.Pause(true)
|
||||
Conn.Pause(true)
|
||||
} else if status["state"] == "pause" && err == nil {
|
||||
CONN.Play(-1)
|
||||
Conn.Play(-1)
|
||||
}
|
||||
return err
|
||||
}
|
||||
@ -42,7 +36,7 @@ func TogglePlayBack() error {
|
||||
func GenerateContentSlice(selectedSuggestion string) ([]interface{}, error) {
|
||||
var ContentSlice []interface{}
|
||||
if strings.TrimRight(selectedSuggestion, " ") == "" {
|
||||
NotificationServer.Send("Empty Search!")
|
||||
notify.Notify.Send("Empty Search!")
|
||||
return nil, errors.New("empty Search String Provided")
|
||||
}
|
||||
if _, ok := ArtistTree[selectedSuggestion]; ok {
|
||||
@ -84,7 +78,7 @@ func GenerateContentSlice(selectedSuggestion string) ([]interface{}, error) {
|
||||
// Album Tree is a map of the tracks in that particular album.
|
||||
func GenerateArtistTree() (map[string]map[string]map[string]string, error) {
|
||||
ArtistTree = make(map[string]map[string]map[string]string)
|
||||
AllInfo, err := CONN.ListAllInfo("/")
|
||||
AllInfo, err := Conn.ListAllInfo("/")
|
||||
if err == nil {
|
||||
for _, i := range AllInfo {
|
||||
if _, ArtistExists := ArtistTree[i["Artist"]]; !ArtistExists {
|
||||
@ -118,12 +112,12 @@ func PrintArtistTree(a map[string]map[string]map[string]string) {
|
||||
// Adds All tracks from a specified album to a playlist
|
||||
func AddAlbum(a map[string]map[string]map[string]string, alb string, artist string) {
|
||||
for _, v := range a[artist][alb] {
|
||||
err := CONN.Add(v)
|
||||
err := Conn.Add(v)
|
||||
if err != nil {
|
||||
NotificationServer.Send("Could Not Add Song : " + v)
|
||||
notify.Notify.Send("Could Not Add Song : " + v)
|
||||
}
|
||||
}
|
||||
NotificationServer.Send("Album Added : " + alb)
|
||||
notify.Notify.Send("Album Added : " + alb)
|
||||
}
|
||||
|
||||
// Adds All tracks from a specified artist to a playlist
|
||||
@ -131,31 +125,31 @@ func AddArtist(a map[string]map[string]map[string]string, artist string) {
|
||||
if val, ok := a[artist]; ok {
|
||||
for _, v := range val {
|
||||
for _, path := range v {
|
||||
err := CONN.Add(path)
|
||||
err := Conn.Add(path)
|
||||
if err != nil {
|
||||
NotificationServer.Send("Could Not Add Song : " + path)
|
||||
notify.Notify.Send("Could Not Add Song : " + path)
|
||||
}
|
||||
}
|
||||
}
|
||||
NotificationServer.Send("Artist Added : " + artist)
|
||||
notify.Notify.Send("Artist Added : " + artist)
|
||||
}
|
||||
}
|
||||
|
||||
// Adds Specified Track to the Playlist
|
||||
func AddTitle(a map[string]map[string]map[string]string, artist, alb, track string, addAndPlay bool) {
|
||||
if addAndPlay {
|
||||
id, err := CONN.AddId(a[artist][alb][track], -1)
|
||||
CONN.PlayId(id)
|
||||
id, err := Conn.AddId(a[artist][alb][track], -1)
|
||||
Conn.PlayId(id)
|
||||
if err != nil {
|
||||
NotificationServer.Send("Could Not Add Track : " + track)
|
||||
notify.Notify.Send("Could Not Add Track : " + track)
|
||||
}
|
||||
} else {
|
||||
err := CONN.Add(a[artist][alb][track])
|
||||
err := Conn.Add(a[artist][alb][track])
|
||||
if err != nil {
|
||||
NotificationServer.Send("Could Not Add Track : " + track)
|
||||
notify.Notify.Send("Could Not Add Track : " + track)
|
||||
}
|
||||
}
|
||||
NotificationServer.Send("Track Added : " + track)
|
||||
notify.Notify.Send("Track Added : " + track)
|
||||
}
|
||||
|
||||
/* Querys the Artist Tree for a track and returns a TrackMap (i.e [3]string{artist, album, track} -> Path) which will help us
|
||||
|
@ -1,20 +0,0 @@
|
||||
package globals
|
||||
|
||||
import (
|
||||
"github.com/aditya-K2/fuzzy"
|
||||
"github.com/aditya-K2/gomp/client"
|
||||
"github.com/aditya-K2/gomp/notify"
|
||||
"github.com/aditya-K2/gomp/render"
|
||||
"github.com/aditya-K2/gomp/ui"
|
||||
"github.com/fhs/gompd/mpd"
|
||||
)
|
||||
|
||||
var (
|
||||
Conn *mpd.Client
|
||||
Notify *notify.NotificationServer
|
||||
Renderer *render.Renderer
|
||||
Ui *ui.Application
|
||||
DirTree *client.FileNode
|
||||
SearchContentSlice []interface{}
|
||||
Matches fuzzy.Matches
|
||||
)
|
131
main.go
131
main.go
@ -7,7 +7,6 @@ import (
|
||||
"github.com/aditya-K2/gomp/cache"
|
||||
"github.com/aditya-K2/gomp/client"
|
||||
"github.com/aditya-K2/gomp/config"
|
||||
"github.com/aditya-K2/gomp/globals"
|
||||
"github.com/aditya-K2/gomp/notify"
|
||||
"github.com/aditya-K2/gomp/render"
|
||||
"github.com/aditya-K2/gomp/ui"
|
||||
@ -31,30 +30,28 @@ func main() {
|
||||
} else if nt == "unix" && port != "" {
|
||||
port = ""
|
||||
}
|
||||
globals.Conn, mpdConnectionError = mpd.Dial(nt,
|
||||
client.Conn, mpdConnectionError = mpd.Dial(nt,
|
||||
viper.GetString("NETWORK_ADDRESS")+del+port)
|
||||
if mpdConnectionError != nil {
|
||||
utils.Print("RED", "Could Not Connect to MPD Server\n")
|
||||
utils.Print("GREEN", "Make Sure You Mention the Correct MPD Port in the config file.\n")
|
||||
panic(mpdConnectionError)
|
||||
}
|
||||
CONN := globals.Conn
|
||||
CONN := client.Conn
|
||||
defer CONN.Close()
|
||||
|
||||
client.SetConnection(CONN)
|
||||
ui.SetConnection(CONN)
|
||||
render.SetConnection(CONN)
|
||||
|
||||
cache.SetCacheDir(viper.GetString("CACHE_DIR"))
|
||||
|
||||
globals.Renderer = render.NewRenderer()
|
||||
render.Rendr = render.NewRenderer()
|
||||
// Connecting the Renderer to the Main UI
|
||||
ui.ConnectRenderer(globals.Renderer)
|
||||
ui.ConnectRenderer(render.Rendr)
|
||||
|
||||
globals.Ui = ui.NewApplication()
|
||||
ui.Ui = ui.NewApplication()
|
||||
|
||||
// Connecting the Notification Server to the Main UI
|
||||
notify.ConnectUI(globals.Ui)
|
||||
notify.ConnectUI(ui.Ui)
|
||||
|
||||
fileMap, err := CONN.ListAllInfo("/")
|
||||
if err != nil {
|
||||
@ -64,10 +61,10 @@ func main() {
|
||||
}
|
||||
|
||||
// Generating the Directory Tree for File Navigation.
|
||||
globals.DirTree = client.GenerateDirectoryTree(fileMap)
|
||||
client.DirTree = client.GenerateDirectoryTree(fileMap)
|
||||
|
||||
// Default View upon Opening is of Playlist.
|
||||
views.PView.Update(globals.Ui.ExpandedView)
|
||||
views.PView.Update(ui.Ui.ExpandedView)
|
||||
|
||||
var Volume int64
|
||||
var Random, Repeat bool
|
||||
@ -92,30 +89,26 @@ func main() {
|
||||
// Used for Fuzzy Searching
|
||||
ArtistTreeContent := utils.ConvertToArray(ArtistTree)
|
||||
|
||||
globals.Notify = notify.NewNotificationServer()
|
||||
globals.Notify.Start()
|
||||
notify.Notify = notify.NewNotificationServer()
|
||||
notify.Notify.Start()
|
||||
|
||||
if c, err := CONN.CurrentSong(); err != nil {
|
||||
utils.Print("RED", "Could Not Retrieve the Current Song\n")
|
||||
panic(err)
|
||||
} else {
|
||||
if len(c) != 0 {
|
||||
globals.Renderer.Start(c["file"])
|
||||
render.Rendr.Start(c["file"])
|
||||
} else {
|
||||
globals.Renderer.Start("stop")
|
||||
render.Rendr.Start("stop")
|
||||
}
|
||||
}
|
||||
|
||||
// Connecting Notification Server to Client and Rendering Module so that they can send Notifications
|
||||
client.SetNotificationServer(globals.Notify)
|
||||
render.SetNotificationServer(globals.Notify)
|
||||
|
||||
// This Function Is Responsible for Changing the Focus it uses the Focus Map and Based on it Chooses
|
||||
// the Draw Function
|
||||
views.SetCurrentView(views.PView)
|
||||
globals.Ui.ExpandedView.SetDrawFunc(func(s tcell.Screen, x, y, width, height int) (int, int, int, int) {
|
||||
views.GetCurrentView().Update(globals.Ui.ExpandedView)
|
||||
return globals.Ui.ExpandedView.GetInnerRect()
|
||||
ui.Ui.ExpandedView.SetDrawFunc(func(s tcell.Screen, x, y, width, height int) (int, int, int, int) {
|
||||
views.GetCurrentView().Update(ui.Ui.ExpandedView)
|
||||
return ui.Ui.ExpandedView.GetInnerRect()
|
||||
})
|
||||
|
||||
// Function Maps is used For Mapping Keys According to the Value mapped to the Key the respective Function is called
|
||||
@ -127,7 +120,7 @@ func main() {
|
||||
},
|
||||
"togglePlayBack": func() {
|
||||
if err := client.TogglePlayBack(); err != nil {
|
||||
globals.Notify.Send("Could not Toggle Play Back")
|
||||
notify.Notify.Send("Could not Toggle Play Back")
|
||||
}
|
||||
},
|
||||
"showParentContent": func() {
|
||||
@ -135,19 +128,19 @@ func main() {
|
||||
},
|
||||
"nextSong": func() {
|
||||
if err := CONN.Next(); err != nil {
|
||||
globals.Notify.Send("Could not Select the Next Song")
|
||||
notify.Notify.Send("Could not Select the Next Song")
|
||||
}
|
||||
},
|
||||
"clearPlaylist": func() {
|
||||
if err := CONN.Clear(); err != nil {
|
||||
globals.Notify.Send("Could not Clear the Playlist")
|
||||
notify.Notify.Send("Could not Clear the Playlist")
|
||||
} else {
|
||||
globals.Notify.Send("Playlist Cleared")
|
||||
notify.Notify.Send("Playlist Cleared")
|
||||
}
|
||||
},
|
||||
"previousSong": func() {
|
||||
if err := CONN.Previous(); err != nil {
|
||||
globals.Notify.Send("Could Not Select the Previous Song")
|
||||
notify.Notify.Send("Could Not Select the Previous Song")
|
||||
}
|
||||
},
|
||||
"addToPlaylist": func() {
|
||||
@ -170,7 +163,7 @@ func main() {
|
||||
Volume -= 10
|
||||
}
|
||||
if err := CONN.SetVolume(int(Volume)); err != nil {
|
||||
globals.Notify.Send("Could Not Decrease the Volume")
|
||||
notify.Notify.Send("Could Not Decrease the Volume")
|
||||
}
|
||||
},
|
||||
"increaseVolume": func() {
|
||||
@ -180,50 +173,50 @@ func main() {
|
||||
Volume += 10
|
||||
}
|
||||
if err := CONN.SetVolume(int(Volume)); err != nil {
|
||||
globals.Notify.Send("Could Not Increase the Volume")
|
||||
notify.Notify.Send("Could Not Increase the Volume")
|
||||
}
|
||||
},
|
||||
"navigateToFiles": func() {
|
||||
views.SetCurrentView(views.FView)
|
||||
globals.Ui.Navbar.Select(1, 0)
|
||||
views.FView.Update(globals.Ui.ExpandedView)
|
||||
ui.Ui.Navbar.Select(1, 0)
|
||||
views.FView.Update(ui.Ui.ExpandedView)
|
||||
},
|
||||
"navigateToPlaylist": func() {
|
||||
views.SetCurrentView(views.PView)
|
||||
globals.Ui.Navbar.Select(0, 0)
|
||||
views.PView.Update(globals.Ui.ExpandedView)
|
||||
ui.Ui.Navbar.Select(0, 0)
|
||||
views.PView.Update(ui.Ui.ExpandedView)
|
||||
},
|
||||
"navigateToMostPlayed": func() {
|
||||
globals.Ui.Navbar.Select(2, 0)
|
||||
ui.Ui.Navbar.Select(2, 0)
|
||||
},
|
||||
"navigateToSearch": func() {
|
||||
views.SetCurrentView(views.SView)
|
||||
globals.Ui.Navbar.Select(3, 0)
|
||||
views.SView.Update(globals.Ui.ExpandedView)
|
||||
ui.Ui.Navbar.Select(3, 0)
|
||||
views.SView.Update(ui.Ui.ExpandedView)
|
||||
},
|
||||
"quit": func() {
|
||||
views.GetCurrentView().Quit()
|
||||
},
|
||||
"stop": func() {
|
||||
if err := CONN.Stop(); err != nil {
|
||||
globals.Notify.Send("Could not Stop the Playback")
|
||||
notify.Notify.Send("Could not Stop the Playback")
|
||||
} else {
|
||||
globals.Notify.Send("Playback Stopped")
|
||||
notify.Notify.Send("Playback Stopped")
|
||||
}
|
||||
},
|
||||
"updateDB": func() {
|
||||
_, err = CONN.Update("")
|
||||
if err != nil {
|
||||
globals.Notify.Send("Could Not Update the Database")
|
||||
notify.Notify.Send("Could Not Update the Database")
|
||||
} else {
|
||||
globals.Notify.Send("Database Updated")
|
||||
notify.Notify.Send("Database Updated")
|
||||
}
|
||||
},
|
||||
"deleteSongFromPlaylist": func() {
|
||||
views.GetCurrentView().DeleteSongFromPlaylist()
|
||||
},
|
||||
"FocusSearch": func() {
|
||||
globals.Ui.App.SetFocus(globals.Ui.SearchBar)
|
||||
ui.Ui.App.SetFocus(ui.Ui.SearchBar)
|
||||
},
|
||||
"FocusBuffSearch": func() {
|
||||
views.GetCurrentView().FocusBuffSearchView()
|
||||
@ -235,12 +228,12 @@ func main() {
|
||||
// for each event T, P, SPACE mapped to the same function togglePlayBack
|
||||
config.GenerateKeyMap(FuncMap)
|
||||
|
||||
globals.Ui.SearchBar.SetAutocompleteFunc(func(c string) []string {
|
||||
ui.Ui.SearchBar.SetAutocompleteFunc(func(c string) []string {
|
||||
if views.GetCurrentView().GetViewName() == "BuffSearchView" {
|
||||
return nil
|
||||
} else {
|
||||
if c != "" && c != " " && c != " " {
|
||||
_, _, w, _ := globals.Ui.SearchBar.GetRect()
|
||||
_, _, w, _ := ui.Ui.SearchBar.GetRect()
|
||||
matches := fuzzy.Find(c, ArtistTreeContent)
|
||||
var suggestions []string
|
||||
for i, match := range matches {
|
||||
@ -257,7 +250,7 @@ func main() {
|
||||
})
|
||||
|
||||
// Input Handler
|
||||
globals.Ui.ExpandedView.SetInputCapture(func(e *tcell.EventKey) *tcell.EventKey {
|
||||
ui.Ui.ExpandedView.SetInputCapture(func(e *tcell.EventKey) *tcell.EventKey {
|
||||
if val, ok := config.KEY_MAP[int(e.Rune())]; ok {
|
||||
FuncMap[val]()
|
||||
return nil
|
||||
@ -265,18 +258,18 @@ func main() {
|
||||
if views.GetCurrentView().GetViewName() == "PlaylistView" {
|
||||
if e.Rune() == 'j' || e.Rune() == 'k' {
|
||||
if p, err := CONN.PlaylistInfo(-1, -1); err != nil {
|
||||
globals.Notify.Send("Error Getting PlaylistInfo")
|
||||
notify.Notify.Send("Error Getting PlaylistInfo")
|
||||
} else {
|
||||
if len(p) == 0 {
|
||||
globals.Notify.Send("Empty Playlist")
|
||||
notify.Notify.Send("Empty Playlist")
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if views.GetCurrentView().GetViewName() == "SearchView" {
|
||||
if e.Rune() == 'j' || e.Rune() == 'k' {
|
||||
if globals.SearchContentSlice == nil || len(globals.SearchContentSlice) == 0 {
|
||||
globals.Notify.Send("No Search Results")
|
||||
if client.SearchContentSlice == nil || len(client.SearchContentSlice) == 0 {
|
||||
notify.Notify.Send("No Search Results")
|
||||
return nil
|
||||
}
|
||||
}
|
||||
@ -285,21 +278,21 @@ func main() {
|
||||
}
|
||||
})
|
||||
|
||||
globals.Ui.SearchBar.SetDoneFunc(func(e tcell.Key) {
|
||||
ui.Ui.SearchBar.SetDoneFunc(func(e tcell.Key) {
|
||||
if e == tcell.KeyEnter {
|
||||
globals.Ui.ExpandedView.Select(0, 0)
|
||||
ui.Ui.ExpandedView.Select(0, 0)
|
||||
if views.GetCurrentView().GetViewName() == "BuffSearchView" {
|
||||
globals.Ui.App.SetFocus(globals.Ui.ExpandedView)
|
||||
ui.Ui.App.SetFocus(ui.Ui.ExpandedView)
|
||||
} else {
|
||||
views.SetCurrentView(views.SView)
|
||||
globals.SearchContentSlice = nil
|
||||
globals.SearchContentSlice, err = client.GenerateContentSlice(globals.Ui.SearchBar.GetText())
|
||||
client.SearchContentSlice = nil
|
||||
client.SearchContentSlice, err = client.GenerateContentSlice(ui.Ui.SearchBar.GetText())
|
||||
if err != nil {
|
||||
globals.Notify.Send("Could Not Retrieve the Results")
|
||||
notify.Notify.Send("Could Not Retrieve the Results")
|
||||
} else {
|
||||
globals.Ui.SearchBar.SetText("")
|
||||
globals.Ui.App.SetFocus(globals.Ui.ExpandedView)
|
||||
globals.Ui.Navbar.Select(3, 0)
|
||||
ui.Ui.SearchBar.SetText("")
|
||||
ui.Ui.App.SetFocus(ui.Ui.ExpandedView)
|
||||
ui.Ui.Navbar.Select(3, 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -307,39 +300,39 @@ func main() {
|
||||
if views.GetCurrentView().GetViewName() == "SearchView" {
|
||||
} else if views.GetCurrentView().GetViewName() == "BuffSearchView" {
|
||||
views.SetCurrentView(views.FView)
|
||||
globals.Matches = nil
|
||||
client.Matches = nil
|
||||
}
|
||||
globals.Ui.SearchBar.SetText("")
|
||||
globals.Ui.App.SetFocus(globals.Ui.ExpandedView)
|
||||
ui.Ui.SearchBar.SetText("")
|
||||
ui.Ui.App.SetFocus(ui.Ui.ExpandedView)
|
||||
}
|
||||
})
|
||||
|
||||
globals.Ui.ExpandedView.SetDoneFunc(func(e tcell.Key) {
|
||||
ui.Ui.ExpandedView.SetDoneFunc(func(e tcell.Key) {
|
||||
if e == tcell.KeyEscape {
|
||||
if views.GetCurrentView().GetViewName() == "BuffSearchView" {
|
||||
views.SetCurrentView(views.FView)
|
||||
globals.Ui.SearchBar.SetText("")
|
||||
globals.Matches = nil
|
||||
ui.Ui.SearchBar.SetText("")
|
||||
client.Matches = nil
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
globals.Ui.SearchBar.SetChangedFunc(func(text string) {
|
||||
ui.Ui.SearchBar.SetChangedFunc(func(text string) {
|
||||
if views.GetCurrentView().GetViewName() == "BuffSearchView" {
|
||||
var f client.FileNodes = globals.DirTree.Children
|
||||
globals.Matches = fuzzy.FindFrom(text, f)
|
||||
views.BuffSView.Update(globals.Ui.ExpandedView)
|
||||
var f client.FileNodes = client.DirTree.Children
|
||||
client.Matches = fuzzy.FindFrom(text, f)
|
||||
views.BuffSView.Update(ui.Ui.ExpandedView)
|
||||
}
|
||||
})
|
||||
|
||||
go func() {
|
||||
for {
|
||||
globals.Ui.App.Draw()
|
||||
ui.Ui.App.Draw()
|
||||
time.Sleep(time.Second)
|
||||
}
|
||||
}()
|
||||
|
||||
if err := globals.Ui.App.Run(); err != nil {
|
||||
if err := ui.Ui.App.Run(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
@ -12,19 +12,20 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
UI *ui.Application
|
||||
UI *ui.Application
|
||||
Notify *NotificationServer
|
||||
)
|
||||
|
||||
func ConnectUI(a *ui.Application) {
|
||||
UI = a
|
||||
}
|
||||
|
||||
/* Notification Primitive */
|
||||
type Notification struct {
|
||||
*tview.Box
|
||||
Text string
|
||||
}
|
||||
|
||||
func ConnectUI(a *ui.Application) {
|
||||
UI = a
|
||||
}
|
||||
|
||||
/* Get A Pointer to A Notification Struct */
|
||||
func NewNotification(s string) *Notification {
|
||||
return &Notification{
|
||||
|
@ -4,8 +4,9 @@ import (
|
||||
"image"
|
||||
"os"
|
||||
|
||||
"github.com/aditya-K2/gomp/client"
|
||||
"github.com/aditya-K2/gomp/notify"
|
||||
"github.com/aditya-K2/gomp/ui"
|
||||
"github.com/fhs/gompd/mpd"
|
||||
|
||||
"github.com/aditya-K2/gomp/cache"
|
||||
"github.com/aditya-K2/gomp/utils"
|
||||
@ -15,18 +16,9 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
CONN *mpd.Client
|
||||
Notify interface{ Send(string) }
|
||||
Rendr *Renderer
|
||||
)
|
||||
|
||||
func SetConnection(c *mpd.Client) {
|
||||
CONN = c
|
||||
}
|
||||
|
||||
func SetNotificationServer(n interface{ Send(string) }) {
|
||||
Notify = n
|
||||
}
|
||||
|
||||
// Renderer is just a channel on which we will send the Path to the song whose
|
||||
// Image is to be Rendered. This channel is passed to the OpenImage which in turn is called
|
||||
// by the Start() function as a go routine.
|
||||
@ -82,7 +74,7 @@ func (r *Renderer) Start(path string) {
|
||||
// rendered it checks first for the image in the cache
|
||||
// else it adds the image to the cache and then extracts it and renders it.
|
||||
func GetImagePath(path string) string {
|
||||
a, err := CONN.ListInfo(path)
|
||||
a, err := client.Conn.ListInfo(path)
|
||||
var extractedImage string
|
||||
if err == nil && len(a) != 0 {
|
||||
if cache.Exists(a[0]["artist"], a[0]["album"]) {
|
||||
@ -95,13 +87,13 @@ func GetImagePath(path string) string {
|
||||
viper.GetString("GET_COVER_ART_FROM_LAST_FM") == "TRUE" {
|
||||
downloadedImage, err := getImageFromLastFM(a[0]["artist"], a[0]["album"], imagePath)
|
||||
if err == nil {
|
||||
Notify.Send("Image From LastFM")
|
||||
notify.Notify.Send("Image From LastFM")
|
||||
extractedImage = downloadedImage
|
||||
} else {
|
||||
Notify.Send("Falling Back to Default Image.")
|
||||
notify.Notify.Send("Falling Back to Default Image.")
|
||||
}
|
||||
} else {
|
||||
Notify.Send("Extracted Image Successfully")
|
||||
notify.Notify.Send("Extracted Image Successfully")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ var (
|
||||
ImgW int
|
||||
ImgH int
|
||||
ImgX int
|
||||
Ui *Application
|
||||
)
|
||||
|
||||
type Application struct {
|
||||
|
@ -3,7 +3,9 @@ package views
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/aditya-K2/gomp/globals"
|
||||
"github.com/aditya-K2/gomp/client"
|
||||
"github.com/aditya-K2/gomp/notify"
|
||||
"github.com/aditya-K2/gomp/ui"
|
||||
"github.com/aditya-K2/gomp/utils"
|
||||
"github.com/aditya-K2/tview"
|
||||
"github.com/gdamore/tcell/v2"
|
||||
@ -17,57 +19,57 @@ func (s BuffSearchView) GetViewName() string {
|
||||
}
|
||||
|
||||
func (s BuffSearchView) ShowChildrenContent() {
|
||||
UI := globals.Ui
|
||||
CONN := globals.Conn
|
||||
UI := ui.Ui
|
||||
CONN := client.Conn
|
||||
r, _ := UI.ExpandedView.GetSelection()
|
||||
SetCurrentView(FView)
|
||||
if len(globals.DirTree.Children[r].Children) == 0 {
|
||||
if id, err := CONN.AddId(globals.DirTree.Children[globals.Matches[r].Index].AbsolutePath, -1); err != nil {
|
||||
globals.Notify.Send(fmt.Sprintf("Could Not add the Song %s to the Playlist",
|
||||
globals.DirTree.Children[globals.Matches[r].Index].AbsolutePath))
|
||||
if len(client.DirTree.Children[r].Children) == 0 {
|
||||
if id, err := CONN.AddId(client.DirTree.Children[client.Matches[r].Index].AbsolutePath, -1); err != nil {
|
||||
notify.Notify.Send(fmt.Sprintf("Could Not add the Song %s to the Playlist",
|
||||
client.DirTree.Children[client.Matches[r].Index].AbsolutePath))
|
||||
} else {
|
||||
if err := CONN.PlayId(id); err != nil {
|
||||
globals.Notify.Send("Could not Play the Song")
|
||||
notify.Notify.Send("Could not Play the Song")
|
||||
}
|
||||
}
|
||||
} else {
|
||||
globals.DirTree = &globals.DirTree.Children[globals.Matches[r].Index]
|
||||
client.DirTree = &client.DirTree.Children[client.Matches[r].Index]
|
||||
FView.Update(UI.ExpandedView)
|
||||
}
|
||||
UI.SearchBar.SetText("")
|
||||
// Resetting globals.Matches
|
||||
globals.Matches = nil
|
||||
// Resetting client.Matches
|
||||
client.Matches = nil
|
||||
}
|
||||
|
||||
func (s BuffSearchView) ShowParentContent() {
|
||||
globals.Notify.Send("Not Allowed in this View")
|
||||
notify.Notify.Send("Not Allowed in this View")
|
||||
return
|
||||
}
|
||||
|
||||
func (s BuffSearchView) AddToPlaylist() {
|
||||
UI := globals.Ui
|
||||
CONN := globals.Conn
|
||||
UI := ui.Ui
|
||||
CONN := client.Conn
|
||||
r, _ := UI.ExpandedView.GetSelection()
|
||||
if err := CONN.Add(globals.DirTree.Children[globals.Matches[r].Index].AbsolutePath); err != nil {
|
||||
globals.Notify.Send(fmt.Sprintf("Could Not Add URI %s to the Playlist",
|
||||
globals.DirTree.Children[globals.Matches[r].Index].Path))
|
||||
if err := CONN.Add(client.DirTree.Children[client.Matches[r].Index].AbsolutePath); err != nil {
|
||||
notify.Notify.Send(fmt.Sprintf("Could Not Add URI %s to the Playlist",
|
||||
client.DirTree.Children[client.Matches[r].Index].Path))
|
||||
} else {
|
||||
SetCurrentView(FView)
|
||||
globals.Notify.Send(fmt.Sprintf("URI Added %s to the Playlist",
|
||||
globals.DirTree.Children[globals.Matches[r].Index].Path))
|
||||
notify.Notify.Send(fmt.Sprintf("URI Added %s to the Playlist",
|
||||
client.DirTree.Children[client.Matches[r].Index].Path))
|
||||
SetCurrentView(BuffSView)
|
||||
}
|
||||
}
|
||||
|
||||
func (s BuffSearchView) Quit() {
|
||||
UI := globals.Ui
|
||||
UI := ui.Ui
|
||||
SetCurrentView(FView)
|
||||
UI.SearchBar.SetText("")
|
||||
globals.Matches = nil
|
||||
client.Matches = nil
|
||||
}
|
||||
|
||||
func (f BuffSearchView) FocusBuffSearchView() {
|
||||
UI := globals.Ui
|
||||
UI := ui.Ui
|
||||
SetCurrentView(BuffSView)
|
||||
UI.App.SetFocus(UI.SearchBar)
|
||||
}
|
||||
@ -75,8 +77,8 @@ func (f BuffSearchView) FocusBuffSearchView() {
|
||||
func (f BuffSearchView) DeleteSongFromPlaylist() {}
|
||||
|
||||
func (s BuffSearchView) Update(inputTable *tview.Table) {
|
||||
m := globals.Matches
|
||||
f := globals.DirTree.Children
|
||||
m := client.Matches
|
||||
f := client.DirTree.Children
|
||||
inputTable.Clear()
|
||||
if m == nil || len(m) == 0 {
|
||||
FView.Update(inputTable)
|
||||
|
@ -3,7 +3,9 @@ package views
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/aditya-K2/gomp/globals"
|
||||
"github.com/aditya-K2/gomp/client"
|
||||
"github.com/aditya-K2/gomp/notify"
|
||||
"github.com/aditya-K2/gomp/ui"
|
||||
"github.com/aditya-K2/gomp/utils"
|
||||
"github.com/aditya-K2/tview"
|
||||
"github.com/gdamore/tcell/v2"
|
||||
@ -17,51 +19,51 @@ func (f FileView) GetViewName() string {
|
||||
}
|
||||
|
||||
func (f FileView) ShowChildrenContent() {
|
||||
UI := globals.Ui
|
||||
CONN := globals.Conn
|
||||
UI := ui.Ui
|
||||
CONN := client.Conn
|
||||
r, _ := UI.ExpandedView.GetSelection()
|
||||
SetCurrentView(FView)
|
||||
if len(globals.DirTree.Children[r].Children) == 0 {
|
||||
if id, err := CONN.AddId(globals.DirTree.Children[r].AbsolutePath, -1); err != nil {
|
||||
globals.Notify.Send(fmt.Sprintf("Could not Add Song %s",
|
||||
globals.DirTree.Children[r].Path))
|
||||
if len(client.DirTree.Children[r].Children) == 0 {
|
||||
if id, err := CONN.AddId(client.DirTree.Children[r].AbsolutePath, -1); err != nil {
|
||||
notify.Notify.Send(fmt.Sprintf("Could not Add Song %s",
|
||||
client.DirTree.Children[r].Path))
|
||||
} else {
|
||||
if err := CONN.PlayId(id); err != nil {
|
||||
globals.Notify.Send(fmt.Sprintf("Could Not Play Song %s",
|
||||
globals.DirTree.Children[r].Path))
|
||||
notify.Notify.Send(fmt.Sprintf("Could Not Play Song %s",
|
||||
client.DirTree.Children[r].Path))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
globals.DirTree = &globals.DirTree.Children[r]
|
||||
client.DirTree = &client.DirTree.Children[r]
|
||||
FView.Update(UI.ExpandedView)
|
||||
UI.ExpandedView.Select(0, 0)
|
||||
}
|
||||
}
|
||||
|
||||
func (f FileView) ShowParentContent() {
|
||||
UI := globals.Ui
|
||||
if globals.DirTree.Parent != nil {
|
||||
globals.DirTree = globals.DirTree.Parent
|
||||
UI := ui.Ui
|
||||
if client.DirTree.Parent != nil {
|
||||
client.DirTree = client.DirTree.Parent
|
||||
FView.Update(UI.ExpandedView)
|
||||
}
|
||||
}
|
||||
|
||||
func (f FileView) AddToPlaylist() {
|
||||
UI := globals.Ui
|
||||
CONN := globals.Conn
|
||||
UI := ui.Ui
|
||||
CONN := client.Conn
|
||||
r, _ := UI.ExpandedView.GetSelection()
|
||||
if err := CONN.Add(globals.DirTree.Children[r].AbsolutePath); err != nil {
|
||||
globals.Notify.Send(fmt.Sprintf("Could not add %s to the Playlist",
|
||||
globals.DirTree.Children[r].Path))
|
||||
if err := CONN.Add(client.DirTree.Children[r].AbsolutePath); err != nil {
|
||||
notify.Notify.Send(fmt.Sprintf("Could not add %s to the Playlist",
|
||||
client.DirTree.Children[r].Path))
|
||||
}
|
||||
}
|
||||
|
||||
func (f FileView) Quit() {
|
||||
globals.Ui.App.Stop()
|
||||
ui.Ui.App.Stop()
|
||||
}
|
||||
|
||||
func (f FileView) FocusBuffSearchView() {
|
||||
UI := globals.Ui
|
||||
UI := ui.Ui
|
||||
SetCurrentView(BuffSView)
|
||||
UI.App.SetFocus(UI.SearchBar)
|
||||
}
|
||||
@ -70,9 +72,9 @@ func (f FileView) DeleteSongFromPlaylist() {}
|
||||
|
||||
func (f FileView) Update(inputTable *tview.Table) {
|
||||
inputTable.Clear()
|
||||
for i, j := range globals.DirTree.Children {
|
||||
for i, j := range client.DirTree.Children {
|
||||
if len(j.Children) == 0 {
|
||||
_songAttributes, err := globals.Conn.ListAllInfo(j.AbsolutePath)
|
||||
_songAttributes, err := client.Conn.ListAllInfo(j.AbsolutePath)
|
||||
if err == nil && _songAttributes[0]["Title"] != "" {
|
||||
_, _, w, _ := inputTable.GetInnerRect()
|
||||
inputTable.SetCell(i, 0,
|
||||
|
@ -1,7 +1,9 @@
|
||||
package views
|
||||
|
||||
import (
|
||||
"github.com/aditya-K2/gomp/globals"
|
||||
"github.com/aditya-K2/gomp/client"
|
||||
"github.com/aditya-K2/gomp/notify"
|
||||
"github.com/aditya-K2/gomp/ui"
|
||||
"github.com/aditya-K2/gomp/utils"
|
||||
"github.com/aditya-K2/tview"
|
||||
"github.com/gdamore/tcell/v2"
|
||||
@ -24,38 +26,38 @@ func GetCell(text string, foreground tcell.Color, bold bool) *tview.TableCell {
|
||||
}
|
||||
|
||||
func (p PlaylistView) ShowChildrenContent() {
|
||||
UI := globals.Ui
|
||||
CONN := globals.Conn
|
||||
UI := ui.Ui
|
||||
CONN := client.Conn
|
||||
r, _ := UI.ExpandedView.GetSelection()
|
||||
if err := CONN.Play(r); err != nil {
|
||||
globals.Notify.Send("Could Not Play the Song")
|
||||
notify.Notify.Send("Could Not Play the Song")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (s PlaylistView) ShowParentContent() {
|
||||
globals.Notify.Send("Not Allowed in this View")
|
||||
notify.Notify.Send("Not Allowed in this View")
|
||||
return
|
||||
}
|
||||
func (p PlaylistView) AddToPlaylist() {}
|
||||
|
||||
func (p PlaylistView) Quit() {
|
||||
globals.Ui.App.Stop()
|
||||
ui.Ui.App.Stop()
|
||||
}
|
||||
|
||||
func (p PlaylistView) FocusBuffSearchView() {}
|
||||
|
||||
func (p PlaylistView) DeleteSongFromPlaylist() {
|
||||
UI := globals.Ui
|
||||
CONN := globals.Conn
|
||||
UI := ui.Ui
|
||||
CONN := client.Conn
|
||||
r, _ := UI.ExpandedView.GetSelection()
|
||||
if err := CONN.Delete(r, -1); err != nil {
|
||||
globals.Notify.Send("Could not Remove the Song from Playlist")
|
||||
notify.Notify.Send("Could not Remove the Song from Playlist")
|
||||
}
|
||||
}
|
||||
|
||||
func (p PlaylistView) Update(inputTable *tview.Table) {
|
||||
CONN := globals.Conn
|
||||
CONN := client.Conn
|
||||
_playlistAttr, _ := CONN.PlaylistInfo(-1, -1)
|
||||
|
||||
inputTable.Clear()
|
||||
|
@ -4,7 +4,8 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/aditya-K2/gomp/client"
|
||||
"github.com/aditya-K2/gomp/globals"
|
||||
"github.com/aditya-K2/gomp/notify"
|
||||
"github.com/aditya-K2/gomp/ui"
|
||||
"github.com/aditya-K2/gomp/utils"
|
||||
"github.com/aditya-K2/tview"
|
||||
"github.com/gdamore/tcell/v2"
|
||||
@ -17,10 +18,10 @@ func (s SearchView) GetViewName() string {
|
||||
return "SearchView"
|
||||
}
|
||||
func (s SearchView) ShowChildrenContent() {
|
||||
UI := globals.Ui
|
||||
SearchContentSlice := globals.SearchContentSlice
|
||||
if len(globals.SearchContentSlice) <= 0 || globals.SearchContentSlice == nil {
|
||||
globals.Notify.Send("No Search Results")
|
||||
UI := ui.Ui
|
||||
SearchContentSlice := client.SearchContentSlice
|
||||
if len(client.SearchContentSlice) <= 0 || client.SearchContentSlice == nil {
|
||||
notify.Notify.Send("No Search Results")
|
||||
} else {
|
||||
r, _ := UI.ExpandedView.GetSelection()
|
||||
client.AddToPlaylist(SearchContentSlice[r], true)
|
||||
@ -28,15 +29,15 @@ func (s SearchView) ShowChildrenContent() {
|
||||
}
|
||||
|
||||
func (s SearchView) ShowParentContent() {
|
||||
globals.Notify.Send("Not Allowed in this View")
|
||||
notify.Notify.Send("Not Allowed in this View")
|
||||
return
|
||||
}
|
||||
|
||||
func (s SearchView) AddToPlaylist() {
|
||||
UI := globals.Ui
|
||||
SearchContentSlice := globals.SearchContentSlice
|
||||
if len(globals.SearchContentSlice) <= 0 || globals.SearchContentSlice == nil {
|
||||
globals.Notify.Send("No Search Results")
|
||||
UI := ui.Ui
|
||||
SearchContentSlice := client.SearchContentSlice
|
||||
if len(client.SearchContentSlice) <= 0 || client.SearchContentSlice == nil {
|
||||
notify.Notify.Send("No Search Results")
|
||||
} else {
|
||||
r, _ := UI.ExpandedView.GetSelection()
|
||||
client.AddToPlaylist(SearchContentSlice[r], false)
|
||||
@ -44,7 +45,7 @@ func (s SearchView) AddToPlaylist() {
|
||||
}
|
||||
|
||||
func (p SearchView) Quit() {
|
||||
globals.Ui.App.Stop()
|
||||
ui.Ui.App.Stop()
|
||||
}
|
||||
|
||||
func (s SearchView) FocusBuffSearchView() {}
|
||||
@ -52,7 +53,7 @@ func (s SearchView) DeleteSongFromPlaylist() {}
|
||||
|
||||
func (s SearchView) Update(inputTable *tview.Table) {
|
||||
inputTable.Clear()
|
||||
c := globals.SearchContentSlice
|
||||
c := client.SearchContentSlice
|
||||
_, _, width, _ := inputTable.GetInnerRect()
|
||||
for i, content := range c {
|
||||
switch content.(type) {
|
||||
|
Loading…
Reference in New Issue
Block a user