From f923a3824561c6cf200c638e3d44d1cbf4adf7d8 Mon Sep 17 00:00:00 2001
From: Arturs Artamonovs <arturs.artamonovs@protonmail.com>
Date: Sun, 5 Jan 2025 10:07:35 +0000
Subject: Waterfall: drawing from file initial implementatiom, visual version
 concept is ready

---
 .../AccentColor.colorset/Contents.json             | 11 +++
 .../AppIcon.appiconset/Contents.json               | 58 +++++++++++++
 WaterfallFile_UI/Assets.xcassets/Contents.json     |  6 ++
 WaterfallFile_UI/ContentView.swift                 | 94 ++++++++++++++++++++++
 WaterfallFile_UI/FileSpectrum.swift                | 64 +++++++++++++++
 WaterfallFile_UI/Item.swift                        | 18 +++++
 .../Preview Assets.xcassets/Contents.json          |  6 ++
 WaterfallFile_UI/WaterfallFile_UI.entitlements     | 10 +++
 WaterfallFile_UI/WaterfallFile_UIApp.swift         | 45 +++++++++++
 9 files changed, 312 insertions(+)
 create mode 100644 WaterfallFile_UI/Assets.xcassets/AccentColor.colorset/Contents.json
 create mode 100644 WaterfallFile_UI/Assets.xcassets/AppIcon.appiconset/Contents.json
 create mode 100644 WaterfallFile_UI/Assets.xcassets/Contents.json
 create mode 100644 WaterfallFile_UI/ContentView.swift
 create mode 100644 WaterfallFile_UI/FileSpectrum.swift
 create mode 100644 WaterfallFile_UI/Item.swift
 create mode 100644 WaterfallFile_UI/Preview Content/Preview Assets.xcassets/Contents.json
 create mode 100644 WaterfallFile_UI/WaterfallFile_UI.entitlements
 create mode 100644 WaterfallFile_UI/WaterfallFile_UIApp.swift

(limited to 'WaterfallFile_UI')

diff --git a/WaterfallFile_UI/Assets.xcassets/AccentColor.colorset/Contents.json b/WaterfallFile_UI/Assets.xcassets/AccentColor.colorset/Contents.json
new file mode 100644
index 0000000..eb87897
--- /dev/null
+++ b/WaterfallFile_UI/Assets.xcassets/AccentColor.colorset/Contents.json
@@ -0,0 +1,11 @@
+{
+  "colors" : [
+    {
+      "idiom" : "universal"
+    }
+  ],
+  "info" : {
+    "author" : "xcode",
+    "version" : 1
+  }
+}
diff --git a/WaterfallFile_UI/Assets.xcassets/AppIcon.appiconset/Contents.json b/WaterfallFile_UI/Assets.xcassets/AppIcon.appiconset/Contents.json
new file mode 100644
index 0000000..3f00db4
--- /dev/null
+++ b/WaterfallFile_UI/Assets.xcassets/AppIcon.appiconset/Contents.json
@@ -0,0 +1,58 @@
+{
+  "images" : [
+    {
+      "idiom" : "mac",
+      "scale" : "1x",
+      "size" : "16x16"
+    },
+    {
+      "idiom" : "mac",
+      "scale" : "2x",
+      "size" : "16x16"
+    },
+    {
+      "idiom" : "mac",
+      "scale" : "1x",
+      "size" : "32x32"
+    },
+    {
+      "idiom" : "mac",
+      "scale" : "2x",
+      "size" : "32x32"
+    },
+    {
+      "idiom" : "mac",
+      "scale" : "1x",
+      "size" : "128x128"
+    },
+    {
+      "idiom" : "mac",
+      "scale" : "2x",
+      "size" : "128x128"
+    },
+    {
+      "idiom" : "mac",
+      "scale" : "1x",
+      "size" : "256x256"
+    },
+    {
+      "idiom" : "mac",
+      "scale" : "2x",
+      "size" : "256x256"
+    },
+    {
+      "idiom" : "mac",
+      "scale" : "1x",
+      "size" : "512x512"
+    },
+    {
+      "idiom" : "mac",
+      "scale" : "2x",
+      "size" : "512x512"
+    }
+  ],
+  "info" : {
+    "author" : "xcode",
+    "version" : 1
+  }
+}
diff --git a/WaterfallFile_UI/Assets.xcassets/Contents.json b/WaterfallFile_UI/Assets.xcassets/Contents.json
new file mode 100644
index 0000000..73c0059
--- /dev/null
+++ b/WaterfallFile_UI/Assets.xcassets/Contents.json
@@ -0,0 +1,6 @@
+{
+  "info" : {
+    "author" : "xcode",
+    "version" : 1
+  }
+}
diff --git a/WaterfallFile_UI/ContentView.swift b/WaterfallFile_UI/ContentView.swift
new file mode 100644
index 0000000..92445d8
--- /dev/null
+++ b/WaterfallFile_UI/ContentView.swift
@@ -0,0 +1,94 @@
+//
+//  ContentView.swift
+//  WaterfallFile_UI
+//
+//  Created by Jacky Jack on 23/12/2024.
+//
+
+import SwiftUI
+import SwiftData
+import AppKit
+
+
+struct ContentView: View {
+    @Environment(\.modelContext) private var modelContext
+    
+    @EnvironmentObject var fileSpectrum: FileSpectrum
+    
+    @State private var image: Image?
+    
+    @Query private var items: [Item]
+
+    var body: some View {
+        /*
+        NavigationSplitView {
+            List {
+                ForEach(items) { item in
+                    NavigationLink {
+                        Text("Item at \(item.timestamp, format: Date.FormatStyle(date: .numeric, time: .standard))")
+                    } label: {
+                        Text(item.timestamp, format: Date.FormatStyle(date: .numeric, time: .standard))
+                    }
+                }
+                .onDelete(perform: deleteItems)
+            }
+            .navigationSplitViewColumnWidth(min: 180, ideal: 200)
+            .toolbar {
+                ToolbarItem {
+                    Button(action: addItem) {
+                        Label("Add Item", systemImage: "plus")
+                    }
+                }
+            }
+        } detail: {
+            Text("Select an item")
+        }
+        */
+        //Image(decorative: fileSpectrum.makeSpectrogramImage(), scale: 1.0, orientation: .left)
+        VStack {
+            //Image(nsImage:fileSpectrum.outputImage)
+            Image(decorative: fileSpectrum.outputImage,
+                              scale: 1,
+                              orientation: .left)
+                        //.resizable()
+            
+            
+            //Image(fileSpectrum.makeSpectrogramImage(), scale: 1, orientation:.left, label: "Image")
+            //Image(decorative: fileSpectrum.makeSpectrogramImage(), scale: 1.0, orientation: .left)
+            //Image(nsImage: fileSpectrum.makeSpectrogramImage())
+            HStack {
+                Text("Hello world")
+                    .padding()
+                Button("Start") {
+                    print("Start")
+                }
+                Button("Stop") {
+                    print("Stop")
+                }
+                Button("Load") {
+                    print("Load")
+                }
+            }
+        }
+    }
+
+    private func addItem() {
+        withAnimation {
+            let newItem = Item(timestamp: Date())
+            modelContext.insert(newItem)
+        }
+    }
+
+    private func deleteItems(offsets: IndexSet) {
+        withAnimation {
+            for index in offsets {
+                modelContext.delete(items[index])
+            }
+        }
+    }
+}
+
+#Preview {
+    ContentView()
+        .modelContainer(for: Item.self, inMemory: true)
+}
diff --git a/WaterfallFile_UI/FileSpectrum.swift b/WaterfallFile_UI/FileSpectrum.swift
new file mode 100644
index 0000000..6415dfa
--- /dev/null
+++ b/WaterfallFile_UI/FileSpectrum.swift
@@ -0,0 +1,64 @@
+//
+//  FileSpectrum.swift
+//  PrySDR
+//
+//  Created by Jacky Jack on 01/01/2025.
+//
+
+import Accelerate
+import AppKit
+import Combine
+import CoreImage
+
+
+class FileSpectrum: NSObject, ObservableObject {
+    
+    let default_width = 512
+    let default_height = 512
+    
+    let sessionQueue = DispatchQueue(label: "sessionQueue",
+                                         attributes: [],
+                                         autoreleaseFrequency: .workItem)
+    
+    @Published var outputImage = emptyCGImage
+    
+    let simpleImage = SimpleImage(width: 256, height: 256)
+    
+    /// A 1x1 Core Graphics image.
+    static var emptyCGImage: CGImage = {
+            let buffer = vImage.PixelBuffer(
+                pixelValues: [0],
+                size: .init(width: 1, height: 1),
+                pixelFormat: vImage.Planar8.self)
+            
+            let fmt = vImage_CGImageFormat(
+                bitsPerComponent: 8,
+                bitsPerPixel: 8 ,
+                colorSpace: CGColorSpaceCreateDeviceGray(),
+                bitmapInfo: CGBitmapInfo(rawValue: CGImageAlphaInfo.none.rawValue),
+                renderingIntent: .defaultIntent)
+            
+            return buffer.makeCGImage(cgImageFormat: fmt!)!
+    }()
+    
+    func makeSpectrogramImage() -> NSImage {
+        
+        return NSImage(cgImage: FileSpectrum.emptyCGImage, size: .zero)
+    }
+
+    
+    
+    func startRunning() {
+        sessionQueue.async {
+            print("lets start the task for spectrum analysis")
+            for i in 0..<100 {
+                print("Process the task \(i)")
+                self.simpleImage.drawPixel(i, i, PixelData(a: 255, r: 255, g: 0, b: 0))
+                DispatchQueue.main.async {
+                    self.outputImage = self.simpleImage.toCGImage()!
+                }
+                sleep(1)
+            }
+        }
+    }
+}
diff --git a/WaterfallFile_UI/Item.swift b/WaterfallFile_UI/Item.swift
new file mode 100644
index 0000000..f20bc8d
--- /dev/null
+++ b/WaterfallFile_UI/Item.swift
@@ -0,0 +1,18 @@
+//
+//  Item.swift
+//  WaterfallFile_UI
+//
+//  Created by Jacky Jack on 23/12/2024.
+//
+
+import Foundation
+import SwiftData
+
+@Model
+final class Item {
+    var timestamp: Date
+    
+    init(timestamp: Date) {
+        self.timestamp = timestamp
+    }
+}
diff --git a/WaterfallFile_UI/Preview Content/Preview Assets.xcassets/Contents.json b/WaterfallFile_UI/Preview Content/Preview Assets.xcassets/Contents.json
new file mode 100644
index 0000000..73c0059
--- /dev/null
+++ b/WaterfallFile_UI/Preview Content/Preview Assets.xcassets/Contents.json	
@@ -0,0 +1,6 @@
+{
+  "info" : {
+    "author" : "xcode",
+    "version" : 1
+  }
+}
diff --git a/WaterfallFile_UI/WaterfallFile_UI.entitlements b/WaterfallFile_UI/WaterfallFile_UI.entitlements
new file mode 100644
index 0000000..18aff0c
--- /dev/null
+++ b/WaterfallFile_UI/WaterfallFile_UI.entitlements
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+	<key>com.apple.security.app-sandbox</key>
+	<true/>
+	<key>com.apple.security.files.user-selected.read-only</key>
+	<true/>
+</dict>
+</plist>
diff --git a/WaterfallFile_UI/WaterfallFile_UIApp.swift b/WaterfallFile_UI/WaterfallFile_UIApp.swift
new file mode 100644
index 0000000..959fe55
--- /dev/null
+++ b/WaterfallFile_UI/WaterfallFile_UIApp.swift
@@ -0,0 +1,45 @@
+//
+//  WaterfallFile_UIApp.swift
+//  WaterfallFile_UI
+//
+//  Created by Jacky Jack on 23/12/2024.
+//
+
+import SwiftUI
+import SwiftData
+
+@main
+struct WaterfallFile_UIApp: App {
+    
+    let fileSpectrum = FileSpectrum()
+    
+    @Environment(\.scenePhase) private var scenePhase
+    
+    var sharedModelContainer: ModelContainer = {
+        let schema = Schema([
+            Item.self,
+        ])
+        let modelConfiguration = ModelConfiguration(schema: schema, isStoredInMemoryOnly: false)
+
+        do {
+            return try ModelContainer(for: schema, configurations: [modelConfiguration])
+        } catch {
+            fatalError("Could not create ModelContainer: \(error)")
+        }
+    }()
+
+    var body: some Scene {
+        WindowGroup {
+            ContentView()
+            .environmentObject(fileSpectrum)
+            .onChange(of: scenePhase) { phase in
+                if phase == .active {
+                    Task(priority: .userInitiated) {
+                        fileSpectrum.startRunning()
+                    }
+                }
+            }
+        }
+        .modelContainer(sharedModelContainer)
+    }
+}
-- 
cgit v1.2.3