1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
// The MIT License (MIT)
//
// Copyright (c) 2013 Jeremy Letang (letang.jeremy@gmail.com)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
// the Software, and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

//! Play Music easily.

use std::thread::sleep;
use std::mem;
use std::thread;
use std::time::Duration;
use libc::c_void;
use std::vec::Vec;
use std::sync::mpsc::{channel, Sender, Receiver};

use internal::OpenAlData;
use openal::{ffi, al};
use sndfile::{SndInfo, SndFile};
use sndfile::OpenMode::Read;
use sndfile::SeekMode::SeekSet;
use states::State;
use states::State::{Initial, Playing, Paused, Stopped};
use audio_controller::AudioController;
use audio_tags::{Tags, AudioTags, get_sound_tags};

/**
 * Play Music easily.
 *
 * Simple class to play music easily in 2 lines.
 *
 * Music is played in their own task and the samples are loaded progressively
 * using circular buffers.
 * They aren't associated to a SoundData like Sounds.
 *
 * # Examples
 * ```no_run
 * extern crate ears;
 * use ears::{Music, AudioController};
 *
 * fn main() -> () {
 *   let mut msc = Music::new("path/to/music.flac").unwrap();
 *   msc.play();
 * }
 * ```
 */
pub struct Music {
    /// The internal OpenAL source identifier
    al_source: u32,
    /// The internal OpenAL buffers
    al_buffers: [u32; 2],
    /// The file open with libmscfile
    file: Option<Box<SndFile>>,
    /// Information of the file
    file_infos: SndInfo,
    /// Quantity of sample to read each time
    sample_to_read: i32,
    /// Format of the sample
    sample_format: i32,
    /// Audio tags
    sound_tags: Tags,

    is_looping: bool,
    /// Channel to tell the thread, if is_looping changed
    looping_sender: Option<Sender<bool>>,

    /// Thread which streams the music file
    thread_handle: Option<thread::JoinHandle<()>>,
}

impl Music {
    /**
     * Create a new Music
     *
     * # Argument
     * * `path` - The path of the file to load the music
     *
     * # Return
     * An Option containing Some(Music) on success, None otherwise
     */
    pub fn new(path: &str) -> Option<Music> {
        // Check that OpenAL is launched
        check_openal_context!(None);
        // Retrieve File and Music datas
        let file = match SndFile::new(path, Read) {
            Ok(file)    => Box::new(file),
            Err(err)    => { println!("{}", err); return None; }
        };
        let infos = file.get_sndinfo();

        // create the source and the buffers
        let mut source_id = 0;
        let mut buffer_ids = [0; 2];
        // create the source
        al::alGenSources(1, &mut source_id);
        // create the buffers
        al::alGenBuffers(2, &mut buffer_ids[0]);

        // Retrieve format informations
        let format =  match al::get_channels_format(infos.channels) {
            Some(fmt) => fmt,
            None => {
                println!("internal error : unrecognized format.");
                return None;
            }
        };

        // Check if there is OpenAL internal error
        match al::openal_has_error() {
            Some(err) => { println!("{}", err); return None; },
            None => {}
        };

        let sound_tags = get_sound_tags(&*file);

        Some(Music {
            al_source: source_id,
            al_buffers: buffer_ids,
            file: Some(file),
            file_infos: infos,
            sample_to_read: 50000,
            sample_format: format,
            sound_tags: sound_tags,
            is_looping: false,
            looping_sender: None,
            thread_handle: None,
        })
    }

    fn process_music(&mut self) -> () {
        let (chan, port) = channel();
        let sample_t_r = self.sample_to_read;
        let sample_rate = self.file_infos.samplerate;
        let sample_format = self.sample_format;
        let al_source = self.al_source;
        let al_buffers = self.al_buffers;

        // create buff
        let mut samples = vec![0i16; sample_t_r as usize];// as u32, 0i16);

        // full buff1
        let mut len = mem::size_of::<i16>() *
            self.file.as_mut().unwrap().read_i16(&mut samples[..], sample_t_r as i64) as usize;
        al::alBufferData(al_buffers[0],
                         sample_format,
                         samples.as_ptr() as *mut c_void,
                         len as i32,
                         sample_rate);

        // full buff2
        samples.clear();
        len = mem::size_of::<i16>() *
            self.file.as_mut().unwrap().read_i16(&mut samples[..], sample_t_r as i64) as usize;
        al::alBufferData(al_buffers[1],
                         sample_format,
                         samples.as_ptr() as *mut c_void,
                         len as i32,
                         sample_rate);

        // Queue the buffers
        al::alSourceQueueBuffers(al_source, 2, &al_buffers[0]);

        // Launche the Music
        al::alSourcePlay(al_source);

        let (looping_sender, looping_receiver): (Sender<bool>, Receiver<bool>) = channel();
        self.looping_sender = Some(looping_sender);
        let is_looping_clone = self.is_looping.clone();

        self.thread_handle = Some(thread::spawn(move|| {
            match OpenAlData::check_al_context() {
                Ok(_)       => {},
                Err(err)    => { println!("{}", err);}
            };
            let mut file : SndFile = port.recv().ok().unwrap();
            let mut samples = vec![0i16; sample_t_r as usize];
            let mut status = ffi::AL_PLAYING;
            let mut i = 0;
            let mut buf = 0;
            let mut is_looping = is_looping_clone;

            while status != ffi::AL_STOPPED {
                // wait a bit
                sleep(Duration::from_millis(50));
                if status == ffi::AL_PLAYING {
                    if let Ok(new_is_looping) = looping_receiver.try_recv() {
                        is_looping = new_is_looping;
                    }
                    al::alGetSourcei(al_source,
                                     ffi::AL_BUFFERS_PROCESSED,
                                     &mut i);
                    if i != 0 {
                        samples.clear();
                        al::alSourceUnqueueBuffers(al_source, 1, &mut buf);
                        let mut read = file.read_i16(&mut samples[..], sample_t_r as i64) *
                                       mem::size_of::<i16>() as i64;
                        if is_looping && read == 0 {
                            file.seek(0, SeekSet);
                            read = file.read_i16(&mut samples[..], sample_t_r as i64) *
                                   mem::size_of::<i16>() as i64;
                        }
                        al::alBufferData(buf,
                                         sample_format,
                                         samples.as_ptr() as *mut c_void,
                                         read as i32,
                                         sample_rate);
                        al::alSourceQueueBuffers(al_source, 1, &buf);
                    }
                }
                // Get source status
                status = al::alGetState(al_source);
            }
            al::alSourcei(al_source, ffi::AL_BUFFER, 0);
        }));
        let file = self.file.as_ref().unwrap().clone();
        chan.send(*file);
    }

}

impl AudioTags for Music {
    /**
     * Get the tags of a Sound.
     *
     * # Return
     * A borrowed pointer to the internal struct SoundTags
     */
    fn get_tags(&self) -> Tags {
        self.sound_tags.clone()
    }
}

impl AudioController for Music {
    /**
     * Play or resume the Music.
     */
    fn play(&mut self) -> () {
        check_openal_context!(());

        match self.get_state() {
            Paused   => { al::alSourcePlay(self.al_source); return; },
            _       => {
                if self.is_playing() {
                    al::alSourceStop(self.al_source);
                    // wait a bit for openal terminate
                    sleep(Duration::from_millis(50));
                }
                self.file.as_mut().unwrap().seek(0, SeekSet);
                self.process_music();
            }
        }
    }

    /**
     * Pause the Music.
     */
    fn pause(&mut self) -> () {
        check_openal_context!(());

        al::alSourcePause(self.al_source)
    }

    /**
     * Stop the Music.
     */
    fn stop(&mut self) -> () {
        check_openal_context!(());

        al::alSourceStop(self.al_source);
    }

    /**
     * Check if the Music is playing or not.
     *
     * # Return
     * True if the Music is playing, false otherwise.
     */
    fn is_playing(&self) -> bool {
        match self.get_state() {
            Playing     => true,
            _           => false
        }
    }

    /**
     * Get the current state of the Music
     *
     * # Return
     * The state of the music as a variant of the enum State
     */
    fn get_state(&self) -> State {
        check_openal_context!(Initial);

        let state  = al::alGetState(self.al_source);

        match state {
            ffi::AL_INITIAL => Initial,
            ffi::AL_PLAYING => Playing,
            ffi::AL_PAUSED  => Paused,
            ffi::AL_STOPPED => Stopped,
            _               => unreachable!()
        }
    }

    /**
     * Set the volume of the Music.
     *
     * A value of 1.0 means unattenuated. Each division by 2 equals an attenuation
     * of about -6dB. Each multiplicaton by 2 equals an amplification of about
     * +6dB.
     *
     * # Argument
     * * `volume` - The volume of the Music, should be between 0. and 1.
     */
    fn set_volume(&mut self, volume: f32) -> () {
        check_openal_context!(());

        al::alSourcef(self.al_source, ffi::AL_GAIN, volume);
    }

    /**
     * Get the volume of the Music.
     *
     * # Return
     * The volume of the Music between 0. and 1.
     */
    fn get_volume(&self) -> f32 {
        check_openal_context!(0.);

        let mut volume : f32 = 0.;
        al::alGetSourcef(self.al_source, ffi::AL_GAIN, &mut volume);
        volume
    }

    /**
     * Set the minimal volume for a Music.
     *
     * The minimum volume allowed for a music, after distance and cone
     * attenation is applied (if applicable).
     *
     * # Argument
     * * `min_volume` - The new minimal volume of the Music should be
     * between 0. and 1.
     */
    fn set_min_volume(&mut self, min_volume: f32) -> () {
        check_openal_context!(());

        al::alSourcef(self.al_source, ffi::AL_MIN_GAIN, min_volume);
    }

    /**
     * Get the minimal volume of the Music.
     *
     * # Return
     * The minimal volume of the Music between 0. and 1.
     */
    fn get_min_volume(&self) -> f32 {
        check_openal_context!(0.);

        let mut volume : f32 = 0.;
        al::alGetSourcef(self.al_source, ffi::AL_MIN_GAIN, &mut volume);
        volume
    }

    /**
     * Set the maximal volume for a Music.
     *
     * The maximum volume allowed for a Music, after distance and cone
     * attenation is applied (if applicable).
     *
     * # Argument
     * * `max_volume` - The new maximal volume of the Music should be
     * between 0. and 1.
     */
    fn set_max_volume(&mut self, max_volume: f32) -> () {
        check_openal_context!(());

        al::alSourcef(self.al_source, ffi::AL_MAX_GAIN, max_volume);
    }

    /**
     * Get the maximal volume of the Music.
     *
     * # Return
     * The maximal volume of the Music between 0. and 1.
     */
    fn get_max_volume(&self) -> f32 {
        check_openal_context!(0.);

        let mut volume : f32 = 0.;
        al::alGetSourcef(self.al_source, ffi::AL_MAX_GAIN, &mut volume);
        volume
    }

    /**
     * Set the Music looping or not
     *
     * The default looping is false.
     *
     * # Arguments
     * `looping` - The new looping state.
     */
    fn set_looping(&mut self, looping: bool) -> () {
        if let Some(ref sender) = self.looping_sender {
            sender.send(looping);
        }
        self.is_looping = looping;
    }

    /**
     * Check if the Music is looping or not
     *
     * # Return
     * True if the Music is looping, false otherwise.
     */
    fn is_looping(&self) -> bool {
        self.is_looping
    }

    /**
     * Set the pitch of the Music.
     *
     * A multiplier for the frequency (sample rate) of the Music's buffer.
     *
     * Default pitch is 1.0.
     *
     * # Argument
     * * `new_pitch` - The new pitch of the Music in the range [0.5 - 2.0]
     */
    fn set_pitch(&mut self, pitch: f32) -> () {
        check_openal_context!(());

        al::alSourcef(self.al_source, ffi::AL_PITCH, pitch)
    }

    /**
     * Set the pitch of the Music.
     *
     * # Return
     * The pitch of the Music in the range [0.5 - 2.0]
     */
    fn get_pitch(&self) -> f32 {
        check_openal_context!(0.);

        let mut pitch = 0.;
        al::alGetSourcef(self.al_source, ffi::AL_PITCH, &mut pitch);
        pitch
    }

    /**
     * Set the position of the Music relative to the listener or absolute.
     *
     * Default position is absolute.
     *
     * # Argument
     * `relative` - True to set Music relative to the listener false to set the
     * Music position absolute.
     */
    fn set_relative(&mut self, relative: bool) -> () {
        check_openal_context!(());

        match relative {
            true    => al::alSourcei(self.al_source,
                                     ffi::AL_SOURCE_RELATIVE,
                                     ffi::ALC_TRUE as i32),
            false   => al::alSourcei(self.al_source,
                                     ffi::AL_SOURCE_RELATIVE,
                                     ffi::ALC_FALSE as i32)
        };
    }

    /**
     * Is the Music relative to the listener or not?
     *
     * # Return
     * True if the Music is relative to the listener false otherwise
     */
    fn is_relative(&mut self) -> bool {
        check_openal_context!(false);

        let mut boolean = 0;
        al::alGetSourcei(self.al_source, ffi::AL_SOURCE_RELATIVE, &mut boolean);
        match boolean as i8 {
            ffi::ALC_TRUE  => true,
            ffi::ALC_FALSE => false,
            _              => unreachable!()
        }
    }

    /**
     * Set the Music location in three dimensional space.
     *
     * OpenAL, like OpenGL, uses a right handed coordinate system, where in a
     * frontal default view X (thumb) points right, Y points up (index finger),
     * and Z points towards the viewer/camera (middle finger).
     * To switch from a left handed coordinate system, flip the sign on the Z
     * coordinate.
     *
     * Default position is [0., 0., 0.].
     *
     * # Argument
     * * `position` - A three dimensional vector of f32 containing the position
     * of the listener [x, y, z].
     */
    fn set_position(&mut self, position: [f32; 3]) -> () {
        check_openal_context!(());

        al::alSourcefv(self.al_source, ffi::AL_POSITION, &position[0]);
    }

    /**
     * Get the position of the Music in three dimensional space.
     *
     * # Return
     * A three dimensional vector of f32 containing the position of the
     * listener [x, y, z].
     */
    fn get_position(&self) -> [f32; 3] {
        check_openal_context!([0.; 3]);

        let mut position : [f32; 3] = [0.; 3];
        al::alGetSourcefv(self.al_source, ffi::AL_POSITION, &mut position[0]);
        position
    }

    /**
     * Set the direction of the Music.
     *
     * Specifies the current direction in local space.
     *
     * The default direction is: [0., 0., 0.]
     *
     * # Argument
     * `direction` - The new direction of the Music.
     */
    fn set_direction(&mut self, direction: [f32; 3]) -> () {
        check_openal_context!(());

        al::alSourcefv(self.al_source, ffi::AL_DIRECTION, &direction[0]);
    }

    /**
     * Get the direction of the Music.
     *
     * # Return
     * The current direction of the Music.
     */
    fn get_direction(&self)  -> [f32; 3] {
        check_openal_context!([0.; 3]);

        let mut direction : [f32; 3] = [0.; 3];
        al::alGetSourcefv(self.al_source, ffi::AL_DIRECTION, &mut direction[0]);
        direction
    }

    /**
     * Set the maximum distance of the Music.
     *
     * The distance above which the source is not attenuated any further with a
     * clamped distance model, or where attenuation reaches 0.0 gain for linear
     * distance models with a default rolloff factor.
     *
     * The default maximum distance is +inf.
     *
     * # Argument
     * `max_distance` - The new maximum distance in the range [0., +inf]
     */
    fn set_max_distance(&mut self, max_distance: f32) -> () {
        check_openal_context!(());

        al::alSourcef(self.al_source, ffi::AL_MAX_DISTANCE, max_distance);
    }

    /**
     * Get the maximum distance of the Music.
     *
     * # Return
     * The maximum distance of the Music in the range [0., +inf]
     */
    fn get_max_distance(&self) -> f32 {
        check_openal_context!(0.);

        let mut max_distance = 0.;
        al::alGetSourcef(self.al_source, ffi::AL_MAX_DISTANCE, &mut max_distance);
        max_distance
    }

    /**
     * Set the reference distance of the Music.
     *
     * The distance in units that no attenuation occurs.
     * At 0.0, no distance attenuation ever occurs on non-linear
     * attenuation models.
     *
     * The default distance reference is 1.
     *
     * # Argument
     * * `ref_distance` - The new reference distance of the Music.
     */
    fn set_reference_distance(&mut self, ref_distance: f32) -> () {
        check_openal_context!(());

        al::alSourcef(self.al_source, ffi::AL_REFERENCE_DISTANCE, ref_distance);
    }

    /**
     * Get the reference distance of the Music.
     *
     * # Return
     * The current reference distance of the Music.
     */
    fn get_reference_distance(&self) -> f32 {
        check_openal_context!(1.);

        let mut ref_distance = 0.;
        al::alGetSourcef(self.al_source,
                         ffi::AL_REFERENCE_DISTANCE,
                         &mut ref_distance);
        ref_distance
    }

    /**
     * Set the attenuation of a Music.
     *
     * Multiplier to exaggerate or diminish distance attenuation.
     * At 0.0, no distance attenuation ever occurs.
     *
     * The default attenuation is 1.
     *
     * # Arguments
     * `attenuation` - The new attenuation for the Music in the range [0., 1.].
     */
    fn set_attenuation(&mut self, attenuation: f32) -> () {
        check_openal_context!(());

        al::alSourcef(self.al_source, ffi::AL_ROLLOFF_FACTOR, attenuation);
    }

    /**
     * Get the attenuation of a Music.
     *
     * # Return
     * The current attenuation for the Music in the range [0., 1.].
     */
    fn get_attenuation(&self) -> f32 {
        check_openal_context!(1.);

        let mut attenuation = 0.;
        al::alGetSourcef(self.al_source,
                         ffi::AL_ROLLOFF_FACTOR,
                         &mut attenuation);
        attenuation
    }
}


impl Drop for Music {
    /// Destroy all the resources of the Music.
    fn drop(&mut self) -> () {
        self.stop();
        if let Some(handle) = self.thread_handle.take() {
            handle.join();
        }
        unsafe {
            al::alSourcei(self.al_source, ffi::AL_BUFFER, 0);
            ffi::alDeleteBuffers(2, &mut self.al_buffers[0]);
            ffi::alDeleteSources(1, &mut self.al_source);
        }
    }
}

#[cfg(test)]
mod test {
    #![allow(non_snake_case)]

    use music::Music;
    use states::State::{Playing, Paused, Stopped};
    use audio_controller::AudioController;

    #[test]
    #[ignore]
    fn music_create_OK() -> () {
        let msc = Music::new("res/shot.wav");

        match msc {
            Some(_) => {},
            None    => panic!()
        }
    }

    #[test]
    #[ignore]
    fn music_create_FAIL() -> () {
        let msc = Music::new("toto.wav");

        match msc {
            Some(_) => panic!(),
            None    => {}
        }
    }

    #[test]
    #[ignore]
    fn music_play_OK() -> () {
        let mut msc = Music::new("res/shot.wav").expect("Cannot create Music");

        msc.play();
        assert_eq!(msc.get_state() as i32, Playing as i32);
        msc.stop();
    }

    #[test]
    #[ignore]
    fn music_pause_OK() -> () {
        let mut msc = Music::new("res/shot.wav").expect("Cannot create Music");

        msc.play();
        msc.pause();
        assert_eq!(msc.get_state() as i32, Paused as i32);
        msc.stop();
    }

    #[test]
    #[ignore]
    fn music_stop_OK() -> () {
        let mut msc = Music::new("res/shot.wav").expect("Cannot create Music");

        msc.play();
        msc.stop();
        assert_eq!(msc.get_state() as i32, Stopped as i32);
        msc.stop();
    }


    #[test]
    #[ignore]
    fn music_is_playing_TRUE() -> () {
        let mut msc = Music::new("res/shot.wav").expect("Cannot create Music");

        msc.play();
        assert_eq!(msc.is_playing(), true);
        msc.stop();
    }

    #[test]
    #[ignore]
    fn music_is_playing_FALSE() -> () {
        let mut msc = Music::new("res/shot.wav").expect("Cannot create Music");

        assert_eq!(msc.is_playing(), false);
        msc.stop();
    }

    #[test]
    #[ignore]
    fn music_set_volume_OK() -> () {
        let mut msc = Music::new("res/shot.wav").expect("Cannot create Music");

        msc.set_volume(0.7);
        assert_eq!(msc.get_volume(), 0.7);
    }

    #[test]
    #[ignore]
    fn music_set_min_volume_OK() -> () {
        let mut msc = Music::new("res/shot.wav").expect("Cannot create Music");

        msc.set_min_volume(0.1);
        assert_eq!(msc.get_min_volume(), 0.1);
    }

    #[test]
    #[ignore]
    fn music_set_max_volume_OK() -> () {
        let mut msc = Music::new("res/shot.wav").expect("Cannot create Music");

        msc.set_max_volume(0.9);
        assert_eq!(msc.get_max_volume(), 0.9);
    }

    #[test]
    #[ignore]
    fn music_is_looping_TRUE() -> () {
        let mut msc = Music::new("res/shot.wav").expect("Cannot create Music");

        msc.set_looping(true);
        assert_eq!(msc.is_looping(), true);
    }

    #[test]
    #[ignore]
    fn music_is_looping_FALSE() -> () {
        let mut msc = Music::new("res/shot.wav").expect("Cannot create Music");

        msc.set_looping(false);
        assert_eq!(msc.is_looping(), false);
    }

    #[test]
    #[ignore]
    fn music_set_pitch_OK() -> () {
        let mut msc = Music::new("res/shot.wav").expect("Cannot create Music");

        msc.set_pitch(1.5);
        assert_eq!(msc.get_pitch(), 1.5);
    }

     #[test]
     #[ignore]
    fn music_set_relative_TRUE() -> () {
        let mut msc = Music::new("res/shot.wav").expect("Cannot create Music");

        msc.set_relative(true);
        assert_eq!(msc.is_relative(), true);
    }

    #[test]
    #[ignore]
    fn music_set_relative_FALSE() -> () {
        let mut msc = Music::new("res/shot.wav").expect("Cannot create Music");

        msc.set_relative(false);
        assert_eq!(msc.is_relative(), false);
    }

    // untill https://github.com/rust-lang/rust/issues/7622 is not fixed, slice comparsion is used

    #[test]
    #[ignore]
    fn music_set_position_OK() -> () {
        let mut msc = Music::new("res/shot.wav").expect("Cannot create Music");

        msc.set_position([50., 150., 250.]);
        let res = msc.get_position();
        assert_eq!([res[0], res[1], res[2]], [50f32, 150f32, 250f32]);
    }

    #[test]
    #[ignore]
    fn music_set_direction_OK() -> () {
        let mut msc = Music::new("res/shot.wav").expect("Cannot create Music");

        msc.set_direction([50., 150., 250.]);
        let res = msc.get_direction();
        assert_eq!([res[0], res[1], res[2]], [50f32, 150f32, 250f32]);
    }

    #[test]
    #[ignore]
    fn music_set_max_distance() -> () {
        let mut msc = Music::new("res/shot.wav").expect("Cannot create Music");

        msc.set_max_distance(70.);
        assert_eq!(msc.get_max_distance(), 70.);
    }

    #[test]
    #[ignore]
    fn music_set_reference_distance() -> () {
        let mut msc = Music::new("res/shot.wav").expect("Cannot create Music");

        msc.set_reference_distance(70.);
        assert_eq!(msc.get_reference_distance(), 70.);
    }

    #[test]
    #[ignore]
    fn music_set_attenuation() -> () {
        let mut msc = Music::new("res/shot.wav").expect("Cannot create Music");

        msc.set_attenuation(0.5f32);
        println!("{}", &msc.get_attenuation());
        assert_eq!(&msc.get_attenuation(), &0.5f32);
    }
}