Skip to content

Commit

Permalink
New UI to call and python pages from home page #108 (#145)
Browse files Browse the repository at this point in the history
  • Loading branch information
Khushalsarode authored Jun 21, 2024
1 parent 26a81f8 commit 70fe4b0
Show file tree
Hide file tree
Showing 8 changed files with 243 additions and 221 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
soundscapenv
2 changes: 1 addition & 1 deletion Amplitude-Frequency-Visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ def close_current_visualizer():
stop()
if event == "Save":
save()

if event == 'Amplitude-Frequency-Visualizer':
close_current_visualizer()
_VARS["current_visualizer_process"] = subprocess.Popen(['python', 'Amplitude-Frequency-Visualizer.py'])
Expand All @@ -171,6 +170,7 @@ def close_current_visualizer():
_VARS["current_visualizer_process"] = subprocess.Popen(['python', 'Intensity-vs-Frequency-and-time.py'])
_VARS["window"].close()
break

elif _VARS["audioData"].size != 0:
try:
_VARS["window"]["-PROG-"].update(np.amax(_VARS["audioData"]))
Expand Down
68 changes: 68 additions & 0 deletions Home.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import PySimpleGUI as sg
import subprocess
import sys

# Create the layout for the landing page
AppFont = "Helvetica 16"
sg.theme("DarkTeal12")
sg.Sizer(800, 800)

# Define button styles
button_style = {"font": AppFont, "button_color": ("white", "#1c86ee"), "expand_x": True}

# Layout for the buttons
button_layout = [
[sg.Button("Amplitude-Frequency Visualizer", **button_style, pad=(10, 10))],
[sg.Button("Waveform", **button_style, pad=(10, 10))],
[sg.Button("Spectrogram", **button_style, pad=(10, 10))],
[sg.Button("Intensity vs Frequency and Time", **button_style, pad=(10, 10))],
[sg.Button("Real-Time VU Meter", **button_style, pad=(10, 10))], # New button for Triangle Wave
]

# Layout for the main landing page
layout = [
[sg.Text("Welcome to SoundScape", font=("Helvetica", 24), justification="center", pad=(0, 5), expand_x=True)],
[sg.Text("Explore various audio visualizers", font=("Helvetica", 14), justification="center", pad=(0, 5), expand_x=True)],
[sg.Multiline("SoundScape is an innovative application designed to transform audio data into stunning visualizations. "
"Choose from a variety of visualizers to unleash the power of audio visualizations!.",
font=("Helvetica", 14), justification="center", size=(50, 4), no_scrollbar=True, disabled=True, pad=(10, 10),
background_color="#e1f5fe", text_color="#006064", expand_x=True, expand_y=True)],
[sg.Column(button_layout, size=(390, 300), scrollable=True, vertical_scroll_only=True), sg.Image(filename='mediafiles/soundwaveimg.png', key='-IMAGE-', size=(390, 300))], # Add the PNG image here
[sg.Button("Exit", font=AppFont, button_color=("white", "red"), pad=(10, 10), expand_x=True)] # Adjusted padding
]

# Create the main window with a fixed size and responsive settings
window = sg.Window("Welcome to SoundScape", layout, finalize=True, element_justification="center", resizable=True, size=(800, 600))

# Function to close the current visualizer process
def close_current_visualizer(process):
if process and process.poll() is None:
process.kill()
process.wait()

# Main loop
current_visualizer_process = None

while True:
event, values = window.read(timeout=100) # Use a timeout to periodically check the process

if event in (sg.WIN_CLOSED, "Exit"):
close_current_visualizer(current_visualizer_process)
break

if event in ["Amplitude-Frequency Visualizer", "Waveform", "Spectrogram", "Intensity vs Frequency and Time","Real-Time VU Meter", "Sine Wave", "Square Wave", "Triangle Wave", "Sawtooth Wave"]:
close_current_visualizer(current_visualizer_process)

# Mapping event to corresponding script names
script_mapping = {
"Amplitude-Frequency Visualizer": "Amplitude-Frequency-Visualizer.py",
"Waveform": "Waveform.py",
"Spectrogram": "Spectrogram.py",
"Intensity vs Frequency and Time": "Intensity-vs-Frequency-and-time.py",
"Real-Time VU Meter": "Real-Time VU Meter.py", # Added button for "Triangle Wave"
}

script_name = script_mapping[event]
current_visualizer_process = subprocess.Popen([sys.executable, script_name])

window.close()
29 changes: 3 additions & 26 deletions Intensity-vs-Frequency-and-time.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,9 @@
AppFont = "Any 16"
sg.theme("DarkBlue3")

menu_layout = [
['Run Visualizers', ['Amplitude-Frequency-Visualizer', 'Waveform', 'Spectogram','Intensity-vs-Frequency-and-time']],
]

# Heatmap plot:
layout = [
[sg.Menu(menu_layout)],

[
sg.Graph(
canvas_size=(500, 500),
Expand Down Expand Up @@ -177,27 +174,7 @@ def compute_intensity_data(audio_data, window_size=1024, hop_size=512):
listen()
if event == "Stop":
stop()
if event == 'Amplitude-Frequency-Visualizer':
close_current_visualizer()
_VARS["current_visualizer_process"] = subprocess.Popen(['python', 'Amplitude-Frequency-Visualizer.py'])
_VARS["window"].close()
break
if event == 'Waveform':
close_current_visualizer()
_VARS["current_visualizer_process"] = subprocess.Popen(['python', 'Waveform.py'])
_VARS["window"].close()
break
if event == 'Spectogram':
close_current_visualizer()
_VARS["current_visualizer_process"] = subprocess.Popen(['python', 'Spectogram.py'])
_VARS["window"].close()
break
if event == 'Intensity-vs-Frequency-and-time':
close_current_visualizer()
_VARS["current_visualizer_process"] = subprocess.Popen(['python', 'Intensity-vs-Frequency-and-time.py'])
_VARS["window"].close()
break


# Along with the global audioData variable, this
# bit updates the waveform plot
elif _VARS["audioData"].size != 0:
Expand Down
Loading

0 comments on commit 70fe4b0

Please sign in to comment.