Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/lib/ksnd.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,3 +268,15 @@ KLYSAPI int KSND_GetPlayTime(KSong *song, int position)
{
return mus_get_playtime_at(&song->song, position);
}


KLYSAPI int KSND_TriggerInstrument(KPlayer *player, KSong *song, int instrument, int channel, int note, int panning)
{
return mus_trigger_instrument(player->mus, channel, &player->mus->instrument[instrument], note, panning);
}


KLYSAPI void KSND_ReleaseNote(KPlayer *player, int channel)
{
mus_release(player, channel);
}
2 changes: 2 additions & 0 deletions src/lib/ksnd.def
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ KSND_GetVUMeters
KSND_GetSongInfo
KSND_SetLooping
KSND_GetPlayTime
KSND_TriggerInstrument
KSND_ReleaseNote
46 changes: 33 additions & 13 deletions src/lib/ksnd.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ typedef struct KPlayer_t KPlayer;
/**
* Song information returned by KSND_GetSongInfo()
*/
typedef struct
typedef struct
{
char *song_title; /**< Song title as a null-terminated string */
char *instrument_name[128]; /**< Instrument names as an array */
Expand All @@ -37,14 +37,14 @@ typedef struct
} KSongInfo;


#ifdef WIN32
#ifdef WIN32
#ifdef DLLEXPORT
#define KLYSAPI _cdecl __declspec(dllexport)
#else
#define KLYSAPI
#define KLYSAPI
#endif
#else
#define KLYSAPI
#define KLYSAPI
#endif

/**
Expand Down Expand Up @@ -82,11 +82,11 @@ KLYSAPI extern int KSND_GetSongLength(const KSong *song);
* Get song information from a @c KSong.
*
* If @c NULL is passed as the @a data pointer, an internal, thread-unsafe buffer will
* be used to store the data. This internal buffer will also change every time this
* function is called, thus it is preferable to supply your own @c KSongInfo or
* be used to store the data. This internal buffer will also change every time this
* function is called, thus it is preferable to supply your own @c KSongInfo or
* otherwise copy the returned data before a new call.
*
* If @c song is freed using KSND_FreeSong(), the corresponding @c KSongInfo may be
* If @c song is freed using KSND_FreeSong(), the corresponding @c KSongInfo may be
* invalidated and point to unallocated memory.
*
* @param song @c KSong whose information is queried
Expand All @@ -97,13 +97,13 @@ KLYSAPI extern const KSongInfo * KSND_GetSongInfo(KSong *song, KSongInfo *data);

/**
* Returns the amount of milliseconds that would need to elapse if the song was played
* from the beginning to pattern row @a position.
* from the beginning to pattern row @a position.
*
* Use this in conjunction with KSND_GetPlayPosition() to find out the current playback
* Use this in conjunction with KSND_GetPlayPosition() to find out the current playback
* time. Or, use with KSND_GetSongLength() to get the song duration.
*
* @param song song whose play time is polled
* @param position
* @param position
* @return @c position measured in milliseconds
*/
KLYSAPI extern int KSND_GetPlayTime(KSong *song, int position);
Expand Down Expand Up @@ -171,7 +171,7 @@ KLYSAPI extern int KSND_FillBuffer(KPlayer *player, short int *buffer, int buffe
* Set player oversampling quality.
*
* Oversample range is [0..4]. 0 implies no oversampling and 4 implies 16-fold oversampling.
* The less oversampling the less CPU intensive the playback is but the sound quality will suffer
* The less oversampling the less CPU intensive the playback is but the sound quality will suffer
* for very high frequencies. Can be adjusted realtime.
*
* @param player @c KPlayer context
Expand All @@ -191,8 +191,8 @@ KLYSAPI extern void KSND_SetVolume(KPlayer *player, int volume);
* Enable or disable song looping.
*
* If a non-zero value is passed via @c looping, the playback routine will exit KSND_FillBuffer()
* if it encounters the song end. This is useful if you want to detect song end and avoid extra
* audio data in the buffer after the song end.
* if it encounters the song end. This is useful if you want to detect song end and avoid extra
* audio data in the buffer after the song end.
*
* @param player player context
* @param looping looping enabled
Expand All @@ -218,6 +218,26 @@ KLYSAPI extern int KSND_GetPlayPosition(KPlayer* player);
*/
KLYSAPI extern void KSND_GetVUMeters(KPlayer *player, int *envelope, int n_channels);

/**
* Trigger an instrument from the song manually. When using this the song file itself sets the number of channels, play rate et cetera
* @param player player context which is currently playing a song set with KSND_PlaySong()
* @param song song which has the instruments and which should currently be playing
* @param instrument the instrument index in the song
* @param channel channel on which the instrument should be triggered on (use -1 to autochoose)
* @param note The note at which the instrument is played. This is a 16-bit value with the semitone in the higher 8 bits and fraction in the lower bits
* @param panning stereo panning for the instrument (zero is center)
* @return the channel on which the instrument should now be playing
*/
KLYSAPI int KSND_TriggerInstrument(KPlayer *player, KSong *song, int instrument, int channel, int note, int panning);

/**
* Release the currently played note
*
* @param player player context which is currently playing a song set with KSND_PlaySong()
* @param channel release the note played on this channel
*/
KLYSAPI void KSND_ReleaseNote(KPlayer *player, int channel);

#ifdef __cplusplus
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ OTHER DEALINGS IN THE SOFTWARE.
block;\
}

#define VER_READ(file_version, first_version, last_version, var, size) VER(file_version, first_version, last_version, SDL_RWread(ctx, var, size == 0 ? sizeof(*var) : size, 1));
#define VER_READ(file_version, first_version, last_version, var, size) VER(file_version, first_version, last_version, my_RWread(ctx, var, size == 0 ? sizeof(*var) : size, 1));
#define _VER_READ(x, size) VER_READ(version, 0, MUS_VERSION, x, size)
#define _VER_WRITE(x, size) fwrite(x, !size ? sizeof(*x) : size, 1, f)

Expand Down