Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add status text #21

Merged
merged 1 commit into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions internal/logic/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ func getAudioFiles(folder string) ([]string, error) {
return audioFiles, nil
}

func CombineFiles(folder1 string, folder2 string, outputFolder string, progress *widget.ProgressBar, soundscapeVolume float64) error {
// Add a statusCallback parameter to allow updates on what is happening
func CombineFiles(folder1 string, folder2 string, outputFolder string, progress *widget.ProgressBar, soundscapeVolume float64, statusCallback func(string)) error {
// Adjust volume to range [0.5, 1.0]
soundscapeVolume = 0.5 + (soundscapeVolume / 100.0 * 0.5)

Expand All @@ -59,10 +60,11 @@ func CombineFiles(folder1 string, folder2 string, outputFolder string, progress
}

ffmpeg := ff.FFmpegPath()

total := len(files1)

for index, file := range files1 {
statusCallback(fmt.Sprintf("Preparing to combine file %d of %d: %s", index+1, total, filepath.Base(file)))

channel , err := getChannelAmount(file)
if err != nil {
return err
Expand Down Expand Up @@ -103,6 +105,8 @@ func CombineFiles(folder1 string, folder2 string, outputFolder string, progress
return err
}

statusCallback(fmt.Sprintf("Combining file %d of %d...", index+1, total))

// Execute FFmpeg command
if err := cmd.Start(); err != nil {
err = fmt.Errorf("error at ffmpeg command start: %w", err)
Expand All @@ -115,8 +119,11 @@ func CombineFiles(folder1 string, folder2 string, outputFolder string, progress
err = fmt.Errorf("error at ffmpeg command wait: %w", err)
return err
}

statusCallback(fmt.Sprintf("Finished combining file %d of %d", index+1, total))
}

statusCallback("All files combined successfully!")
return nil
}

Expand Down Expand Up @@ -194,20 +201,17 @@ func getCoverArtArguments(file1 string, file2 string) []string {
}

func testCoverArt(filePath string) bool {
// Open the audio file
f, err := os.Open(filePath)
if err != nil {
return false
}
defer f.Close()

// Use taglib to parse the audio file
metadata, err := tag.ReadFrom(f)
if err != nil {
return false
}

// Check if there is any artwork
if metadata.Picture() != nil {
return true
}
Expand Down
30 changes: 18 additions & 12 deletions internal/ui/windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,25 +178,32 @@ func CreateMainContent(app fyne.App, window fyne.Window) fyne.CanvasObject {
progressBar := widget.NewProgressBar()
progressBar.Hide()

statusLabel := widget.NewLabel("Idle")

startButton.OnTapped = func() {
startButton.Disable()
progressBar.Show()
go func() {
err := logic.CombineFiles(folder1, folder2, folderOutput, progressBar, volumeSlider.Value)
if err != nil {
dialog.ShowError(err, window)
} else {
dialog.ShowInformation("Success", "Audio files combined successfully", window)
}
progressBar.Hide()
startButton.Enable()
}()
// Run CombineFiles synchronously on the main goroutine
err := logic.CombineFiles(folder1, folder2, folderOutput, progressBar, volumeSlider.Value, func(msg string) {
// Safe to call directly because we're on the main goroutine
statusLabel.SetText(msg)
})
progressBar.Hide()
if err != nil {
dialog.ShowError(err, window)
statusLabel.SetText("Error during combination")
} else {
dialog.ShowInformation("Success", "Audio files combined successfully", window)
statusLabel.SetText("Done")
}
startButton.Enable()
}

actionCard := widget.NewCard(
"",
"",
container.NewVBox(
statusLabel,
startButton,
progressBar,
),
Expand All @@ -211,8 +218,7 @@ func CreateMainContent(app fyne.App, window fyne.Window) fyne.CanvasObject {
newText := "I am an individual developer who has created an app for Soundscape synchronization.\n" +
"I hope this app helps you as much as it has helped me.\n" +
"If you find it useful, please consider buying me a coffee. Thank you!"

// Use a label for static text to ensure consistent, visible color

aboutLabel := widget.NewLabel(newText)
aboutLabel.Wrapping = fyne.TextWrapWord

Expand Down
Loading