rich presence and stuffs

This commit is contained in:
Bucket Of Chicken
2025-09-07 10:11:35 +02:00
parent 6c2382a2ce
commit 1be235df0a
20 changed files with 417 additions and 215 deletions
+1 -1
View File
@@ -24,7 +24,7 @@ bus/1/name = &"Music"
bus/1/solo = false
bus/1/mute = false
bus/1/bypass_fx = false
bus/1/volume_db = -10.986328
bus/1/volume_db = -10.9863
bus/1/send = &"Master"
bus/1/effect/0/effect = SubResource("AudioEffectReverb_tqf74")
bus/1/effect/0/enabled = false
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

+34
View File
@@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://dumymuj4w4si0"
path="res://.godot/imported/shuffle.png-21f68d69d5bd71fb81079750a3d07cc4.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://Icons/shuffle.png"
dest_files=["res://.godot/imported/shuffle.png-21f68d69d5bd71fb81079750a3d07cc4.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

+34
View File
@@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://bqqbb8m2o8j45"
path="res://.godot/imported/shufflepressed.png-525d2e3fe7b3a5854b3aa7cd44a38683.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://Icons/shufflepressed.png"
dest_files=["res://.godot/imported/shufflepressed.png-525d2e3fe7b3a5854b3aa7cd44a38683.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
+47
View File
@@ -0,0 +1,47 @@
[gd_scene load_steps=3 format=3 uid="uid://dds3tnltcg0sg"]
[ext_resource type="Script" uid="uid://23jo0gxt4s8r" path="res://Scripts/PerformanceDisplay.cs" id="1_ytklf"]
[ext_resource type="PackedScene" uid="uid://c21wc1bq2pnm" path="res://Scenes/song_display.tscn" id="2_5dy3w"]
[node name="SearchResults" type="Panel" node_paths=PackedStringArray("UpperMargin", "SongContainer", "LowerMargin", "Scroll")]
custom_minimum_size = Vector2(200, 0)
anchors_preset = -1
anchor_left = 0.285
anchor_right = 0.715
anchor_bottom = 0.937
offset_left = 0.209961
offset_right = -0.210022
offset_bottom = 0.121979
grow_horizontal = 2
script = ExtResource("1_ytklf")
display = ExtResource("2_5dy3w")
UpperMargin = NodePath("ScrollContainer/VBoxContainer/UpperMargin")
SongContainer = NodePath("ScrollContainer/VBoxContainer/SongContainer")
LowerMargin = NodePath("ScrollContainer/VBoxContainer/LowerMargin")
Scroll = NodePath("ScrollContainer")
[node name="ScrollContainer" type="ScrollContainer" parent="."]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
follow_focus = true
horizontal_scroll_mode = 0
[node name="VBoxContainer" type="VBoxContainer" parent="ScrollContainer"]
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 3
theme_override_constants/separation = 0
[node name="UpperMargin" type="Control" parent="ScrollContainer/VBoxContainer"]
layout_mode = 2
[node name="SongContainer" type="VBoxContainer" parent="ScrollContainer/VBoxContainer"]
layout_mode = 2
theme_override_constants/separation = 0
[node name="LowerMargin" type="Control" parent="ScrollContainer/VBoxContainer"]
layout_mode = 2
+30 -67
View File
@@ -1,4 +1,4 @@
[gd_scene load_steps=18 format=3 uid="uid://mfcbf2sfino6"]
[gd_scene load_steps=17 format=3 uid="uid://mfcbf2sfino6"]
[ext_resource type="Texture2D" uid="uid://0jo87vtoeheu" path="res://Images/pole2.jpg" id="1_6bp64"]
[ext_resource type="Texture2D" uid="uid://df2e70jxwrmjs" path="res://Icons/BackOne.png" id="1_8gbba"]
@@ -9,9 +9,8 @@
[ext_resource type="Texture2D" uid="uid://myq6n4bshduj" path="res://Icons/search.png" id="2_ynf5e"]
[ext_resource type="Script" uid="uid://bq55jftgugexl" path="res://Scripts/Context.cs" id="3_8gbba"]
[ext_resource type="Texture2D" uid="uid://38c8dfym0svn" path="res://Icons/Loop.png" id="4_21xkr"]
[ext_resource type="Script" uid="uid://dq3yj21reqk80" path="res://Scripts/SearchDisplay.cs" id="4_hptm8"]
[ext_resource type="Texture2D" uid="uid://cekkhyppj88xi" path="res://Icons/Headphones.png" id="4_kry3j"]
[ext_resource type="PackedScene" uid="uid://c21wc1bq2pnm" path="res://Scenes/song_display.tscn" id="5_d1ilt"]
[ext_resource type="PackedScene" uid="uid://dds3tnltcg0sg" path="res://Scenes/PerformanceDisplay.tscn" id="5_fdnlq"]
[ext_resource type="Script" uid="uid://ci5h1wwbedkbt" path="res://Scripts/UIManager.cs" id="12_6iyac"]
[ext_resource type="Texture2D" uid="uid://ch8wymyxftkb3" path="res://Icons/Pause.png" id="14_jkdf5"]
@@ -62,6 +61,20 @@ anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
[node name="Context" type="Node" parent="."]
script = ExtResource("3_8gbba")
[node name="UiManager" type="Node" parent="." node_paths=PackedStringArray("PlayPauseButton", "ProgressIndicator", "SkipButton", "GoBackButton", "LoopButton", "RandomizeButton")]
script = ExtResource("12_6iyac")
PlayPauseButton = NodePath("../Padding/VBoxContainer/Bottom/HBoxContainer/PlayButton")
PauseImage = ExtResource("14_jkdf5")
PlayImage = ExtResource("2_jjvhh")
ProgressIndicator = NodePath("../Padding/VBoxContainer/Bottom/HBoxContainer/Progress")
SkipButton = NodePath("../Padding/VBoxContainer/Bottom/HBoxContainer/SkipButton")
GoBackButton = NodePath("../Padding/VBoxContainer/Bottom/HBoxContainer/BackButton")
LoopButton = NodePath("../Padding/VBoxContainer/Bottom/HBoxContainer/Loop")
RandomizeButton = NodePath("../Padding/VBoxContainer/Bottom/HBoxContainer/Shuffle")
[node name="Background" type="TextureRect" parent="."]
z_index = -2
layout_mode = 1
@@ -76,6 +89,7 @@ stretch_mode = 6
[node name="Padding" type="Control" parent="."]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = 29.0
@@ -153,43 +167,16 @@ expand_icon = true
layout_mode = 2
size_flags_vertical = 3
[node name="SearchResults" type="Panel" parent="Padding/VBoxContainer/Center"]
custom_minimum_size = Vector2(200, 0)
layout_mode = 1
anchors_preset = -1
anchor_left = 0.28500003
anchor_right = 0.71500003
anchor_bottom = 0.93700004
offset_left = 0.20996094
offset_right = -0.21002197
offset_bottom = 0.12197876
grow_horizontal = 2
[node name="ScrollContainer" type="ScrollContainer" parent="Padding/VBoxContainer/Center/SearchResults"]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
[node name="SearchResults" parent="Padding/VBoxContainer/Center" instance=ExtResource("5_fdnlq")]
custom_minimum_size = Vector2(500, 0)
layout_mode = 2
anchors_preset = 0
anchor_left = 0.339
anchor_right = 0.661
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
follow_focus = true
horizontal_scroll_mode = 0
[node name="VBoxContainer" type="VBoxContainer" parent="Padding/VBoxContainer/Center/SearchResults/ScrollContainer"]
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 3
theme_override_constants/separation = 0
[node name="UpperMargin" type="Control" parent="Padding/VBoxContainer/Center/SearchResults/ScrollContainer/VBoxContainer"]
layout_mode = 2
[node name="SongContainer" type="VBoxContainer" parent="Padding/VBoxContainer/Center/SearchResults/ScrollContainer/VBoxContainer"]
layout_mode = 2
theme_override_constants/separation = 0
[node name="LowerMargin" type="Control" parent="Padding/VBoxContainer/Center/SearchResults/ScrollContainer/VBoxContainer"]
layout_mode = 2
offset_left = 0.133972
offset_right = -0.134033
offset_bottom = 0.0
[node name="Bottom" type="Control" parent="Padding/VBoxContainer"]
custom_minimum_size = Vector2(0, 42)
@@ -222,14 +209,12 @@ layout_mode = 2
icon = ExtResource("2_bo1nx")
expand_icon = true
[node name="HSlider" type="HSlider" parent="Padding/VBoxContainer/Bottom/HBoxContainer"]
[node name="Progress" type="HSlider" parent="Padding/VBoxContainer/Bottom/HBoxContainer"]
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 4
max_value = 1.0
step = 0.0010000000038417
tick_count = 5
ticks_position = 3
step = 0.001
[node name="Loop" type="Button" parent="Padding/VBoxContainer/Bottom/HBoxContainer"]
custom_minimum_size = Vector2(42, 0)
@@ -263,21 +248,18 @@ offset_bottom = -42.0
grow_horizontal = 2
grow_vertical = 0
max_value = 1.0
step = 0.01000000000931322
step = 0.01
value = 1.0
script = SubResource("GDScript_d1ilt")
[node name="FileDialog" type="FileDialog" parent="."]
oversampling_override = 1.0
title = "Open a Directory"
size = Vector2i(807, 360)
ok_button_text = "Select Current Folder"
file_mode = 2
access = 2
use_native_dialog = true
[node name="Context" type="Node" parent="."]
script = ExtResource("3_8gbba")
[node name="Label" type="Label" parent="."]
layout_mode = 1
anchors_preset = -1
@@ -290,22 +272,3 @@ offset_top = -23.0
grow_horizontal = 0
grow_vertical = 0
text = "v2.0"
[node name="SearchDisplay" type="Node" parent="." node_paths=PackedStringArray("UpperMargin", "SongContainer", "LowerMargin", "Scroll")]
script = ExtResource("4_hptm8")
display = ExtResource("5_d1ilt")
UpperMargin = NodePath("../Padding/VBoxContainer/Center/SearchResults/ScrollContainer/VBoxContainer/UpperMargin")
SongContainer = NodePath("../Padding/VBoxContainer/Center/SearchResults/ScrollContainer/VBoxContainer/SongContainer")
LowerMargin = NodePath("../Padding/VBoxContainer/Center/SearchResults/ScrollContainer/VBoxContainer/LowerMargin")
Scroll = NodePath("../Padding/VBoxContainer/Center/SearchResults/ScrollContainer")
[node name="UiManager" type="Node" parent="." node_paths=PackedStringArray("PlayPauseButton", "ProgressIndicator", "SkipButton", "GoBackButton", "LoopButton", "RandomizeButton")]
script = ExtResource("12_6iyac")
PlayPauseButton = NodePath("../Padding/VBoxContainer/Bottom/HBoxContainer/PlayButton")
PauseImage = ExtResource("14_jkdf5")
PlayImage = ExtResource("2_jjvhh")
ProgressIndicator = NodePath("../Padding/VBoxContainer/Bottom/HBoxContainer/HSlider")
SkipButton = NodePath("../Padding/VBoxContainer/Bottom/HBoxContainer/SkipButton")
GoBackButton = NodePath("../Padding/VBoxContainer/Bottom/HBoxContainer/BackButton")
LoopButton = NodePath("../Padding/VBoxContainer/Bottom/HBoxContainer/Loop")
RandomizeButton = NodePath("../Padding/VBoxContainer/Bottom/HBoxContainer/Shuffle")
+20 -11
View File
@@ -1,18 +1,19 @@
[gd_scene load_steps=4 format=3 uid="uid://c21wc1bq2pnm"]
[gd_scene load_steps=5 format=3 uid="uid://c21wc1bq2pnm"]
[ext_resource type="Script" uid="uid://bs55rsv7eh4l5" path="res://Scripts/SongDisplay.cs" id="1_76jf4"]
[ext_resource type="Texture2D" uid="uid://dwvy6crqhardn" path="res://Icons/Dropdown.png" id="2_x33bo"]
[sub_resource type="LabelSettings" id="LabelSettings_swnt4"]
font_size = 20
shadow_size = 2
shadow_color = Color(0, 0, 0, 0.5647059)
shadow_color = Color(0, 0, 0, 0.564706)
[sub_resource type="LabelSettings" id="LabelSettings_8tgr4"]
font_color = Color(0.7919991, 0.79199916, 0.7919991, 1)
font_color = Color(0.791999, 0.791999, 0.791999, 1)
shadow_size = 2
shadow_color = Color(0, 0, 0, 0.5647059)
shadow_color = Color(0, 0, 0, 0.564706)
[node name="SongDisplay" type="Control" node_paths=PackedStringArray("background", "NameLabel", "ArtistLabel", "PlayButton", "OpenURLButton")]
[node name="SongDisplay" type="Control" node_paths=PackedStringArray("background", "NameLabel", "ArtistLabel", "PlayButton")]
custom_minimum_size = Vector2(0, 75)
layout_mode = 3
anchors_preset = 10
@@ -23,7 +24,6 @@ background = NodePath("TextureRect")
NameLabel = NodePath("VBoxContainer/Name")
ArtistLabel = NodePath("VBoxContainer/Artist")
PlayButton = NodePath("Playbutton")
OpenURLButton = NodePath("OpenURl")
[node name="Panel" type="Panel" parent="."]
layout_mode = 1
@@ -83,13 +83,22 @@ grow_horizontal = 2
grow_vertical = 2
flat = true
[node name="OpenURl" type="Button" parent="."]
[node name="MenuButton" type="MenuButton" parent="."]
layout_mode = 1
anchors_preset = -1
anchors_preset = 6
anchor_left = 1.0
anchor_top = 0.5
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = -73.0
anchor_bottom = 0.5
offset_left = -22.0
offset_top = -31.5
offset_bottom = 31.5
grow_horizontal = 0
grow_vertical = 2
text = "open url"
icon = ExtResource("2_x33bo")
expand_icon = true
item_count = 2
popup/item_0/text = "Open URL"
popup/item_0/id = 0
popup/item_1/text = "Delete"
popup/item_1/id = 1
+9
View File
@@ -19,8 +19,17 @@ public partial class Context : Node
instance = this;
ISongPlayer = new SongPlayer();
AddChild(ISongPlayer);
RichPresenceManager.instance = new();
RichPresenceManager.instance.Setup();
}
public override void _Process(double delta)
{
base._Process(delta);
RichPresenceManager.instance.Update();
}
public void LoadDirectory(String path){
+41 -20
View File
@@ -13,30 +13,48 @@ using System.Net.Http;
public class Song{
public String Name;
public String Name = "";
public bool LoadedMetadata;
public String Artist;
public String Album;
public float Length;
public String Comment;
public String URL;
public String Directory;
public String Artist = "";
public String Album = "";
public double Length;
public String Comment = "";
public String URL = "";
public String Directory = "";
public void LoadMetadata(){
var TLfile = TagLib.File.Create(Directory);
Track theTrack = new Track(Directory);
if (theTrack.AdditionalFields.ContainsKey("comment")){
URL = theTrack.AdditionalFields["comment"];
if (Directory == ""){
return;
}
Album ??= theTrack.Album;
Artist ??= theTrack.Artist;
Name = String.IsNullOrEmpty(TLfile.Tag.Title) ? Name : theTrack.Title;
Track theTrack = new(Directory);
if (theTrack.AdditionalFields.TryGetValue("comment", out string value)){
URL = value;
}
Album = theTrack.Album;
Artist = theTrack.Artist;
Name = String.IsNullOrEmpty(theTrack.Title) ? Name : theTrack.Title;
Length = theTrack.Duration;
Comment = theTrack.Comment;
}
public AudioStream LoadSong(){
AudioStream Stream = new();
if (Directory.ToLower().EndsWith(".mp3")){
AudioStreamMP3 stream = AudioStreamMP3.LoadFromFile(Directory);
Stream = stream;
}
else if(Directory.ToLower().EndsWith(".wav")){
AudioStreamWav stream = AudioStreamWav.LoadFromFile(Directory);
Stream = stream;
}
else if(Directory.ToLower().EndsWith(".ogg")){
AudioStreamOggVorbis stream = AudioStreamOggVorbis.LoadFromFile(Directory);
Stream = stream;
}
Length = Stream.GetLength();
return Stream;
}
public Image LoadImage(){
var TLfile = TagLib.File.Create(Directory);
if (TLfile.Tag.Pictures.Count() == 0){
if (TLfile.Tag.Pictures.Length == 0){
return null;
}
String type = TLfile.Tag.Pictures[0].MimeType;
@@ -97,13 +115,16 @@ class URLImageGetter{
String cleansource = source;
String ImageURL = "";
if (cleansource.StartsWith("https://")){
cleansource = cleansource.Remove(0,7);
cleansource = cleansource.Remove(0,8);
}
GD.Print(cleansource);
if (source.StartsWith("www.youtube.com")){
if (cleansource.StartsWith("www.youtube")){
ImageURL = "https://i.ytimg.com/vi/";
ImageURL += cleansource.Split("?")[1].Split("?")[0].Replace("v=","");
ImageURL += "/hqdefault.jpg";
ImageURL += cleansource.Split("?")[1].Split("&")[0].Replace("v=","");
ImageURL += "/hq720.jpg";
}
else{
GD.Print("Dosent start wi yt ");
}
GD.Print("converted ", source, " to ", ImageURL);
return ImageURL;
+94
View File
@@ -0,0 +1,94 @@
using Godot;
using System;
using System.Collections.Generic;
using System.Linq;
public partial class PerformanceDisplay : Node
{
[Export] public PackedScene display;
[Export] public Control UpperMargin;
[Export] public Control SongContainer;
[Export] public Control LowerMargin;
[Export] public ScrollContainer Scroll;
public override void _Ready()
{
base._Ready();
if (Context.instance != null){
Context.instance.SongsUpdated += UpdateDisplay;
}
else{
GD.PushError("instance null");
}
}
IEnumerable<Song> DisplayedSongs = [];
void UpdateDisplay(IEnumerable<Song> songs){
DisplayedSongs = songs;
GD.Print("Updated, songs ",songs.Count());
}
public override void _Process(double delta)
{
base._Process(delta);
int CurrentIndex = (int)(Scroll.ScrollVertical/ 75);
int MaxIndex = (int)((Scroll.Size.Y / 75)+CurrentIndex+1);
IEnumerable<SongDisplay> DisplayRemove =[];
IEnumerable<int> ids = [];
IEnumerable<SongDisplay> displays = [];
foreach(Node child in SongContainer.GetChildren()){
if (child is SongDisplay display1)
{
displays = displays.Append(display1);
}
}
if (displays.Any())
{
foreach (SongDisplay display in displays){
if (display.DisplayId < CurrentIndex || display.DisplayId > MaxIndex){
DisplayRemove = DisplayRemove.Append(display);
}
else{
ids = ids.Append(display.DisplayId);
}
}
}
for (int i = CurrentIndex; i >= CurrentIndex && i <= MaxIndex;i++)
{
if (!ids.Contains(i)){
if (i > DisplayedSongs.Count()-1){
break;
}
Song Songinfo = DisplayedSongs.ElementAt(i);
if (!Songinfo.LoadedMetadata){
Songinfo.LoadMetadata();
}
SongDisplay scene = (SongDisplay)display.Instantiate();
SongContainer.AddChild(scene);
scene.Setup(Songinfo);
scene.DisplayId = i;
SongContainer.MoveChild(scene,i - CurrentIndex);
GD.Print("CurrentIndex ", CurrentIndex);
displays = displays.Append(scene);
}
}
foreach (SongDisplay display in DisplayRemove)
{
display.QueueFree();
}
update_margins(CurrentIndex);
}
void update_margins(int CurrentIndex,int songsize = 75){
int ChildSize = SongContainer.GetChildren().Count * songsize;
int TotalSize = songsize * DisplayedSongs.Count();
int TopMarginSize = CurrentIndex*songsize;
int LowMarginSize = TotalSize-ChildSize-TopMarginSize;
UpperMargin.CustomMinimumSize = new Vector2(0,TopMarginSize);
LowerMargin.CustomMinimumSize = new Vector2(0, LowMarginSize);
}
}
+1
View File
@@ -0,0 +1 @@
uid://23jo0gxt4s8r
+88
View File
@@ -0,0 +1,88 @@
using System;
using System.Collections.Generic;
using System.Linq;
using DiscordRPC;
using Godot;
public class RichPresenceManager{
public static RichPresenceManager instance;
public static DiscordRpcClient client;
public const string DISCORD_APP_ID = "1276916292170809426";
RichPresence CurrentPresence;
public void Setup(){
client = new DiscordRpcClient(DISCORD_APP_ID,autoEvents:false);
client.Initialize();
client.SetPresence(new RichPresence()
{
Details = "Just started up...",
State = "Listening",
DetailsUrl = "https://realbucketofchicken.github.io/SimplSite/simplaudio.html",
StatusDisplay = StatusDisplayType.State,
Type = DiscordRPC.ActivityType.Listening,
Assets = new DiscordRPC.Assets()
{
SmallImageText = "Simpaudio",
}
});
client.OnReady += (sender, msg) =>
{
//Create some events so we know things are happening
GD.Print("Connected to discord with user ", msg.User.Username);
GD.Print("Avatar: ", msg.User.GetAvatarURL(User.AvatarFormat.WebP));
GD.Print("Decoration: ", msg.User.GetAvatarDecorationURL());
};
}
public void SetPresence(Song song){
if (!song.LoadedMetadata){
song.LoadMetadata();
}
Timestamps SongTimespan = Timestamps.FromTimeSpan(song.Length);
List<DiscordRPC.Button> buttons = [new DiscordRPC.Button(){
Label = "About Simplaudio",
Url = "https://realbucketofchicken.github.io/SimplSite/simplaudio.html"
}];
if (song.URL != ""){
buttons.Add(new DiscordRPC.Button(){
Label = "Open song",
Url = song.URL
});
}
GD.Print("Song end rpc set to ", SongTimespan.EndUnixMilliseconds/1000);
GD.Print("artist is : ", song.Artist);
CurrentPresence = new RichPresence()
{
Details = song.Name,
State = song.Artist ,
StatusDisplay = (!String.IsNullOrEmpty(song.Artist)) ? StatusDisplayType.State : StatusDisplayType.Details,
Type = DiscordRPC.ActivityType.Listening,
Assets = new DiscordRPC.Assets()
{
LargeImageKey = URLImageGetter.GetImageURL(song.URL),
SmallImageKey = (URLImageGetter.GetImageURL(song.URL) != "") ? "logo" : "",
SmallImageText = "Simpaudio",
},
Timestamps = SongTimespan,
Buttons = buttons.ToArray()
};
client.SetPresence(CurrentPresence);
}
public void UpdateTime(double progress,double totaltime,bool paused) {
GD.Print("total ", totaltime, " progess", progress," without ",totaltime-progress);
Timestamps stamps = Timestamps.FromTimeSpan(totaltime-progress);
Timestamps newstamps = new()
{
Start = stamps.Start.Value.AddSeconds(-progress),
End = stamps.End.Value
};
CurrentPresence.Timestamps = newstamps;
client.SetPresence(CurrentPresence);
GD.Print(CurrentPresence.Timestamps.StartUnixMilliseconds/1000," Song end rpc set to ", CurrentPresence.Timestamps.EndUnixMilliseconds/1000);
}
public void Update() {
//Invoke the events once per-frame. The events will be executed on calling thread.
client?.Invoke();
}
}
+1
View File
@@ -0,0 +1 @@
uid://8lkuvswadl5r
+1 -76
View File
@@ -3,87 +3,12 @@ using System;
using System.Collections.Generic;
using System.Linq;
public partial class SearchDisplay : Node
public partial class SearchDisplay : PerformanceDisplay
{
[Export] PackedScene display;
[Export] Control UpperMargin;
[Export] Control SongContainer;
[Export] Control LowerMargin;
[Export] ScrollContainer Scroll;
public override void _Ready()
{
base._Ready();
Context.instance.SongsUpdated += UpdateDisplay;
}
IEnumerable<Song> DisplayedSongs = [];
void UpdateDisplay(IEnumerable<Song> songs){
DisplayedSongs = songs;
GD.Print("Updated, songs ",songs.Count());
}
public override void _Process(double delta)
{
base._Process(delta);
int CurrentIndex = (int)(Scroll.ScrollVertical/ 75);
int MaxIndex = (int)((Scroll.Size.Y / 75)+CurrentIndex+1);
IEnumerable<SongDisplay> DisplayRemove =[];
IEnumerable<int> ids = [];
IEnumerable<SongDisplay> displays = [];
foreach(Node child in SongContainer.GetChildren()){
if (child is SongDisplay display1)
{
displays = displays.Append(display1);
}
}
if (displays.Any())
{
foreach (SongDisplay display in displays){
if (display.DisplayId < CurrentIndex || display.DisplayId > MaxIndex){
DisplayRemove = DisplayRemove.Append(display);
}
else{
ids = ids.Append(display.DisplayId);
}
}
}
for (int i = CurrentIndex; i >= CurrentIndex && i <= MaxIndex;i++)
{
if (!ids.Contains(i)){
if (i > DisplayedSongs.Count()-1){
break;
}
Song Songinfo = DisplayedSongs.ElementAt(i);
if (!Songinfo.LoadedMetadata){
Songinfo.LoadMetadata();
}
SongDisplay scene = (SongDisplay)display.Instantiate();
SongContainer.AddChild(scene);
scene.Setup(Songinfo);
scene.DisplayId = i;
SongContainer.MoveChild(scene,i - CurrentIndex);
GD.Print("CurrentIndex ", CurrentIndex);
displays = displays.Append(scene);
}
}
foreach (SongDisplay display in DisplayRemove)
{
display.QueueFree();
}
update_margins(CurrentIndex);
}
void update_margins(int CurrentIndex,int songsize = 75){
int ChildSize = SongContainer.GetChildren().Count * songsize;
int TotalSize = songsize * DisplayedSongs.Count();
int TopMarginSize = CurrentIndex*songsize;
int LowMarginSize = TotalSize-ChildSize-TopMarginSize;
UpperMargin.CustomMinimumSize = new Vector2(0,TopMarginSize);
LowerMargin.CustomMinimumSize = new Vector2(0, LowMarginSize);
}
}
+5 -2
View File
@@ -10,7 +10,7 @@ public partial class SongDisplay : Control
[Export] Label NameLabel;
[Export] Label ArtistLabel;
[Export] Button PlayButton;
[Export] Button OpenURLButton;
[Export] MenuButton OpenURLButton;
public void Setup(Song info){
SavedInfo = info;
Image image = info.LoadImage();
@@ -22,7 +22,7 @@ public partial class SongDisplay : Control
ArtistLabel.Text = SavedInfo.Artist;
PlayButton.Pressed += ButtonPressed;
OpenURLButton.Pressed += URLOpen;
//OpenURLButton.GetPopup().Connect("id_pressed", new Callable(this, "id_pressed"));
}
void ButtonPressed(){
Context.ISongPlayer.LoadSong(SavedInfo);
@@ -31,4 +31,7 @@ public partial class SongDisplay : Control
void URLOpen(){
OS.ShellOpen(SavedInfo.URL);
}
public void id_pressed(int idx){
}
}
+8 -20
View File
@@ -17,6 +17,7 @@ public partial class SongPlayer : Node{
}
Player.StreamPaused = true;
SongStateUpdated?.Invoke(true);
}
public void UnpauseSong(){
GD.Print("UnpauseSong");
@@ -28,35 +29,22 @@ public partial class SongPlayer : Node{
}
public void LoadSong(Song song){
Player?.QueueFree();
if (song.Directory.ToLower().EndsWith(".mp3")){
AudioStreamMP3 stream = AudioStreamMP3.LoadFromFile(song.Directory);
Player = new AudioStreamPlayer();
Player.Stream = stream;
AddChild(Player);
}
else if(song.Directory.ToLower().EndsWith(".wav")){
AudioStreamWav stream = AudioStreamWav.LoadFromFile(song.Directory);
Player = new AudioStreamPlayer();
Player.Stream = stream;
AddChild(Player);
}
else if(song.Directory.ToLower().EndsWith(".ogg")){
AudioStreamOggVorbis stream = AudioStreamOggVorbis.LoadFromFile(song.Directory);
Player = new AudioStreamPlayer();
Player.Stream = stream;
AddChild(Player);
}
Player = new AudioStreamPlayer();
Player.Stream = song.LoadSong();
AddChild(Player);
GD.Print("Playing ", song.Directory);
SongChanged?.Invoke(song);
Player.Bus = "Music";
RichPresenceManager.instance?.SetPresence(song);
}
// 0 - 1 range
public void SetPosition(float Position){
if (Player == null || Player.Stream == null){
return;
}
float length = (float)Player.Stream.GetLength();
Player.Play(length*Position);
double length = Player.Stream.GetLength();
Player.Play((float)length*Position);
RichPresenceManager.instance.UpdateTime((double)Position*length,(double)length,false);
}
public float GetPosition(){
if (Player == null || Player.Stream == null){
+1 -1
View File
@@ -1,4 +1,4 @@
<Project Sdk="Godot.NET.Sdk/4.5.0-beta.7">
<Project Sdk="Godot.NET.Sdk/4.4.0">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<EnableDynamicLoading>true</EnableDynamicLoading>
-11
View File
@@ -1,11 +0,0 @@
<Project Sdk="Godot.NET.Sdk/4.5.0-beta.7">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<EnableDynamicLoading>true</EnableDynamicLoading>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="TagLibSharp" Version="2.3.0" />
<PackageReference Include="z440.atl.core" Version="7.3.0" />
</ItemGroup>
</Project>
+2 -6
View File
@@ -12,7 +12,7 @@ config_version=5
config/name="Simplaudio"
run/main_scene="uid://mfcbf2sfino6"
config/features=PackedStringArray("4.5", "C#", "Forward Plus")
config/features=PackedStringArray("4.4", "C#", "Forward Plus")
run/low_processor_mode=true
boot_splash/bg_color=Color(0, 0, 0, 1)
boot_splash/use_filter=false
@@ -24,10 +24,6 @@ config/windows_native_icon="res://addons/godot-yt-dlp/src/favicon2.ico"
buses/default_bus_layout="res://Audio/default_bus_layout.tres"
[autoload]
DiscordRPCLoader="*res://addons/discord-rpc-gd/nodes/discord_autoload.gd"
[display]
window/size/initial_position_type=3
@@ -47,7 +43,7 @@ version_control/autoload_on_startup=true
[editor_plugins]
enabled=PackedStringArray("res://addons/discord-rpc-gd/plugin.cfg", "res://addons/godot-yt-dlp/plugin.cfg")
enabled=PackedStringArray()
[internationalization]