-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
ybenel
committed
Oct 2, 2023
1 parent
7429211
commit 087e989
Showing
16 changed files
with
1,547 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[Details] | ||
Icon = "icon.png" | ||
Name = "Neptune" | ||
ID = "cf.ybenel.Neptune" | ||
Version = "1.0.0" | ||
Build = 3 | ||
|
||
[Development] | ||
HelperText = "Neptune Keysounds Made Free" | ||
|
||
[Release] | ||
HelperText = "Neptune Keysounds Without Going Broke" | ||
|
||
[LinuxAndBSD] | ||
GenericName = "Neptune" | ||
Categories = ["Release"] | ||
Comment = "Enjoy free the free sounds without killing your cpu and ram" | ||
Keywords = ["keyboard", "sound"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
module github.com/m1ndo/Neptune | ||
|
||
go 1.21.1 | ||
|
||
require ( | ||
fyne.io/fyne/v2 v2.4.0 | ||
github.com/ebitengine/oto/v3 v3.1.0 | ||
github.com/hajimehoshi/ebiten/v2 v2.6.0 | ||
github.com/m1ndo/LogGdb v0.0.0-20230927203252-1bc32f78b34a | ||
github.com/robotn/gohook v0.41.0 | ||
) | ||
|
||
require ( | ||
fyne.io/systray v1.10.1-0.20230722100817-88df1e0ffa9a // indirect | ||
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect | ||
github.com/charmbracelet/lipgloss v0.8.0 // indirect | ||
github.com/charmbracelet/log v0.2.4 // indirect | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/ebitengine/purego v0.5.0 // indirect | ||
github.com/fredbi/uri v1.0.0 // indirect | ||
github.com/fsnotify/fsnotify v1.6.0 // indirect | ||
github.com/fyne-io/gl-js v0.0.0-20220119005834-d2da28d9ccfe // indirect | ||
github.com/fyne-io/glfw-js v0.0.0-20220120001248-ee7290d23504 // indirect | ||
github.com/fyne-io/image v0.0.0-20220602074514-4956b0afb3d2 // indirect | ||
github.com/go-gl/gl v0.0.0-20211210172815-726fda9656d6 // indirect | ||
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20221017161538-93cebf72946b // indirect | ||
github.com/go-logfmt/logfmt v0.6.0 // indirect | ||
github.com/go-text/render v0.0.0-20230619120952-35bccb6164b8 // indirect | ||
github.com/go-text/typesetting v0.0.0-20230905121921-abdbcca6e0eb // indirect | ||
github.com/godbus/dbus/v5 v5.1.0 // indirect | ||
github.com/gopherjs/gopherjs v1.17.2 // indirect | ||
github.com/jfreymuth/oggvorbis v1.0.5 // indirect | ||
github.com/jfreymuth/vorbis v1.0.2 // indirect | ||
github.com/jsummers/gobmp v0.0.0-20151104160322-e2ba15ffa76e // indirect | ||
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect | ||
github.com/mattn/go-isatty v0.0.18 // indirect | ||
github.com/mattn/go-runewidth v0.0.14 // indirect | ||
github.com/muesli/reflow v0.3.0 // indirect | ||
github.com/muesli/termenv v0.15.2 // indirect | ||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect | ||
github.com/pmezard/go-difflib v1.0.0 // indirect | ||
github.com/rivo/uniseg v0.2.0 // indirect | ||
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.4 // indirect | ||
github.com/tevino/abool v1.2.0 // indirect | ||
github.com/vcaesar/keycode v0.10.1 // indirect | ||
github.com/yuin/goldmark v1.5.5 // indirect | ||
golang.org/x/image v0.12.0 // indirect | ||
golang.org/x/mobile v0.0.0-20230922142353-e2f452493d57 // indirect | ||
golang.org/x/net v0.14.0 // indirect | ||
golang.org/x/sys v0.12.0 // indirect | ||
golang.org/x/text v0.13.0 // indirect | ||
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
honnef.co/go/js/dom v0.0.0-20210725211120-f030747120f2 // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/m1ndo/Neptune/pkg/neptune" | ||
"github.com/m1ndo/Neptune/pkg/ui" | ||
) | ||
|
||
func main() { | ||
App := neptune.NewApp() | ||
if !App.CfgVars.Cli { | ||
uiApp := &ui.UiApp{} | ||
SoundWid := uiApp.SoundsList(App.FoundSounds(), App.SetSounds) | ||
err := uiApp.NewApp(SoundWid, App.AppRun, App.AppStop) | ||
if err != nil { | ||
App.Logger.Log.Fatal(err) | ||
} | ||
uiApp.MainWindow.ShowAndRun() | ||
} else { | ||
App.AppRun() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package neptune | ||
|
||
import ( | ||
"flag" | ||
) | ||
|
||
type SelectVars struct { | ||
Cli bool | ||
Soundkey string | ||
} | ||
|
||
func ParseFlags() *SelectVars { | ||
cfgVars := &SelectVars{} | ||
flag.BoolVar(&cfgVars.Cli, "cli", false, "Run in CLI instead of GUI") | ||
soundKey := flag.String("soundkey", "", "Soundkey to use default (nk-cream)") | ||
flag.Parse() | ||
if *soundKey != "" { | ||
cfgVars.Soundkey = *soundKey | ||
} | ||
return cfgVars | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package neptune | ||
|
||
import ( | ||
hook "github.com/robotn/gohook" | ||
) | ||
|
||
type KeyEvent struct { | ||
Enabled bool | ||
EvChan chan hook.Event | ||
} | ||
|
||
type Event interface { | ||
KindCode() uint8 | ||
Keycode() uint16 | ||
} | ||
|
||
type CustomEvent struct { | ||
Kind uint8 | ||
Keycodes uint16 | ||
} | ||
|
||
|
||
func NewKeyEvent() *KeyEvent { | ||
return &KeyEvent{} | ||
} | ||
|
||
func (Kv *KeyEvent) StartEven() chan hook.Event { | ||
Kv.Enabled = true | ||
Kv.EvChan = hook.Start() | ||
return Kv.EvChan | ||
} | ||
|
||
func (Kv *KeyEvent) StopEvent() { | ||
if Kv.Enabled { | ||
hook.End() | ||
Kv.Enabled = false | ||
} | ||
} | ||
|
||
func (k *KeyEvent) EventChannel() chan hook.Event { | ||
return k.EvChan | ||
} | ||
|
||
func (ce CustomEvent) KindCode() uint8 { | ||
return ce.Kind | ||
} | ||
|
||
func (ce CustomEvent) Keycode() uint16 { | ||
return ce.Keycodes | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package neptune | ||
|
||
import ( | ||
"bytes" | ||
"io" | ||
"os" | ||
"path" | ||
"time" | ||
|
||
"fyne.io/fyne/v2" | ||
"github.com/ebitengine/oto/v3" | ||
"github.com/hajimehoshi/ebiten/v2/audio/vorbis" | ||
"github.com/hajimehoshi/ebiten/v2/audio/wav" | ||
"github.com/m1ndo/Neptune/pkg/sdata" | ||
) | ||
|
||
type NewContextPlayer struct { | ||
Options *oto.NewContextOptions | ||
Player *oto.Player | ||
Context *oto.Context | ||
readyChan chan struct{} | ||
AppIn *App | ||
} | ||
|
||
func decoder(fBytes *bytes.Reader, ext string) (io.Reader, error) { | ||
switch { | ||
case ext == ".wav": | ||
decoder, err := wav.DecodeWithoutResampling(fBytes) | ||
return decoder, err | ||
case ext == ".ogg": | ||
decoder, err := vorbis.DecodeWithoutResampling(fBytes) | ||
return decoder, err | ||
} | ||
return nil, nil | ||
} | ||
|
||
func (Ctx *NewContextPlayer) NewContext() error { | ||
Ctx.Options = &oto.NewContextOptions{ | ||
SampleRate: 48000, | ||
ChannelCount: 2, | ||
Format: oto.FormatSignedInt16LE, | ||
} | ||
var err error | ||
Ctx.Context, Ctx.readyChan, err = oto.NewContext(Ctx.Options) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func GetKeys(key string) *fyne.StaticResource { | ||
data := sdata.KeyList[key] | ||
return data | ||
} | ||
|
||
func (Ctx *NewContextPlayer) PlaySound(file string) error { | ||
var f []byte | ||
var err error | ||
if Ctx.AppIn.Config.DefaultSound != "nk-cream" { | ||
file := Ctx.AppIn.Config.FSounds[Ctx.AppIn.Config.DefaultSound] + "/" + Ctx.AppIn.Config.Config.KSound[file] | ||
f, err = os.ReadFile(file) | ||
if err != nil { | ||
return err | ||
} | ||
} else { | ||
f = GetKeys(file).StaticContent | ||
} | ||
fBytes := bytes.NewReader(f) | ||
decoded, err := decoder(fBytes, path.Ext(file)) | ||
if err != nil { | ||
return err | ||
} | ||
<-Ctx.readyChan | ||
Ctx.Player = Ctx.Context.NewPlayer(decoded) | ||
go func() { | ||
Ctx.Player.Play() | ||
for Ctx.Player.IsPlaying() { | ||
time.Sleep(time.Millisecond) | ||
} | ||
err := Ctx.Player.Close() | ||
if err != nil { | ||
panic("Player.Close failed: " + err.Error()) | ||
} | ||
}() | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package neptune | ||
|
||
import ( | ||
"strconv" | ||
|
||
loggdb "github.com/m1ndo/LogGdb" | ||
) | ||
|
||
type App struct { | ||
Config *SConfig | ||
ContextPlayer *NewContextPlayer | ||
KeyEvent *KeyEvent | ||
Logger *loggdb.Logger | ||
Running bool | ||
CfgVars *SelectVars | ||
} | ||
|
||
func NewApp() *App { | ||
a := &App{ | ||
Config: &SConfig{SoundDir: "sounds/", DefaultSound: "nk-cream"}, | ||
KeyEvent: &KeyEvent{}, | ||
ContextPlayer: &NewContextPlayer{}, | ||
Logger: &loggdb.Logger{}, | ||
CfgVars: &SelectVars{}, | ||
Running: false, | ||
} | ||
// Set Logger | ||
a.Logger.NewLogger() | ||
// Cli args | ||
a.CfgVars = ParseFlags() | ||
if a.CfgVars.Soundkey != "" { | ||
a.Config.DefaultSound = a.CfgVars.Soundkey | ||
} | ||
// Find Sounds | ||
a.Config.AppIn = a | ||
a.Config.FindSounds() | ||
if err := a.Config.ReadConfig(); err != nil { | ||
a.Logger.Log.Fatal(err) | ||
} | ||
// New Context Player | ||
a.ContextPlayer.AppIn = a | ||
if err := a.ContextPlayer.NewContext(); err != nil { | ||
a.Logger.Log.Fatal(err) | ||
} | ||
return a | ||
} | ||
|
||
func (a *App) AppRun() { | ||
if a.Running { | ||
a.Logger.Log.Warn("App is already running") | ||
return | ||
} | ||
a.Running = true | ||
evChan := a.KeyEvent.StartEven() | ||
a.Logger.Log.Infof("Using Selected Sound %s, ", a.Config.DefaultSound) | ||
for ev := range evChan { | ||
go func(event Event) { | ||
if event.KindCode() == 5 { | ||
code := strconv.Itoa(int(event.Keycode())) | ||
if a.Config.Config.KSound[code] != "" { | ||
// sfile := a.Config.FSounds[a.Config.DefaultSound] + "/" + a.Config.Config.KSound[code] | ||
if err := a.ContextPlayer.PlaySound(a.Config.Config.KSound[code]); err != nil { | ||
a.Logger.Log.Error(err) | ||
} | ||
} | ||
} | ||
}(&CustomEvent{ | ||
Kind: ev.Kind, | ||
Keycodes: ev.Keycode, | ||
}) | ||
} | ||
} | ||
|
||
func (a *App) AppStop() { | ||
if !a.Running { | ||
a.Logger.Log.Warn("Can't stop and app that is not running") | ||
return | ||
} | ||
a.KeyEvent.StopEvent() | ||
a.Running = false | ||
} | ||
|
||
// List Found Sounds. | ||
func (a *App) FoundSounds() []string { | ||
var Fsounds []string | ||
for Found := range a.Config.FSounds { | ||
Fsounds = append(Fsounds, Found) | ||
} | ||
return Fsounds | ||
} | ||
|
||
// Set Soundkeys | ||
func (a *App) SetSounds(sound string) { | ||
a.Logger.Log.Infof("Executed and sat %s", sound) | ||
a.Config.DefaultSound = sound | ||
} |
Oops, something went wrong.