AndreMiras / pycaw

Python Core Audio Windows Library
MIT License
385 stars 67 forks source link

Reorganize / Split the pycaw.pycaw file in modules and subpackages. #38

Closed TurboAnonym closed 3 years ago

TurboAnonym commented 3 years ago

Split up!

I have much more to contribute besides the already added audio session notification. But before that, the code needs to be split up properly otherwise it all gets too cluttered.

i divided the pycaw.pycaw.py file after following pattern:

pycaw/
├─ api/ (contains all com calls)
│  ├─ header name: like audiopolicy(.h)/
│  │  ├─ __init__.py (only com methods that are linked to audiopolicy.h)
│  │  ├─ depend.py (structures / dependencies for the com methods)
│  ├─ audioclient/
│  │  ├─ depend.py
│  │  ├─ __init__.py
│  ├─ __init__.py (empty)
├─ module1.py (location for new modules)
├─ constants.py (which are used in utils.py)
├─ utils.py (wrappers like AudioDevice, AudioSession, AudioUtilities)
├─ pycaw.py (imports everything for backwards compatibility)
├─ __init__.py (empty)

I did not add any new Features (yet)

... so it should be easy to understand and follow the split.

Its relativly easy to check if i did everything correct, by copy and pasting everything again.

when you do this you might find REFERENCE_TIME and UINT32 missing, but i renamed them on import: pycaw\api\audioclient__init__.py

... but i sure made everything work as expected. Here is the test output:

(env) C:\############\Desktop\pycaw2>python -m unittest discover
.......
----------------------------------------------------------------------
Ran 7 tests in 0.244s

OK

volume.GetVolumeRange()' expected output has been adjusted on my computer to (-96.0, 0.0, 1.5) instead of (-95.25, 0.0, 0.75)

Imports from one module to another and external libraries

I added in the first step for each newly created module all possible imports, and removed the unused later with: autoflake --remove-all-unused-imports (not in place, but with manual double checking) So each module has the minimum amount of imports.

AndreMiras commented 3 years ago

Nice well done :clap: I missed that PR and now it conflicts with a PR I merged today. Do you mind solving the conflict and squashing everything to a single commit so I can merge?

TurboAnonym commented 3 years ago

Haha all that git stuff took me some time to figure out ;) Finally it worked 😁