-
Notifications
You must be signed in to change notification settings - Fork 108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Several changes, basis for discussion #18
Conversation
In new-style classes the base class __setattr__() has to be called instead of inserting the value into self.__dict__. See http://docs.python.org/2/reference/datamodel.html#customizing-attribute-access
Moving 'mode' right after 'name' and 'format' after 'subtype' and 'endian'. This way most situations can be handled with positional arguments only, e.g.: f1 = SoundFile('file1.wav') f2 = SoundFile('file2.wav', 'rw') f3 = SoundFile('file3.wav', 'w', 48000, 1, sf.PCM_24)
... and set default channels=None
Also, use named constants similar to the ones used in libsndfile (but underscore-prefixed to not clutter the module namespace).
... and a module-level function get_format_info()
This is just an idea about how to retrieve meaningful strings for format codes etc. Most likely there are much better methods!
Also, the quite explicit name _add_formats_to_module_namespace() should now explain what's going on.
This is relevant for tools that do instrospection, e.g. for auto-completion in IDEs.
There is now a much better (= cleaner and faster) solution involving FormatType, SubtypeType and EndianType.
@bastibe: If you want, you can cherry-pick the following commits (in the given order they should apply cleanly): 0d0f47f For the following commits I'll add some documentation and then do a new pull request: 2948783 These didn't apply cleanly, I'll also create a new pull request e35911c (is These are a little messy, I'll create a new pull request for these: 2833332 And these are garbage: |
I'd like to put a few names up for discussion ... please tell me if any of them can be improved ... The components of file types are now described by The name I'm also not sure about The class attributes The internal name And there is a little discrepancy between I invented a little helper function EDIT: In 3abdaf1 I changed this to
... I'm not sure if that's better ... |
Regarding 2572742: I just realized that Probably we should also accept Also And Also, the order of the characters seems to be arbitrary ... so this should be also handled by PySoundFile. All in all, the situation is much more complicated than I initially thought. See also #19. |
Here's an idea: How about using the binary modes for raw input/output? That actually makes some kind of sense. |
That's an interesting idea, but I fail to see how this makes sense ... can you please elaborate? What do you mean by "raw"? |
Special treatment for modes 'w' and 'r+'.
OK, I think I now get what you mean with "raw". I don't think the Another confusing aspect is that the "normal" read/write function use frames, and the raw functions use bytes, therefore I wouldn't recommend putting the functionality into the same function. I guess it would be better to make new methods |
Mostly PCM_16, as supported according to the table at http://www.mega-nerd.com/libsndfile/
The functions should probably be called Also, the parameter should probably still be a NumPy array ...? And And finally, I'm having a really hard time imagining a use case for this ... |
|
I created an issue for that: #25. BTW, I think the overhead caused by NumPy (using Anyway, I don't see a reason why not to provide this feature. |
This commit holds several changes which were discussed in #22 (which was itself based on #18). Change handling of file formats: File formats are handled as three simple strings: format, subtype and endian. Add "which" argument to seek(). This is needed because the combination with logical or (e.g. SEEK_SET | READ) isn't possible with string formats. Update frames counter on write(). Hide all non-API names in module namespace (by prefixing _). This is relevant for tools that do introspection, e.g. for auto-completion in IDEs. Support sf_open_fd(), remove obsolete argument virtual_io The first constructor argument can now be: - a string (path to a file) - an int (a file descriptor) - a file-like object The argument virtual_io is not needed, because this can be detected automatically. Closes #19 Get file extension from 'name' attribute of a file-like object. Change public attributes of SoundFile class to properties. Add 'name' property. Add properties 'format_info' and 'subtype_info'. Proper handling of dtype's in read() and write(). Add function default_subtype().
This commit holds several changes which were discussed in #22 (which was itself based on #18). Change handling of file formats: File formats are handled as three simple strings: format, subtype and endian. Add "which" argument to seek(). This is needed because the combination with logical or (e.g. SEEK_SET | READ) isn't possible with string formats. Update frames counter on write(). Hide all non-API names in module namespace (by prefixing _). This is relevant for tools that do introspection, e.g. for auto-completion in IDEs. Support sf_open_fd(), remove obsolete argument virtual_io The first constructor argument can now be: - a string (path to a file) - an int (a file descriptor) - a file-like object The argument virtual_io is not needed, because this can be detected automatically. Closes #19 Get file extension from 'name' attribute of a file-like object. Change public attributes of SoundFile class to properties. Add 'name' property. Add properties 'format_info' and 'subtype_info'. Proper handling of dtype's in read() and write(). Add function default_subtype().
WARNING: this pull request is not meant to be merged as is!
It is rather meant as a basis for discussion and a proof-of-concept of some ideas, but for many things improvements are needed.
Documentation is lacking for most of the new features.
In-between new features, there are also a few minor bugfixes which can be cherry-picked if desired.
Some of the commits became obsolete because of following commits.
e.g. the function
decode_number()
(d72075f) is not needed anymore because the specialized types introduced in d31a484 provide a much better solution to the problem.With that, most changes from 2833332 became obsolete, too.
If desired, I can provide individual pull requests for certain features (I can also add documentation, where lacking).