🚧 Fade in menu
This commit is contained in:
		
					parent
					
						
							
								d8e671d5ca
							
						
					
				
			
			
				commit
				
					
						d175360362
					
				
			
		
					 2 changed files with 81 additions and 18 deletions
				
			
		
							
								
								
									
										71
									
								
								app/fade.go
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										71
									
								
								app/fade.go
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,71 @@ | |||
| package app | ||||
| 
 | ||||
| import ( | ||||
| 	"os" | ||||
| 	"strconv" | ||||
| 
 | ||||
| 	"codeberg.org/danjones000/strip-beats/media" | ||||
| 	"github.com/rivo/tview" | ||||
| ) | ||||
| 
 | ||||
| func validateNumber(input string, lastChar rune) bool { | ||||
| 	num, err := strconv.ParseFloat(input, 64) | ||||
| 	if err != nil { | ||||
| 		return false | ||||
| 	} | ||||
| 
 | ||||
| 	if num < 0 { | ||||
| 		return false | ||||
| 	} | ||||
| 
 | ||||
| 	if file == nil { | ||||
| 		return true | ||||
| 	} | ||||
| 
 | ||||
| 	st := file.WantedAudioStream() | ||||
| 	if st == nil { | ||||
| 		return true | ||||
| 	} | ||||
| 
 | ||||
| 	return num <= st.Duration | ||||
| } | ||||
| 
 | ||||
| func fadeFile() error { | ||||
| 	tmp, err := os.CreateTemp("", "audio.*.mka") | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	tmp.Close() | ||||
| 
 | ||||
| 	var start, stop, up, down float64 | ||||
| 
 | ||||
| 	cont := tview.NewApplication() | ||||
| 	form := tview.NewForm(). | ||||
| 		AddInputField("Beginning time?", "0", 0, validateNumber, func(input string) { | ||||
| 			start, _ = strconv.ParseFloat(input, 64) | ||||
| 		}). | ||||
| 		AddInputField("Ending time? (leave 0 for full time)", "0", 0, validateNumber, func(input string) { | ||||
| 			stop, _ = strconv.ParseFloat(input, 64) | ||||
| 		}). | ||||
| 		AddInputField("Fade in duration?", "0", 0, validateNumber, func(input string) { | ||||
| 			up, _ = strconv.ParseFloat(input, 64) | ||||
| 		}). | ||||
| 		AddInputField("Fade out duration?", "0", 0, validateNumber, func(input string) { | ||||
| 			down, _ = strconv.ParseFloat(input, 64) | ||||
| 		}). | ||||
| 		AddButton("Start", func() { | ||||
| 			cont.Stop() | ||||
| 		}) | ||||
| 
 | ||||
| 	form.SetBorder(true).SetTitleAlign(tview.AlignLeft) | ||||
| 	if err := cont.SetRoot(form, true).EnableMouse(true).Run(); err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 
 | ||||
| 	err = media.TrimWithFade(*file, tmp.Name(), start, stop, up, down) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	SetTmpFile(tmp.Name()) | ||||
| 	return nil | ||||
| } | ||||
							
								
								
									
										28
									
								
								app/run.go
									
										
									
									
									
								
							
							
						
						
									
										28
									
								
								app/run.go
									
										
									
									
									
								
							|  | @ -24,21 +24,6 @@ func quit() { | |||
| 	os.Exit(0) | ||||
| } | ||||
| 
 | ||||
| func testTrim() { | ||||
| 	path := "/home/drj/MyFiles/Videos/WebShows/YouTube/Savannah_Outen/Love_Me_Like_You_Do_-_Ellie_Goulding_Cover_by_Savannah_Outen-tPYfBpRxXfI.mp4" | ||||
| 	file := SetFile(path) | ||||
| 	tmp, _ := os.CreateTemp("", "audio.*.mka") | ||||
| 	tmp.Close() | ||||
| 	// err := media.TrimWithFade(file, tmp.Name(), 0, 215.84, 0, 3) | ||||
| 	// err := media.Trim(file, tmp.Name(), 0, 215.84) | ||||
| 	err := media.TrimWithFade(file, tmp.Name(), 15.2, 70.84, 3.6, 8.4) | ||||
| 	if err != nil { | ||||
| 		panic(err) | ||||
| 	} | ||||
| 	fmt.Println(tmp.Name()) | ||||
| 	quit() | ||||
| } | ||||
| 
 | ||||
| func Run(step AppStep) { | ||||
| 	for step < Quit { | ||||
| 		switch step { | ||||
|  | @ -56,16 +41,23 @@ func Run(step AppStep) { | |||
| 			} | ||||
| 		case Watch: | ||||
| 			media.Watch(file.Format.Path) | ||||
| 			fade := boolean.Choose(fmt.Sprintf("Would you like to trim/fade %s?", file.ShortPath())) | ||||
| 			if fade { | ||||
| 			fadeAns := boolean.Choose(fmt.Sprintf("Would you like to trim/fade %s?", file.ShortPath())) | ||||
| 			if fadeAns { | ||||
| 				step = Fade | ||||
| 			} else { | ||||
| 				step = mainMenu() | ||||
| 			} | ||||
| 		case Fade: | ||||
| 			fadeFile() | ||||
| 			listenFaded := boolean.Choose(fmt.Sprintf("Would you like to listen to %s?", tmpfile.ShortPath())) | ||||
| 			if listenFaded { | ||||
| 				media.Watch(tmpfile.Format.Path) | ||||
| 			} | ||||
| 			step = mainMenu() // @todo ask to check new file | ||||
| 		case Quit: | ||||
| 			quit() | ||||
| 		default: | ||||
| 			step = mainMen() | ||||
| 			step = mainMenu() | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue