Skip to content

Commit 56bc0f0

Browse files
Merge pull request #31 from gituser12981u2/v0.4.0
V0.4.0
2 parents 66e8eb5 + 2984b25 commit 56bc0f0

10 files changed

Lines changed: 461 additions & 112 deletions

CONTRIBUTING.md

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
## Contributing
2+
3+
Contribution to are welcome! Here's how you can help.
4+
5+
## Getting Started
6+
7+
1. Fork the repository.
8+
2. Create a new branch(`git checkout -b feature-branch`).
9+
3. Commit changes(`git commit -am 'Add new feature'`)
10+
4. Push to the branch(`git push origin feature-branch`)..
11+
5. Create a new Pull Request.
12+
13+
## Linting and Formatting
14+
15+
Before submitting a pull request, please ensure that any updates adhere to the project's style guidelines:
16+
17+
### Using Flake8 for Linting
18+
19+
- Run flake8 to check for linting issues:
20+
```bash
21+
flake8 audio_visualizer tests
22+
```
23+
24+
- Run autopep8 to format the code to flake8 standards
25+
26+
```bash
27+
autopep8 --in-place --aggressive --aggressive audio_visualizer tests
28+
```
29+
**Note**: that autopep8 doesn't work 100% so some manual formatting may be necessary
30+
31+
### Setting up Pre-Commit Hooks
32+
33+
One can also set up a pre-commit hook to automate these checks:
34+
35+
1. Install pre-commit:
36+
```bash
37+
pip install pre-commit
38+
```
39+
40+
2. Create a .pre-commit-config.yaml file with the following content:
41+
```yaml
42+
repos:
43+
- repo: https://github.com/pre-commit/mirrors-autopep8
44+
rev: v1.5.7
45+
hooks:
46+
- id: autopep8
47+
args: [--aggressive, --aggressive]
48+
49+
- repo: https://gitlab.com/pycqa/flake8
50+
rev: 3.9.2
51+
hooks:
52+
- id: flake8
53+
```
54+
55+
3. Install the pre-commit hooks:
56+
```bash
57+
pre-commit install
58+
```
59+
60+
This will ensure that autopep8 and flake8 run automatically before each commit.
61+
62+
## Testing and CI/CD Integration
63+
64+
Please ensure contributions pass the automated tests which can be run locally using the following command:
65+
66+
```bash
67+
xvfb-run --auto-servernum python -m unittest discover tests
68+
```
69+
70+
**Note**: xvfb is a linux program and can these tests must be passed on a linux distribution--though this project is for macOS and Windows too, linux is the only one tested due to audio loop back issues with the former.
71+
72+
The continuous integration (CI) process also includes linting with flake8, so check for linting issues before pushing
73+
74+
```bash
75+
flake8 audio_visualizer tests
76+
```
77+
78+
For more details on the CI/CD processes, ses the `.github/workflows/ci.yml` file
79+
80+
## Code Style and Documentation
81+
82+
The code must adhere to the Google style for docstring in this codebase. Please ensure that all public classes and functions include doctrings that follow this format:
83+
84+
```python
85+
class ClassName:
86+
"""
87+
Short description.
88+
89+
Attributes:
90+
attribute1 (type): Description
91+
attribute2 (type): Description
92+
...
93+
"""
94+
95+
def Method(args):
96+
"""
97+
method_name: Description
98+
99+
Args:
100+
arg1 (type): Description
101+
arg2 (type): Description
102+
...
103+
104+
Returns:
105+
return1 (type): description
106+
return2 (type): description
107+
"""
108+
```
109+
110+
## Using the Issue and Feature Templates
111+
112+
For reporting bugs or requesting new features, please use the predefined templates, or use a custom one if your communication does not fit any template. This ensures that all necessary information is provided and helps to address issues and enhancements efficiently.
113+

README.md

Lines changed: 28 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ A simple, janky, yet charming terminal-based audio visualizer written in Python.
66

77
- Visualize audio data in vertical or horizontal bar charts.
88
- Adjustable parameters such as smoothing factor, buffer size, sampling rate, and number of bars.
9+
- Theme support for customizing the visual output.
910
- Works on Linux, macOS, and Windows.
1011
- Works best in VSC terminal, iterm2, kitty, and alacritty.
1112

@@ -22,6 +23,7 @@ A simple, janky, yet charming terminal-based audio visualizer written in Python.
2223
```bash
2324
sudo apt-get update
2425
```
26+
2527
```bash
2628
sudo apt-get install -y portaudio19-dev
2729
```
@@ -55,6 +57,7 @@ Download and install the PortAudio library from [here](https://files.portaudio.c
5557
```bash
5658
python3 -m venv .venv
5759
```
60+
5861
```bash
5962
source .venv/bin/activate
6063
# On Windows, use '.venv\Scripts\activate'
@@ -65,6 +68,7 @@ Download and install the PortAudio library from [here](https://files.portaudio.c
6568
```bash
6669
pip install -r requirements.txt
6770
```
71+
6872
```bash
6973
pip install .
7074
```
@@ -93,15 +97,32 @@ audio-visualizer --mode horizontal-ltr
9397

9498
**Note**: there are two horizontal modes. One that draws bars from left to right (ltr) and one that draws bars from right to left (rtl)
9599

100+
### Configuration File
101+
102+
Modify `config.lua` to change default settings and key bindings. This file controls various aspects of the Audio Visualizer's behavior, including the visual mode, hotkeys, and audio processing parameters.
103+
104+
#### Config File Location
105+
106+
- **Linux/macOS**: Place your `config.lua` in `~/.config/audio_visualizer/`. This is teh recommended location as it follwos the standard configuration directory structure on Unix-like systems.
107+
- **Windows**: Place your `config.lua` in `%APPDATA%\audio-visualizer\`. This location is recommended for Windows users as it aligns with the typical application data storage.
108+
109+
If a `config.lua` file is not found in these locations, the program will attempt to load it from the directory where the `audio-visualizer` command is executed.
110+
96111
### Hotkey mode switcher
97112
98-
Switch to a different view--mode--while already in a visualization.
113+
Switch visualization modes dynamically with configured hotkeys.
114+
For example, the default keybindings are:
99115
100-
While running a mode, press **'ctrl+l'** to switch to horizontal ltr mode, **'ctrl+r'** to switch to horizontal rtl mode, or **'ctrl+v'** to switch to vertical mode.
116+
- 'ctrl+h': horizontal ltr mode
117+
- 'ctrl+l': horizontal rtl mode
118+
- 'ctrl+j': vertical mode
101119
102-
-'ctrl+l': horizontal ltr mode
103-
-'ctrl+r': horizontal rtl mode
104-
-'ctrl+v': vertical mode
120+
### Themes
121+
122+
Themes allow you to customize the visual appearance of the audio visualizer:
123+
124+
- **background_color**: Set to a 'RGB' value like '255;0;0' for red, or 'default to use the terminal's default color.
125+
- **bar_color**: Set to a 'RGB' value or 'default' to use the terminal's default color.
105126

106127
### Command Line Options
107128

@@ -127,64 +148,12 @@ On Windows, audio routing can be tricky. If you want to visualize audio from you
127148
128149
This will allow for the program to render the audio that is being outputted on the device as well as continue to have the user be able to hear the same audio.
129150
130-
## Contributing
131-
132-
1. Fork the repository.
133-
2. Create a new branch(`git checkout -b feature-branch`).
134-
3. Commit your changes(`git commit -am 'Add new feature'`)
135-
4. Push to the branch(`git push origin feature-branch`)..
136-
5. Create a new Pull Request.
137-
138-
### Linting and Formatting
139-
140-
Please ensure that any updates adhere to the project's style guidelines before committing.
141-
142-
- Run flake8 to check for linting issues:
143-
```bash
144-
flake8 audio_visualizer tests audio_capture.py horizontal_visualizer.py vertical_visualizer.py visualizer.py
145-
```
146-
147-
- Run autopep8 to format the code to flake8 standards
148-
- Note that autopep8 doesn't work 100% so some manual formatting may be necessary
149-
150-
```bash
151-
autopep8 --in-place --aggressive --aggressive audio_visualizer tests audio_capture.py horizontal_visualizer.py vertical_visualizer.py visualizer.py
152-
```
153-
154-
One can also set up a pre-commit hook to automate these checks:
155-
156-
1. Install pre-commit:
157-
```bash
158-
pip install pre-commit
159-
```
160-
161-
2. Create a .pre-commit-config.yaml file with the following content:
162-
```yaml
163-
repos:
164-
- repo: https://github.com/pre-commit/mirrors-autopep8
165-
rev: v1.5.7
166-
hooks:
167-
- id: autopep8
168-
args: [--aggressive, --aggressive]
169-
170-
- repo: https://gitlab.com/pycqa/flake8
171-
rev: 3.9.2
172-
hooks:
173-
- id: flake8
174-
```
175-
176-
3. Install the pre-commit hooks:
177-
```bash
178-
pre-commit install
179-
```
180-
181-
This will ensure that autopep8 and flake8 run automatically before each commit.
182-
183151
## License
184152
185153
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
186154
187155
## Contributors
156+
188157
Thank you to the follow people for their contributions to this project:
189158
190-
-[@ohksith](https://github.com/ohksith) - Provided fix for the terminal to clean it self after visualization stopped
159+
-[@ohksith](https://github.com/ohksith) - Provided fix for the terminal to clean it self after visualization stopped

audio_visualizer/__init__.py

Lines changed: 69 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
import argparse
33
import logging
44
import time
5+
import os
6+
from sys import platform
7+
from lupa import LuaRuntime
8+
59

610
# Configure logging
711
logging.basicConfig(level=logging.DEBUG,
@@ -11,32 +15,91 @@
1115
])
1216

1317

18+
def load_config():
19+
"""
20+
Dynamically loads configuration settings from a Lua file
21+
based on the operating system.
22+
The function checks common configuration directories on
23+
Linux, macOS, and Windows.
24+
25+
Returns:
26+
dict: A dictionary containing configuration settings loaded
27+
from the Lua file.
28+
"""
29+
config_filename = "config.lua"
30+
paths = []
31+
if platform == "linux" or platform == "linux2" or platform == "darwin":
32+
# Unix-like systems: look in the user's home directory config folder
33+
paths.append(os.path.join(os.getenv("HOME"), ".config",
34+
"audio_visualizer", config_filename))
35+
elif platform == "win32":
36+
# Windows: look in AppData folder
37+
paths.append(os.path.join(os.getenv("APPDATA"),
38+
"audio_visualizer", config_filename))
39+
40+
# Check the current directory last
41+
paths.append(os.path.join(os.getcwd(), config_filename))
42+
43+
# Try each path in sequence
44+
for path in paths:
45+
if os.path.exists(path):
46+
with open(path, 'r') as file:
47+
lua = LuaRuntime(unpack_returned_tuples=True)
48+
config_script = file.read()
49+
return lua.execute(config_script)
50+
51+
# If no config file is found, log the error and return default settings
52+
logging.warning(f"No configuration file found in expected locations: {
53+
paths}. Using default settings.")
54+
return {
55+
'key_binds': {
56+
'modifier_key': 'ctrl',
57+
'keys': {
58+
'v': 'vertical',
59+
'l': 'horizontal-ltr',
60+
'r': 'horizontal-rtl'
61+
}
62+
},
63+
'settings': {
64+
'default_mode': 'vertical',
65+
'alpha': 0.4,
66+
'chunk_size': 2048,
67+
'sample_rate': 44100
68+
},
69+
'themes': {
70+
'background_color': 'default', # RGB for black
71+
'bar_color': 'default' # RGB for white
72+
}
73+
}
74+
75+
1476
def main():
1577
"""Entry point for the audio visualizer command line interface."""
78+
config = load_config()
1679

1780
parser = argparse.ArgumentParser(description="Terminal Audio Visualizer")
1881
parser.add_argument(
1982
"--mode",
2083
choices=["vertical", "horizontal-ltr", "horizontal-rtl"],
21-
default="vertical",
84+
default=config['settings']['default_mode'],
2285
help="Choose visualization mode: vertical or horizontal",
2386
)
2487
parser.add_argument(
2588
"--alpha",
2689
type=float,
27-
default=0.4,
90+
default=config['settings']['alpha'],
2891
help="Smoothing factor for FFT; default is 0.4.",
2992
)
3093
parser.add_argument(
3194
"--chunk",
3295
type=int,
33-
default=2048,
96+
default=config['settings']['chunk_size'],
3497
help="Number of frames per buffer; default is 2048",
3598
)
3699
parser.add_argument(
37100
"--rate",
38101
type=int,
39-
default=44100,
102+
default=config['settings']['sample_rate'],
40103
help="Sampling rate; default is 44100",
41104
)
42105
args = parser.parse_args()
@@ -46,6 +109,8 @@ def main():
46109
alpha=args.alpha,
47110
chunk=args.chunk,
48111
rate=args.rate,
112+
config=config['key_binds'],
113+
theme=config['themes']
49114
)
50115
visualizer.start()
51116

0 commit comments

Comments
 (0)