Skip to content

Commit

Permalink
Update neco arc player and removed possible memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
zSnails committed Nov 5, 2022
1 parent 5500866 commit 98f2e76
Show file tree
Hide file tree
Showing 63 changed files with 781 additions and 73 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
assets
*.exe
*.syso
*.log
*.log
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
all:
go build -ldflag="-s -w -H=windowsgui"
Binary file added assets/audio/Neco Ataranai a.mp3
Binary file not shown.
Binary file added assets/audio/Neco Bacagare!.mp3
Binary file not shown.
Binary file added assets/audio/Neco Braca sobe sibu.mp3
Binary file not shown.
Binary file added assets/audio/Neco Bucoros!!!.mp3
Binary file not shown.
Binary file added assets/audio/Neco Carano neco caeiru.mp3
Binary file not shown.
Binary file added assets/audio/Neco Chaina Chainese.mp3
Binary file not shown.
Binary file added assets/audio/Neco Juf.mp3
Binary file not shown.
Binary file added assets/audio/Neco Muda muDa.mp3
Binary file not shown.
Binary file added assets/audio/Neco NINIÑA.mp3
Binary file not shown.
Binary file added assets/audio/Neco On.mp3
Binary file not shown.
Binary file added assets/audio/Neco SAyayya!.mp3
Binary file not shown.
Binary file added assets/audio/Neco Sa Yesa 1.mp3
Binary file not shown.
Binary file added assets/audio/Neco Sa Yesa 2.mp3
Binary file not shown.
Binary file added assets/audio/Neco Senpocu.mp3
Binary file not shown.
Binary file added assets/audio/Neco Simpera tentera.mp3
Binary file not shown.
Binary file added assets/audio/Neco Sinuca.mp3
Binary file not shown.
Binary file added assets/audio/Neco Suriu.mp3
Binary file not shown.
Binary file added assets/audio/Neco UUUUUUUHHHHNIIIAAAAA!!!!.mp3
Binary file not shown.
Binary file added assets/audio/Neco VI BI VII!!.mp3
Binary file not shown.
Binary file added assets/audio/Neco aahiii No.mp3
Binary file not shown.
Binary file added assets/audio/Neco agua zero damesca.mp3
Binary file not shown.
Binary file added assets/audio/Neco banyi quico faito.mp3
Binary file not shown.
Binary file added assets/audio/Neco booooocooooooon.mp3
Binary file not shown.
Binary file added assets/audio/Neco bu buuu.mp3
Binary file not shown.
Binary file added assets/audio/Neco cho atas callo.mp3
Binary file not shown.
Binary file added assets/audio/Neco come sasis.mp3
Binary file not shown.
Binary file added assets/audio/Neco dori dori dori.mp3
Binary file not shown.
Binary file added assets/audio/Neco fuero fueru.mp3
Binary file not shown.
Binary file added assets/audio/Neco guiningun.mp3
Binary file not shown.
Binary file added assets/audio/Neco haiyai na.mp3
Binary file not shown.
Binary file added assets/audio/Neco iiiiisAAAAA.mp3
Binary file not shown.
Binary file added assets/audio/Neco jooooonoooo oooo.mp3
Binary file not shown.
Binary file added assets/audio/Neco la Boando des.mp3
Binary file not shown.
Binary file added assets/audio/Neco mhmhmh baca bacai.mp3
Binary file not shown.
Binary file added assets/audio/Neco miico nieco neo nundaaa.mp3
Binary file not shown.
Binary file added assets/audio/Neco mosimosi doco.mp3
Binary file not shown.
Binary file added assets/audio/Neco mosimosi.mp3
Binary file not shown.
Binary file added assets/audio/Neco niiiaaa.mp3
Binary file not shown.
Binary file added assets/audio/Neco nnonoooiinnnn ahahh.mp3
Binary file not shown.
Binary file added assets/audio/Neco quiajuuubn.mp3
Binary file not shown.
Binary file added assets/audio/Neco ttaaaiiimoooo.mp3
Binary file not shown.
Binary file added assets/audio/Neco uhh.mp3
Binary file not shown.
Binary file added assets/audio/Neco uhh2.mp3
Binary file not shown.
Binary file added assets/audio/Neco ungia!.mp3
Binary file not shown.
Binary file added assets/audio/Neco usuero cachi cum.mp3
Binary file not shown.
Binary file added assets/audio/Neco uuniiu.mp3
Binary file not shown.
Binary file added assets/audio/Neco uuuuhh.mp3
Binary file not shown.
Binary file added assets/audio/Neco yanyan yaan.mp3
Binary file not shown.
Binary file added assets/audio/Neco yuiyuruu.mp3
Binary file not shown.
Binary file added assets/audio/Neco ÑA ÑA ÑA.mp3
Binary file not shown.
Binary file added assets/audio/Neco ÑA ÑA ÑA2.mp3
Binary file not shown.
Binary file added assets/audio/Neco ÑA ÑA.mp3
Binary file not shown.
Binary file added assets/audio/Neco ÑA.mp3
Binary file not shown.
Binary file added assets/audio/Neco ÑAÑAA AÑA Ña.mp3
Binary file not shown.
Binary file added assets/audio/Neco-Arc sound effect.mp3
Binary file not shown.
Binary file added assets/audio/neco Sinbu bocoari.mp3
Binary file not shown.
Binary file added assets/favicon.ico
Binary file not shown.
Binary file added assets/neco.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 30 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,35 @@ module neko-arc-player
go 1.16

require (
fyne.io/fyne/v2 v2.1.1
fyne.io/fyne/v2 v2.2.3
github.com/Kodeworks/golang-image-ico v0.0.0-20141118225523-73f0f4cfade9 // indirect
github.com/faiface/beep v1.1.0
github.com/getlantern/systray v1.1.0
github.com/sirupsen/logrus v1.8.1
github.com/fredbi/uri v0.0.0-20221012073901-fb871453c6d3 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/fyne-io/gl-js v0.0.0-20220802150000-8e339395f381 // indirect
github.com/fyne-io/glfw-js v0.0.0-20220517201726-bebc2019cd33 // indirect
github.com/fyne-io/image v0.0.0-20221020213044-f609c6a24345 // indirect
github.com/getlantern/errors v1.0.3 // indirect
github.com/getlantern/golog v0.0.0-20221014032422-49749a7176cf // indirect
github.com/getlantern/hidden v0.0.0-20220104173330-f221c5a24770 // indirect
github.com/getlantern/systray v1.2.1
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20221017161538-93cebf72946b // indirect
github.com/goki/freetype v0.0.0-20220119013949-7a161fd3728c // indirect
github.com/hajimehoshi/go-mp3 v0.3.3 // indirect
github.com/hajimehoshi/oto v1.0.1 // indirect
github.com/jackmordaunt/icns v0.0.0-20181231085925-4f16af745526 // indirect
github.com/sirupsen/logrus v1.9.0
github.com/srwiley/oksvg v0.0.0-20221011165216-be6e8873101c // indirect
github.com/srwiley/rasterx v0.0.0-20220730225603-2ab79fcdd4ef // indirect
github.com/stretchr/testify v1.8.1 // indirect
github.com/yuin/goldmark v1.5.2 // indirect
go.opentelemetry.io/otel v1.11.1 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
go.uber.org/zap v1.23.0 // indirect
golang.org/x/exp/shiny v0.0.0-20221031165847-c99f073a8326 // indirect
golang.org/x/image v0.1.0 // indirect
golang.org/x/mobile v0.0.0-20221020085226-b36e6246172e // indirect
golang.org/x/net v0.1.0 // indirect
honnef.co/go/js/dom v0.0.0-20221001195520-26252dedbe70 // indirect
)
681 changes: 681 additions & 0 deletions go.sum

Large diffs are not rendered by default.

135 changes: 67 additions & 68 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import (
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/data/binding"
"fyne.io/fyne/v2/driver/desktop"
"fyne.io/fyne/v2/layout"
"fyne.io/fyne/v2/widget"
"github.com/faiface/beep"
"github.com/faiface/beep/effects"
"github.com/faiface/beep/mp3"
"github.com/faiface/beep/speaker"
"github.com/getlantern/systray"
"github.com/sirupsen/logrus"
)

Expand All @@ -36,9 +36,10 @@ var (

outputFile string
maxTime int
mainApp = app.NewWithID("neco-annoying")
w = mainApp.NewWindow("Neco Annoying")
mApp = app.NewWithID("Neco-Annoying")
mWindow = mApp.NewWindow("Neco Arc Player")
volume = binding.NewFloat()
iconRes = fyne.NewStaticResource("icon", iconPng)
)

func init() {
Expand All @@ -55,24 +56,69 @@ func main() {
}
logrus.SetOutput(logOut)

volPref := mainApp.Preferences().FloatWithFallback("app-volume", 0)
volPref := mApp.Preferences().FloatWithFallback("app-volume", 0)

volume.Set(volPref)
w.SetIcon(fyne.NewStaticResource("icon", iconPng))

volumeSlider := widget.NewSliderWithData(-10, 0, volume)
volumeSlider.Step = 0.01
volumeSlider.SetValue(0)
w.SetContent(container.New(layout.NewMaxLayout(), widget.NewLabelWithData(binding.FloatToString(volume)), volumeSlider))
w.SetCloseIntercept(func() {
w.Hide()

mWindow.SetIcon(iconRes)

mWindow.Resize(fyne.NewSize(300, 150))
mWindow.SetFixedSize(true)
mWindow.SetContent(container.New(layout.NewMaxLayout(), widget.NewLabelWithData(binding.FloatToString(volume)), volumeSlider))
mWindow.SetCloseIntercept(func() {
mWindow.Hide()
})
w.Resize(fyne.NewSize(300, 150))
w.SetFixedSize(true)

if desk, ok := mApp.(desktop.App); ok {
menu := fyne.NewMenu("Neco Arc Random Sounds", fyne.NewMenuItem("Manage volume", func() {
mWindow.Show()
mWindow.RequestFocus()
}), fyne.NewMenuItem("Donate", func() {
u, err := url.Parse("https://paypal.me/elesneils")
if err != nil {
logrus.Error(err)
}
err = mApp.OpenURL(u)
if err != nil {
logrus.Error(err)
}
}))
desk.SetSystemTrayMenu(menu)
desk.SetSystemTrayIcon(iconRes)
}

go playAudio()
systray.Register(onReady, nil)
mainApp.Run()

mApp.Run()
}

func playAudio() {
vol, err := volume.Get()
if err != nil {
logrus.Fatal(err)
}

volumeManager := effects.Volume{
Base: 2,
Volume: vol,
Silent: false,
}

volume.AddListener(binding.NewDataListener(func() {
vol, err := volume.Get()
if err != nil {
logrus.Fatal(err)
}
speaker.Lock()
volumeManager.Volume = vol
speaker.Unlock()
mApp.Preferences().SetFloat("app-volume", vol)
}))

audioFolder, _ := soundsFs.ReadDir("assets/audio")
for {
file := audioFolder[r.Intn(len(audioFolder))].Name()
Expand All @@ -87,75 +133,28 @@ func playAudio() {
continue
}
logrus.Infof("Playing audio %v", file)
if err != nil {

if err := streamer.Err(); err != nil {
logrus.Error(err)
continue
}
play(streamer, format)

volumeManager.Streamer = streamer
play(volumeManager, streamer, format)
time.Sleep(time.Duration(r.Intn(maxTime) * int(time.Minute)))
}

}

func play(streamer beep.StreamSeekCloser, format beep.Format) {
vol, err := volume.Get()
volumeManager := effects.Volume{
Streamer: streamer,
Base: 2,
Volume: vol,
Silent: false,
}
volume.AddListener(binding.NewDataListener(func() {
if err != nil {
logrus.Error(err)
}
speaker.Lock()
volumeManager.Volume = vol
speaker.Unlock()
mainApp.Preferences().SetFloat("app-volume", vol)
}))
func play(manager effects.Volume, streamer beep.StreamSeekCloser, format beep.Format) {

if err := speaker.Init(format.SampleRate, format.SampleRate.N(time.Second/10)); err != nil {
logrus.Error(err)
return
}
done := make(chan bool)
speaker.Play(beep.Seq(&volumeManager, beep.Callback(func() {
speaker.Play(beep.Seq(&manager, beep.Callback(func() {
done <- true
})))
<-done
if err := streamer.Err(); err != nil {
logrus.Error(err)
return
}
}

func onReady() {
systray.SetIcon(icon)
systray.SetTitle("Neco arc sound player")
systray.SetTooltip("Randomly plays neco-arc's sounds over time")
manageButton := systray.AddMenuItem("Show Window", "Opens the audio management window")
donateBtn := systray.AddMenuItem("Donate", "I appreciate your support")
systray.AddSeparator()
quitBtn := systray.AddMenuItem("Stop", "Stops the whole app")
go func() {
for {
select {
case <-quitBtn.ClickedCh:
systray.Quit()
mainApp.Quit()
case <-donateBtn.ClickedCh:
// openbrowser()
u, err := url.Parse("https://paypal.me/elesneils")
if err != nil {
logrus.Error(err)
}
err = mainApp.OpenURL(u)
if err != nil {
logrus.Error(err)
}
case <-manageButton.ClickedCh:
w.Show()
// w.RequestFocus()
}
}
}()
}

0 comments on commit 98f2e76

Please sign in to comment.