Skip to content

Commit

Permalink
Add a word remove list, which wont remove the whole line
Browse files Browse the repository at this point in the history
fix scaling on high dpi displays
use skiplist to allow words that are in the remove list
  • Loading branch information
zefanjajobse committed Sep 8, 2024
1 parent c496f58 commit 00ce4c1
Show file tree
Hide file tree
Showing 8 changed files with 167 additions and 98 deletions.
43 changes: 29 additions & 14 deletions PlanningCenter to OPS/Actions/DrawFormItems.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ public SongInfo(string type, int? id, Structs.SongListData detailed)
}
}

internal class DpiScale
{
public float DpiX;
public float DpiY;

public DpiScale(float dpiX, float dpiY)
{
DpiX = dpiX;
DpiY = dpiY;
}
}

internal class DrawFormItems
{
private static string SongTextInfo = "Lyrics:";
Expand All @@ -35,15 +47,18 @@ internal class DrawFormItems
private string SongId { get; set; }
private Config Config { get; set; }

private UcLabel Label = new UcLabel() { Width = 150 };
public static Graphics graphics = Graphics.FromHwnd(IntPtr.Zero);

Check warning on line 50 in PlanningCenter to OPS/Actions/DrawFormItems.cs

View workflow job for this annotation

GitHub Actions / Add release to GitHub

This call site is reachable on all platforms. 'Graphics.FromHwnd(nint)' is only supported on: 'windows' 6.1 and later. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)
public static DpiScale dpi_scale = new DpiScale(graphics.DpiX / 96, graphics.DpiY / 96);

Check warning on line 51 in PlanningCenter to OPS/Actions/DrawFormItems.cs

View workflow job for this annotation

GitHub Actions / Add release to GitHub

This call site is reachable on all platforms. 'Graphics.DpiY' is only supported on: 'windows' 6.1 and later. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 51 in PlanningCenter to OPS/Actions/DrawFormItems.cs

View workflow job for this annotation

GitHub Actions / Add release to GitHub

This call site is reachable on all platforms. 'Graphics.DpiX' is only supported on: 'windows' 6.1 and later. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

private UcLabel Label = new UcLabel() { Width = (int)Math.Round(150 * dpi_scale.DpiX), Height = (int)Math.Round(new UcLabel().Height * dpi_scale.DpiY) };

Check warning on line 53 in PlanningCenter to OPS/Actions/DrawFormItems.cs

View workflow job for this annotation

GitHub Actions / Add release to GitHub

This call site is reachable on all platforms. 'Control.Height' is only supported on: 'windows' 6.1 and later. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 53 in PlanningCenter to OPS/Actions/DrawFormItems.cs

View workflow job for this annotation

GitHub Actions / Add release to GitHub

This call site is reachable on all platforms. 'Control.Height' is only supported on: 'windows' 6.1 and later. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 53 in PlanningCenter to OPS/Actions/DrawFormItems.cs

View workflow job for this annotation

GitHub Actions / Add release to GitHub

This call site is reachable on all platforms. 'Control.Width' is only supported on: 'windows' 6.1 and later. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)
private Dictionary<string, Structs.Song> FoundSongs = new Dictionary<string, Structs.Song>();
private Dictionary<string, string> SongTooltipInfo = new Dictionary<string, string>();
private ComboBox ComboBox = new ComboBox() { DropDownStyle = ComboBoxStyle.DropDownList, DrawMode = DrawMode.OwnerDrawFixed, Width = 250 };
private Button CopyButton = new Button() { Text = "Kopieer lyrics", Width = 90 };
private ComboBox ComboBox = new ComboBox() { DropDownStyle = ComboBoxStyle.DropDownList, DrawMode = DrawMode.OwnerDrawFixed, Width = (int)Math.Round(250 * dpi_scale.DpiX) };
private Button CopyButton = new Button() { Text = "Kopieer lyrics", Width = (int)Math.Round(90 * dpi_scale.DpiX), Height = (int)Math.Round(new UcLabel().Height * dpi_scale.DpiY) };
private ToolTip ToolTip = new ToolTip() { AutoPopDelay = 0, InitialDelay = 0, ReshowDelay = 0, ShowAlways = true };

public static int StartX { get; set; } = 20;
public static int StartY { get; set; } = 40;
public static int StartX { get; set; } = (int)Math.Round(20 * DrawFormItems.dpi_scale.DpiX);
public static int StartY { get; set; } = (int)Math.Round(40 * DrawFormItems.dpi_scale.DpiX);
public static List<Structs.Song> OwnSongs;
public DrawFormItems(Config config, Structs.SongListData song_info, string type, string song_id)
{
Expand Down Expand Up @@ -109,16 +124,16 @@ public void Render(Form f, Config config)

Label.Left = StartX;
Label.Top = StartY;
StartX += 150; // Move position to right
StartX += (int)Math.Round(150 * dpi_scale.DpiX); // Move position to right
ComboBox.Left = StartX;
ComboBox.Top = StartY - 4;
ComboBox.Top = StartY - (int)Math.Round(4 * dpi_scale.DpiY);

CopyButton.Left = StartX + 252;
CopyButton.Top = StartY - 4;
CopyButton.Left = StartX + (int)Math.Round(252 * dpi_scale.DpiX);
CopyButton.Top = StartY - (int)Math.Round(4 * dpi_scale.DpiY);
CopyButton.Click += CopyButton_Click;

StartX = 20; // Reset to start
StartY += 30; // Move position to down
StartX = (int)Math.Round(20 * dpi_scale.DpiX); // Reset to start
StartY += (int)Math.Round(30 * dpi_scale.DpiY); // Move position to down
f.Controls.Add(Label);
f.Controls.Add(ComboBox);
f.Controls.Add(CopyButton);
Expand Down Expand Up @@ -147,16 +162,16 @@ internal static void RenderTitle(Form f, string text)
label.Text = text;
label.Left = StartX;
label.Top = StartY;
label.Width = 400;
label.Width = (int)Math.Round(400 * dpi_scale.DpiX);
label.ForeColor = System.Drawing.Color.Gray;
StartY += 30;
StartY += (int)Math.Round(30 * dpi_scale.DpiY);
f.Controls.Add(label);
}

private string GetLyrics()
{
Structs.Lyrics lyrics = Api.GetLyrics(this.Config, this.SongInfo.links.self);
return LyricsToFile.Lyrics(lyrics.data.attributes.lyrics);
return LyricsToFile.Lyrics(lyrics.data.attributes.lyrics, this.Config.skip_list);
}

private void CopyButton_Click(object sender, EventArgs e)
Expand Down
36 changes: 30 additions & 6 deletions PlanningCenter to OPS/Actions/LyricsToFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ namespace PlanningCenter_to_OPS.Actions
{
internal class LyricsToFile
{
private static readonly string[] removed_text = {
private static readonly string[] removed_if_in_line = {
"Vers 1",
"Vers 2",
"Vers 3",
"Vers 4",
"Vers 5",
"Verse 1",
"Verse 2",
"Verse 3",
Expand All @@ -35,7 +40,15 @@ internal class LyricsToFile
"(Interlude)",
"(REPEAT)",
"Verhoging",
};

private static readonly string[] remove_text = {
"<b>",
"<i>",
"<u>",
"</b>",
"</i>",
"</u>"
};

public static string ReplaceWordChars(string text)
Expand Down Expand Up @@ -73,7 +86,7 @@ public static string ReplaceWordChars(string text)
return s;
}

internal static string Lyrics(string lyrics)
internal static string Lyrics(string lyrics, List<string> skip_list)
{

string[] current_lyrics = lyrics.Split(
Expand All @@ -82,10 +95,11 @@ internal static string Lyrics(string lyrics)
);
string cleaned_lyrics = "";

string previous_line = "";
foreach (string line in current_lyrics)
{
// if value not in RemovedText
if (!removed_text.Any(s => line.ToLower().Contains(s.ToLower())))
// if value not in RemovedText or if added to skip_list
if (!removed_if_in_line.Any(s => line.ToLower().Contains(s.ToLower())) || skip_list.Any(s => s == line))
{
// replace chorus with ops eqivelant
Dictionary<string, string> translate_to_ops = new Dictionary<string, string>() {
Expand All @@ -112,7 +126,17 @@ internal static string Lyrics(string lyrics)
char[] chars = Encoding.ASCII.GetChars(bytes);
string result = new(chars);
result = result.Replace("?", "");
cleaned_lyrics += result + "\r\n";
foreach (var item in remove_text)
{
result = Regex.Replace(result, item, "");
}

// skip the line if current and previous result are both empty
if (!(previous_line == "" && result == ""))
{
cleaned_lyrics += result + "\r\n";
}
previous_line = result;
}
}
}
Expand All @@ -126,7 +150,7 @@ internal static void ToFile(Config config, Structs.SongListData song)
Structs.Lyrics lyrics_return = Api.GetLyrics(config, song.links.self);
if (lyrics_return.data.attributes.lyrics != null)
{
string cleaned_lyrics = Lyrics(lyrics_return.data.attributes.lyrics);
string cleaned_lyrics = Lyrics(lyrics_return.data.attributes.lyrics, config.skip_list);
try
{
File.WriteAllText(Path.Combine(config.song_folder, String.Format("{0}.txt", song.attributes.title)), cleaned_lyrics);
Expand Down
28 changes: 27 additions & 1 deletion PlanningCenter to OPS/Config.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
namespace PlanningCenter_to_OPS
using System.IO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;

namespace PlanningCenter_to_OPS
{
internal class Config
{
public string skip_list_location = "C:\\ProgramData\\Stichting Opwekking\\OPS 8\\opsSkipList.txt";
public List<string> skip_list = new();

public string app_id;
public string secret;
public string song_folder;
Expand Down Expand Up @@ -33,6 +42,23 @@ public Config()
last_used_ops_theme = Properties.Settings.Default.last_used_ops_theme;
}


public void ReadSkipList()
{
try
{
StreamReader sr = new StreamReader(this.skip_list_location);
while (!sr.EndOfStream)
{
skip_list.Add(sr.ReadLine());
}
}
catch (Exception e)
{
Console.WriteLine("Failed to read skiplist: " + e.Message);
}
}

public void Update()
{
Properties.Settings.Default.app_id = app_id;
Expand Down
Loading

0 comments on commit 00ce4c1

Please sign in to comment.