From 6bea457977265928434671cab364b05140dad555 Mon Sep 17 00:00:00 2001 From: Michael Fairley Date: Thu, 7 Sep 2017 12:09:25 -0500 Subject: [PATCH 1/3] Add Mac OS travis build --- .travis.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 630a0eef..2150a75a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,9 @@ rust: - beta - nightly - stable +os: +- linux +- osx install: - wget https://www.libsdl.org/release/SDL2-2.0.5.tar.gz -O sdl2.tar.gz - tar xzf sdl2.tar.gz @@ -24,7 +27,8 @@ install: before_script: - | pip install 'travis-cargo<0.2' --user && - export PATH=$HOME/.local/bin:$PATH + export PATH=$HOME/.local/bin:$PATH && + export PATH=~/Library/Python/2.7/bin:$PATH script: - | travis-cargo build -- --features "gfx image ttf mixer" && From b52bd54463236818304d18ec84fac9024078f2c0 Mon Sep 17 00:00:00 2001 From: Flaise Date: Sun, 10 Sep 2017 17:40:11 -0500 Subject: [PATCH 2/3] Add Music::from_bytes() function (#704) --- changelog.md | 5 +++++ src/sdl2/mixer/mod.rs | 26 ++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/changelog.md b/changelog.md index 173414cd..ee2a40a9 100644 --- a/changelog.md +++ b/changelog.md @@ -18,6 +18,11 @@ breaking exisitng code too much. * Adds the `unsafe_textures` feature to this crate, allowing to get rid of the lifetimes in `Texture`s in the `render` module. +[PR #704](https://github.com/Rust-SDL2/rust-sdl2/pull/704) + +* Adds the `Music::from_static_bytes` function, which creates a Music instance with the +static lifetime from a buffer that also has a static lifetime. + ### v0.30 Re-exported sdl2\_sys as sdl2::sys diff --git a/src/sdl2/mixer/mod.rs b/src/sdl2/mixer/mod.rs index a85f9c29..481dee09 100644 --- a/src/sdl2/mixer/mod.rs +++ b/src/sdl2/mixer/mod.rs @@ -1,7 +1,7 @@ //! //! A binding for the library `SDL2_mixer` //! -//! +//! //! Note that you need to build with the //! feature `mixer` for this module to be enabled, //! like so: @@ -27,7 +27,7 @@ use std::ffi::{CString, CStr}; use std::str::from_utf8; use std::borrow::ToOwned; use std::path::Path; -use libc::{c_int, uint16_t, c_double, c_uint}; +use libc::{c_int, uint16_t, c_double, c_uint, c_void}; use ::get_error; use ::rwops::RWops; use ::version::Version; @@ -790,6 +790,28 @@ impl<'a> Music<'a> { } } + /// Load music from a static byte buffer. + pub fn from_static_bytes(buf: &'static [u8]) -> Result, String> { + let rw = unsafe { + ::sys::rwops::SDL_RWFromConstMem(buf.as_ptr() as *const c_void, buf.len() as c_int) + }; + + if rw.is_null() { + return Err(get_error()); + } + + let raw = unsafe { ffi::Mix_LoadMUS_RW(rw, 0) }; + if raw.is_null() { + Err(get_error()) + } else { + Ok(Music { + raw: raw, + owned: true, + _marker: PhantomData, + }) + } + } + /// The file format encoding of the music. pub fn get_type(&self) -> MusicType { let ret = unsafe { ffi::Mix_GetMusicType(self.raw) as i32 } as c_uint; From 0f44d4359586e30e2d1f01de65cd2340120874f1 Mon Sep 17 00:00:00 2001 From: Joshua Erney Date: Thu, 21 Sep 2017 11:33:06 -0500 Subject: [PATCH 3/3] Fix floating-point literal used in pattern in example (#705) --- examples/audio-squarewave.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/examples/audio-squarewave.rs b/examples/audio-squarewave.rs index ce518668..4c62d1eb 100644 --- a/examples/audio-squarewave.rs +++ b/examples/audio-squarewave.rs @@ -15,10 +15,7 @@ impl AudioCallback for SquareWave { fn callback(&mut self, out: &mut [f32]) { // Generate a square wave for x in out.iter_mut() { - *x = match self.phase { - 0.0...0.5 => self.volume, - _ => -self.volume - }; + *x = if self.phase < 0.5 { self.volume } else { -self.volume }; self.phase = (self.phase + self.phase_inc) % 1.0; } }