View Single Post
AdRiAnIlloO
Member
Join Date: Jul 2015
Location: Spain
Old 11-08-2021 , 11:11   Re: [EXTENSION] Sound Info Library v1.0.1
Reply With Quote #95

Quote:
Originally Posted by MAGNAT2645 View Post
Hi. Can you please also implement methodmap natives (in the extension) from this?
Code:
methodmap SoundFile < Handle {
    /**
    * Opens a sound file.
    *
    * @note Sound files are closed with CloseHandle().
    *
    * @param file                File to open
    * @param relativeToSound     if true, it is relative to the sound directory, otherwise you have to build the path yourself
    * @return                    A Handle to the sound file, null on open error.
    */
    public SoundFile(const char[] file, bool relativeToSound=true) { return view_as< SoundFile >( OpenSoundFile( file, relativeToSound ) ); }

    /**
    * Gets the length of the sound file in seconds
    *
    * @return                    The song length in seconds
    */
    property int Length {
        public get() { return GetSoundLength( this ); }
    }

    /**
    * Gets the length of the sound file in seconds as float.
    * Note: this probably won't work with some VBR encoded mp3's
    *
    * @return                    The song length in seconds as float
    */
    property float LengthFloat {
        public get() { return GetSoundLengthFloat( this ); }
    }

    /**
    * Get the Bit rate of sound (kbps)
    *
    * @return                    Sound bitrate (cell)
    */
    property int BitRate {
         public get() { return GetSoundBitRate( this ); }
    }

    /**
    * Get the Sampling rate of sound (hz)
    *
    * @return                    Sampling rate (cell)
    */
    property int SamplingRate {
        public get() { return GetSoundSamplingRate( this ); }
    }

    /**
    * Get the Artist of the sound
    *
    * @param buffer              Buffer to use for storing the string.
    * @param maxlength           Maximum length of the buffer.
    * @return                    Length of string written to buffer.
    */
    public int GetArtist(char[] buffer, int maxlength) { return GetSoundArtist( this, buffer, maxlength ); }

    /**
    * Get the Track title of sound
    *
    * @param buffer              Buffer to use for storing the string.
    * @param maxlength           Maximum length of the buffer.
    * @return                    Length of string written to buffer.
    */
    public int GetTitle(char[] buffer, int maxlength) { return GetSoundTitle( this, buffer, maxlength ); }

    /**
    * Get the Track number of the sound
    *
    * @return                    Sound number (cell)
    */
    property int Number {
        public get() { return GetSoundNum( this ); }
    }

    /**
    * Get the Album of the sound
    *
    * @param buffer              Buffer to use for storing the string.
    * @param maxlength           Maximum length of the buffer.
    * @return                    Length of string written to buffer.
    */
    public int GetAlbum(char[] buffer, int maxlength) { return GetSoundAlbum( this, buffer, maxlength ); }

    /**
    * Get the Year of sound
    *
    * @return                    Sound year (cell)
    */
    property int Year {
        public get() { return GetSoundYear( this ); }
    }

    /**
    * Get the Comment of the sound
    *
    * @param buffer              Buffer to use for storing the string.
    * @param maxlength           Maximum length of the buffer.
    * @return                    Length of string written to buffer.
    */
    public int GetComment(char[] buffer, int maxlength) { return GetSoundComment( this, buffer, maxlength ); }

    /**
    * Get the Genre of the sound
    *
    * @param buffer              Buffer to use for storing the string.
    * @param maxlength           Maximum length of the buffer.
    * @return                    Length of string written to buffer.
    */
    public int GetGenre(char[] buffer, int maxlength) { return GetSoundGenre( this, buffer, maxlength ); }
};
So it doesn't have to be a wrapper.
Done: https://github.com/Adrianilloo/sound...e/soundlib.inc

Thanks for your contribution.

Sample output from working methodmap based API:

Code:
sm plugins reload soundlib_demo
[SM] Plugin soundlib test reloaded successfully.
sm_soundinfo 02 CP Violation.mp3
Song Info 02 CP Violation.mp3
Sound Length: 105
Sound Length (float): 105.508575
Birate: 320
Sampling Rate: 44100
Artist: Valve
Title: CP Violation
Num 2
Album: The Soundtrack of Half-Life 2
Year: 2004
Comment: 0
Genre: Soundtrack
If you're going to test sounds from VPKs (and/or additional search paths), or just my upgraded extension in general, let me know how it goes (whether you find any issue etc.).

[+General info: I recently added support to SaySounds plugin (which uses SoundLib) with required edits to support VPK / search path reading as well, which requires my edited SoundLib: https://github.com/Gh0sty/SaysoundsHE]

Last edited by AdRiAnIlloO; 11-08-2021 at 11:20.
AdRiAnIlloO is offline