sound fixed!
This commit is contained in:
parent
b39a778b2d
commit
c3ef0c4b7b
12 changed files with 27 additions and 23 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
@ -87,9 +87,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bitflags"
|
name = "bitflags"
|
||||||
version = "1.2.1"
|
version = "1.3.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
|
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bumpalo"
|
name = "bumpalo"
|
||||||
|
|
|
@ -13,21 +13,16 @@ use crate::soundGenerator;
|
||||||
pub struct Bar {
|
pub struct Bar {
|
||||||
pub position:usize,
|
pub position:usize,
|
||||||
pub color:color::Color,
|
pub color:color::Color,
|
||||||
sound:Sound,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
impl Bar{
|
impl Bar{
|
||||||
pub async fn new(position:usize, hsl_color:f32, frequency:f32) -> Self{
|
pub fn new(position:usize, hsl_color:f32) -> Self{
|
||||||
Bar{
|
Bar{
|
||||||
position,
|
position,
|
||||||
color: color::hsl_to_rgb((hsl_color as f32) , 1.0, 0.5),
|
color: color::hsl_to_rgb((hsl_color as f32) , 1.0, 0.5),
|
||||||
sound:soundGenerator::generateTone(frequency, 0.1).await
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn playSound(&self ){
|
|
||||||
play_sound(self.sound, PlaySoundParams::default());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
|
|
||||||
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
|
use macroquad::audio::{play_sound_once, Sound};
|
||||||
use macroquad::color::{BROWN, WHITE};
|
use macroquad::color::{BROWN, WHITE};
|
||||||
use macroquad::{hash, time};
|
use macroquad::{hash, time};
|
||||||
use macroquad::prelude::{clear_background, Vec2, BLACK};
|
use macroquad::prelude::{clear_background, Vec2, BLACK};
|
||||||
|
@ -11,6 +12,7 @@ use macroquad::time::{get_frame_time, get_fps};
|
||||||
use macroquad::ui::root_ui;
|
use macroquad::ui::root_ui;
|
||||||
use macroquad::window::{next_frame, screen_height, screen_width};
|
use macroquad::window::{next_frame, screen_height, screen_width};
|
||||||
use crate::BarPlugin::Bar;
|
use crate::BarPlugin::Bar;
|
||||||
|
use crate::soundGenerator;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -29,7 +31,8 @@ pub struct GuiVec{
|
||||||
renderSkip:i32,
|
renderSkip:i32,
|
||||||
skipped:i32,
|
skipped:i32,
|
||||||
lastTouched:Vec<usize>,
|
lastTouched:Vec<usize>,
|
||||||
lastPlayed:f64
|
lastPlayed:f64,
|
||||||
|
sounds:Vec<Sound>
|
||||||
}
|
}
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
pub trait SortingList{
|
pub trait SortingList{
|
||||||
|
@ -71,8 +74,15 @@ impl SortingList for GuiVec{
|
||||||
|
|
||||||
for i in 1..length+1 {
|
for i in 1..length+1 {
|
||||||
let frequency = i as f32 * freqStep;
|
let frequency = i as f32 * freqStep;
|
||||||
list.push(Bar::new(i, (colorStep*i as f32)/360., frequency).await);
|
list.push(Bar::new(i, (colorStep*i as f32)/360.));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Generate sounds
|
||||||
|
let mut sounds = Vec::with_capacity(1000);
|
||||||
|
for i in (50..2100).step_by(2){
|
||||||
|
sounds.push(soundGenerator::generateTone(i as f32, 0.1).await);
|
||||||
|
}
|
||||||
|
|
||||||
GuiVec{
|
GuiVec{
|
||||||
list,
|
list,
|
||||||
initialSize:length as usize,
|
initialSize:length as usize,
|
||||||
|
@ -87,6 +97,7 @@ impl SortingList for GuiVec{
|
||||||
skipped:0,
|
skipped:0,
|
||||||
lastTouched:Vec::with_capacity(2),
|
lastTouched:Vec::with_capacity(2),
|
||||||
lastPlayed:0.,
|
lastPlayed:0.,
|
||||||
|
sounds,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,7 +179,7 @@ impl SortingList for GuiVec{
|
||||||
|
|
||||||
|
|
||||||
if time::get_time() + 0.5 >= self.lastPlayed{
|
if time::get_time() + 0.5 >= self.lastPlayed{
|
||||||
self.list[index1].playSound();
|
play_sound_once(self.sounds[ (self.list[index1].position * 1000 / self.list.len()) ]);
|
||||||
self.lastPlayed = time::get_time()+0.5;
|
self.lastPlayed = time::get_time()+0.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -251,7 +262,7 @@ impl SortingList for NonGuiVec{
|
||||||
async fn new(length:usize, delay:f32) -> Self{
|
async fn new(length:usize, delay:f32) -> Self{
|
||||||
let mut list = Vec::new();
|
let mut list = Vec::new();
|
||||||
for i in 0..(length as usize){
|
for i in 0..(length as usize){
|
||||||
list.push(Bar::new(i, i as f32, 0.0).await)
|
list.push(Bar::new(i, i as f32))
|
||||||
}
|
}
|
||||||
NonGuiVec { list: list }
|
NonGuiVec { list: list }
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,7 @@ use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn binartHeap_correct() {
|
fn binartHeap_correct() {
|
||||||
let mut list:NonGuiVec = SortingList::new(1000,0.0);
|
let mut list:NonGuiVec = aw!(SortingList::new(1000,0.0));
|
||||||
aw!(binaryHeap(&mut list));
|
aw!(binaryHeap(&mut list));
|
||||||
assert_eq!( list.isSorted(), true);
|
assert_eq!( list.isSorted(), true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn bogoSort_correct_this_is_a_meme() {
|
fn bogoSort_correct_this_is_a_meme() {
|
||||||
let mut list:NonGuiVec = SortingList::new(5,0.0);
|
let mut list:NonGuiVec = aw!(SortingList::new(5,0.0));
|
||||||
aw!(bogoSort(&mut list));
|
aw!(bogoSort(&mut list));
|
||||||
assert_eq!( list.isSorted(), true);
|
assert_eq!( list.isSorted(), true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn bubblesort_correct() {
|
fn bubblesort_correct() {
|
||||||
let mut list:NonGuiVec = SortingList::new(1000,0.0);
|
let mut list:NonGuiVec = aw!(SortingList::new(1000,0.0));
|
||||||
aw!(bubbleSort(&mut list));
|
aw!(bubbleSort(&mut list));
|
||||||
assert_eq!( list.isSorted(), true);
|
assert_eq!( list.isSorted(), true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@ use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn coctailshakersort_correct() {
|
fn coctailshakersort_correct() {
|
||||||
let mut list:NonGuiVec = SortingList::new(1000,0.0);
|
let mut list:NonGuiVec = aw!(SortingList::new(1000,0.0));
|
||||||
aw!(cocktailShaker(&mut list));
|
aw!(cocktailShaker(&mut list));
|
||||||
assert_eq!( list.isSorted(), true);
|
assert_eq!( list.isSorted(), true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn insertsort_correct() {
|
fn insertsort_correct() {
|
||||||
let mut list:NonGuiVec = SortingList::new(1000,0.0);
|
let mut list:NonGuiVec = aw!(SortingList::new(1000,0.0));
|
||||||
aw!(insertSort(&mut list));
|
aw!(insertSort(&mut list));
|
||||||
assert_eq!( list.isSorted(), true);
|
assert_eq!( list.isSorted(), true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,7 +62,7 @@ use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn quicksort_correct() {
|
fn quicksort_correct() {
|
||||||
let mut list:NonGuiVec = SortingList::new(1000,0.0);
|
let mut list:NonGuiVec = aw!(SortingList::new(1000,0.0));
|
||||||
aw!(quickSort(&mut list));
|
aw!(quickSort(&mut list));
|
||||||
assert_eq!( list.isSorted(), true);
|
assert_eq!( list.isSorted(), true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,7 +98,7 @@ use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn radixsort_correct() {
|
fn radixsort_correct() {
|
||||||
let mut list:NonGuiVec = SortingList::new(1000,0.0);
|
let mut list:NonGuiVec = aw!(SortingList::new(1000,0.0));
|
||||||
aw!(radixSort(&mut list));
|
aw!(radixSort(&mut list));
|
||||||
assert_eq!( list.isSorted(), true);
|
assert_eq!( list.isSorted(), true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,7 +75,7 @@ use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn radixsort_correct() {
|
fn radixsort_correct() {
|
||||||
let mut list:NonGuiVec = SortingList::new(1000,0.0);
|
let mut list:NonGuiVec = aw!(SortingList::new(1000,0.0));
|
||||||
aw!(radixSort(&mut list));
|
aw!(radixSort(&mut list));
|
||||||
assert_eq!( list.isSorted(), true);
|
assert_eq!( list.isSorted(), true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,9 +10,7 @@ use std::path::Path;
|
||||||
|
|
||||||
use dropdown::ButtonDropDown;
|
use dropdown::ButtonDropDown;
|
||||||
|
|
||||||
use macroquad::audio::PlaySoundParams;
|
|
||||||
use macroquad::audio::play_sound;
|
|
||||||
use macroquad::audio::play_sound_once;
|
|
||||||
use macroquad::prelude::*;
|
use macroquad::prelude::*;
|
||||||
|
|
||||||
use macroquad::hash;
|
use macroquad::hash;
|
||||||
|
|
Loading…
Reference in a new issue