TSTTPInputVM.swift 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. //
  2. // TSTTPInputVM.swift
  3. // AIEmoji
  4. //
  5. // Created by 100Years on 2025/3/11.
  6. //
  7. import ObjectMapper
  8. let kRandomTextToRintone:[String] = [
  9. "Create a upbeat Pop ringtone with a catchy melody, bright synths, and a cheerful vibe. Use a BPM of 120-130 and keep it energetic and memorable.",
  10. "Generate a cinematic ringtone with orchestral strings, powerful brass, and a dramatic build-up. Use a BPM of 60-80 for a grand, inspiring feel.",
  11. "Produce a Lo-Fi ringtone with a relaxed piano melody, soft beats, and warm vinyl crackle. Use a BPM of 70-90 for a cozy, laid-back vibe.",
  12. "Create a EDM ringtone with a pulsating bassline, uplifting synths, and a quick build-up. Use a BPM of 128-132 for a high-energy, festival-ready sound.",
  13. "Generate a Jazz ringtone with a smooth saxophone melody, soft piano chords, and a gentle swing rhythm. Use a BPM of 90-100 for a classy, sophisticated tone.",
  14. "Produce a Funk ringtone with a groovy bassline, rhythmic guitar chops, and punchy brass hits. Use a BPM of 100-110 for a lively, danceable vibe.",
  15. "Create a Dubstep ringtone with heavy bass wobbles, aggressive synths, and a quick drop. Use a BPM of 140-150 for an intense, edgy sound.",
  16. "Generate a Folk ringtone with a fingerpicked acoustic guitar melody and light percussion. Use a BPM of 80-90 for a warm, earthy feel.",
  17. "Produce a Synthwave ringtone with retro arpeggiated synths, a driving beat, and an 80s-inspired vibe. Use a BPM of 100-110 for a nostalgic, futuristic tone.",
  18. "Create a Techno ringtone with a repetitive bassline, crisp hi-hats, and subtle synth textures. Use a BPM of 125-130 for a sleek, modern sound.",
  19. ]
  20. class TSTTPInputVM {
  21. var selectedStyleIndex:Int = 0
  22. //选择 prompt 类型组
  23. lazy var ptpStyleModels: [TSGenerateStyleModel] = {
  24. var ptpStyleModels = [TSGenerateStyleModel]()
  25. if let dataArray = Mapper<TSGenerateStyleModel>().mapArray(JSONfile: "text_to_photo_style.json"){
  26. ptpStyleModels = dataArray
  27. if let model = dataArray.safeObj(At: selectedStyleIndex) {
  28. selectPromptModel = model //加上默认的选择
  29. }
  30. }
  31. return ptpStyleModels
  32. }()
  33. //输入框内容
  34. var promptText:String = "" {
  35. didSet{
  36. isCanGennerateBlock?(isCanGennerate)
  37. }
  38. }
  39. //选择的 prompt 类型
  40. var selectPromptModel:TSGenerateStyleModel?{
  41. didSet{
  42. isCanGennerateBlock?(isCanGennerate)
  43. }
  44. }
  45. //可生成状态变化 block
  46. var isCanGennerateBlock:((Bool)->Void)?
  47. }
  48. extension TSTTPInputVM {
  49. //是否满足生成条件
  50. var isCanGennerate:Bool {
  51. if selectPromptModel != nil ,
  52. promptText.replacingOccurrences(of: " ", with: "").count > 0
  53. {
  54. return true
  55. }
  56. return false
  57. }
  58. var prompt:String{
  59. var prompt = promptText
  60. if let selectPromptModel = selectPromptModel,selectPromptModel.prompt.count > 0 {
  61. prompt = "\(selectPromptModel.prompt)," + prompt
  62. }
  63. return prompt
  64. }
  65. func saveModel(model:TSActionInfoModel){
  66. TSRMShared.ttpDBHistory.updateData(model)
  67. }
  68. }