fn generate_map(
	mut contents: String,
	beats: &[Beat],
	pattern_collection: &PatternCollection,
	highest_pitch: f64,
	lowest_pitch: f64,
	beats_per_minute: f64,
	processed_notes: &mut Vec<PatternNote>,
) -> String {
	let mut obstacles_content: String = " ".to_owned();

	let mut pattern_map = HashMap::new();
	let mut pattern_end_time: f64 = 0.0;

	//we'll treat the lowest 10% as nothing
	let lowest_threshold = lowest_pitch * 1.10;

	let hard_threshold = highest_pitch * 0.25;
	let normal_threshold = highest_pitch * 0.65;

	let mut beat_id = 0;

	let mut left_prev_cut_direction: &CutDirection = &CUT_OMNI;
	let mut left_prev_x = 1;
	let mut left_prev_y = 2;
	let mut right_prev_cut_direction: &CutDirection = &CUT_OMNI;
	let mut right_prev_x = 2;
	let mut right_prev_y = 2;

	for beat in beats {
		//println!("peak :{} vs {}",beat.peak_time_sec,pattern_end_time);
		if beat.pitch > lowest_threshold && beat.peak_time_sec > pattern_end_time {
			let dynamic_pattern_chance = rand::thread_rng().gen_range(0, 100);

			if dynamic_pattern_chance <= CHANCE_FOR_DYNAMIC_PATTERN {
				let new_pattern: Pattern = generate_dynamic_pattern(
					left_prev_cut_direction,
					left_prev_x,
					left_prev_y,
					right_prev_cut_direction,
					right_prev_x,
					right_prev_y,
				);

				for pattern_note in &new_pattern.notes {
					if pattern_note.note_type == 0 {
						left_prev_cut_direction =
							&CUT_DIRECTIONS[pattern_note.cut_direction as usize];
						left_prev_x = pattern_note.x as usize;
						left_prev_y = pattern_note.y as usize;
					} else if pattern_note.note_type == 1 {
						right_prev_cut_direction =
							&CUT_DIRECTIONS[pattern_note.cut_direction as usize];
						right_prev_x = pattern_note.x as usize;
						right_prev_y = pattern_note.y as usize;
					}
				}
				let add_pattern_results: AddPatternResult = add_pattern(
					&new_pattern,
					contents,
					beats,
					processed_notes,
					beat_id,
					beats_per_minute,
					pattern_end_time,
					obstacles_content,
				);
				contents = add_pattern_results.contents;
				pattern_end_time = add_pattern_results.pattern_end_time;
				obstacles_content = add_pattern_results.obstacles_content;
			} else {
				let mut patterns = &pattern_collection.easy_patterns;
				if beat.pitch <= hard_threshold {
					patterns = &pattern_collection.normal_patterns;
				} else if beat.pitch <= normal_threshold {
					patterns = &pattern_collection.hard_patterns;
				}
				let random_pattern_id = rand::thread_rng().gen_range(0, patterns.len());

				//x = rand::thread_rng().gen_range(0, 2);
				let random_pattern = &patterns[random_pattern_id];

				let pattern = pattern_map.entry(beat.id).or_insert(random_pattern);

				let add_pattern_results: AddPatternResult = add_pattern(
					pattern,
					contents,
					beats,
					processed_notes,
					beat_id,
					beats_per_minute,
					pattern_end_time,
					obstacles_content,
				);
				contents = add_pattern_results.contents;
				pattern_end_time = add_pattern_results.pattern_end_time;
				obstacles_content = add_pattern_results.obstacles_content;
			}
		}
		beat_id += 1;
	}

	//generate walls
	//contents = generate_walls(contents, wall_times, &peak_pitches, beats_per_minute, time, lowest_pitch);

	let contents_end: String = format!(
		"{{
			\"_time\": 0.0,
			\"_lineIndex\": 3,
			\"_lineLayer\": 3,
			\"_type\": 1,
			\"_cutDirection\": 0
		}}],
		\"_obstacles\": [{}
			{{
				\"_time\": 0,
				\"_lineIndex\": 0,
				\"_type\": 0,
				\"_duration\": 1,
				\"_width\": 1
			}}]
		}}",
		obstacles_content
	)
	.to_owned();

	//add to json string
	contents.push_str(&contents_end);
	let note_count = processed_notes.len();
	println!("note count:{}", note_count.to_owned());
	//return the completed json string
	(contents)
}
/*
* Generate a bsaber map using the information provided
*/
Generate a bsaber map using the information provided
Generate a bsaber map using the information provided
fn generate_map(
	mut contents: String,
	beats: &[Beat],
	pattern_collection: &PatternCollection,
	highest_pitch: f64,
	lowest_pitch: f64,
	beats_per_minute: f64,
	processed_notes: &mut Vec<PatternNote>,
) -> String {
	let mut obstacles_content: String = " ".to_owned();
	let mut pattern_map = HashMap::new();
	let mut pattern_end_time: f64 = 0.0;
	//we'll treat the lowest 10% as nothing
	let lowest_threshold = lowest_pitch * 1.10;
	let hard_threshold = highest_pitch * 0.25;
	let normal_threshold = highest_pitch * 0.65;
	let mut beat_id = 0;
	let mut left_prev_cut_direction: &CutDirection = &CUT_OMNI;
	let mut left_prev_x = 1;
	let mut left_prev_y = 2;
	let mut right_prev_cut_direction: &CutDirection = &CUT_OMNI;
	let mut right_prev_x = 2;
	let mut right_prev_y = 2;
	for beat in beats {
		//println!("peak :{} vs {}",beat.peak_time_sec,pattern_end_time);
		if beat.pitch > lowest_threshold && beat.peak_time_sec > pattern_end_time {
			let dynamic_pattern_chance = rand::thread_rng().gen_range(0, 100);
			if dynamic_pattern_chance <= CHANCE_FOR_DYNAMIC_PATTERN {
				let new_pattern: Pattern = generate_dynamic_pattern(
					left_prev_cut_direction,
					left_prev_x,
					left_prev_y,
					right_prev_cut_direction,
					right_prev_x,
					right_prev_y,
				);
				for pattern_note in &new_pattern.notes {
					if pattern_note.note_type == 0 {
						left_prev_cut_direction =
							&CUT_DIRECTIONS[pattern_note.cut_direction as usize];
						left_prev_x = pattern_note.x as usize;
						left_prev_y = pattern_note.y as usize;
					} else if pattern_note.note_type == 1 {
						right_prev_cut_direction =
							&CUT_DIRECTIONS[pattern_note.cut_direction as usize];
						right_prev_x = pattern_note.x as usize;
						right_prev_y = pattern_note.y as usize;
					}
				}
				let add_pattern_results: AddPatternResult = add_pattern(
					&new_pattern,
					contents,
					beats,
					processed_notes,
					beat_id,
					beats_per_minute,
					pattern_end_time,
					obstacles_content,
				);
				contents = add_pattern_results.contents;
				pattern_end_time = add_pattern_results.pattern_end_time;
				obstacles_content = add_pattern_results.obstacles_content;
			} else {
				let mut patterns = &pattern_collection.easy_patterns;
				if beat.pitch <= hard_threshold {
					patterns = &pattern_collection.normal_patterns;
				} else if beat.pitch <= normal_threshold {
					patterns = &pattern_collection.hard_patterns;
				}
				let random_pattern_id = rand::thread_rng().gen_range(0, patterns.len());
				//x = rand::thread_rng().gen_range(0, 2);
				let random_pattern = &patterns[random_pattern_id];
				let pattern = pattern_map.entry(beat.id).or_insert(random_pattern);
				let add_pattern_results: AddPatternResult = add_pattern(
					pattern,
					contents,
					beats,
					processed_notes,
					beat_id,
					beats_per_minute,
					pattern_end_time,
					obstacles_content,
				);
				contents = add_pattern_results.contents;
				pattern_end_time = add_pattern_results.pattern_end_time;
				obstacles_content = add_pattern_results.obstacles_content;
			}
		}
		beat_id += 1;
	}
	//generate walls
	//contents = generate_walls(contents, wall_times, &peak_pitches, beats_per_minute, time, lowest_pitch);
	let contents_end: String = format!(
		"{{
			\"_time\": 0.0,
			\"_lineIndex\": 3,
			\"_lineLayer\": 3,
			\"_type\": 1,
			\"_cutDirection\": 0
		}}],
		\"_obstacles\": [{}
			{{
				\"_time\": 0,
				\"_lineIndex\": 0,
				\"_type\": 0,
				\"_duration\": 1,
				\"_width\": 1
			}}]
		}}",
		obstacles_content
	)
	.to_owned();
	//add to json string
	contents.push_str(&contents_end);
	let note_count = processed_notes.len();
	println!("note count:{}", note_count.to_owned());
	//return the completed json string
	(contents)
}
fn generate_map ( mut contents : String , beats : & [ Beat ] , pattern_collection : & PatternCollection , highest_pitch : f64 , lowest_pitch : f64 , beats_per_minute : f64 , processed_notes : & mut Vec < PatternNote > , ) -> String { let mut obstacles_content : String = " " . to_owned ( ) ; let mut pattern_map = HashMap :: new ( ) ; let mut pattern_end_time : f64 = 0.0 ; //we'll treat the lowest 10% as nothing let lowest_threshold = lowest_pitch * 1.10 ; let hard_threshold = highest_pitch * 0.25 ; let normal_threshold = highest_pitch * 0.65 ; let mut beat_id = 0 ; let mut left_prev_cut_direction : & CutDirection = & CUT_OMNI ; let mut left_prev_x = 1 ; let mut left_prev_y = 2 ; let mut right_prev_cut_direction : & CutDirection = & CUT_OMNI ; let mut right_prev_x = 2 ; let mut right_prev_y = 2 ; for beat in beats { //println!("peak :{} vs {}",beat.peak_time_sec,pattern_end_time); if beat . pitch > lowest_threshold && beat . peak_time_sec > pattern_end_time { let dynamic_pattern_chance = rand :: thread_rng ( ) . gen_range ( 0 , 100 ) ; if dynamic_pattern_chance <= CHANCE_FOR_DYNAMIC_PATTERN { let new_pattern : Pattern = generate_dynamic_pattern ( left_prev_cut_direction , left_prev_x , left_prev_y , right_prev_cut_direction , right_prev_x , right_prev_y , ) ; for pattern_note in & new_pattern . notes { if pattern_note . note_type == 0 { left_prev_cut_direction = & CUT_DIRECTIONS [ pattern_note . cut_direction as usize ] ; left_prev_x = pattern_note . x as usize ; left_prev_y = pattern_note . y as usize ; } else if pattern_note . note_type == 1 { right_prev_cut_direction = & CUT_DIRECTIONS [ pattern_note . cut_direction as usize ] ; right_prev_x = pattern_note . x as usize ; right_prev_y = pattern_note . y as usize ; } } let add_pattern_results : AddPatternResult = add_pattern ( & new_pattern , contents , beats , processed_notes , beat_id , beats_per_minute , pattern_end_time , obstacles_content , ) ; contents = add_pattern_results . contents ; pattern_end_time = add_pattern_results . pattern_end_time ; obstacles_content = add_pattern_results . obstacles_content ; } else { let mut patterns = & pattern_collection . easy_patterns ; if beat . pitch <= hard_threshold { patterns = & pattern_collection . normal_patterns ; } else if beat . pitch <= normal_threshold { patterns = & pattern_collection . hard_patterns ; } let random_pattern_id = rand :: thread_rng ( ) . gen_range ( 0 , patterns . len ( ) ) ; //x = rand::thread_rng().gen_range(0, 2); let random_pattern = & patterns [ random_pattern_id ] ; let pattern = pattern_map . entry ( beat . id ) . or_insert ( random_pattern ) ; let add_pattern_results : AddPatternResult = add_pattern ( pattern , contents , beats , processed_notes , beat_id , beats_per_minute , pattern_end_time , obstacles_content , ) ; contents = add_pattern_results . contents ; pattern_end_time = add_pattern_results . pattern_end_time ; obstacles_content = add_pattern_results . obstacles_content ; } } beat_id += 1 ; } //generate walls //contents = generate_walls(contents, wall_times, &peak_pitches, beats_per_minute, time, lowest_pitch); let contents_end : String = format ! ( " \" \" \" \" \" \" \" \" \" \" \" \" \" \" \" \" \" \" \" \" \" \" " obstacles_content ) . to_owned ( ) ; //add to json string contents . push_str ( & contents_end ) ; let note_count = processed_notes . len ( ) ; println ! ( " " note_count to_owned ( ) ) ; //return the completed json string ( contents ) }
Generate a bsaber map using the information provided
Generate a bsaber map using the information provided
contents
String
beats
&[Beat]
pattern_collection
&PatternCollection
highest_pitch
f64
lowest_pitch
f64
beats_per_minute
f64
processed_notes
&mut Vec<PatternNote>
contents
String
beats
&[Beat]
pattern_collection
&PatternCollection
highest_pitch
f64
lowest_pitch
f64
beats_per_minute
f64
processed_notes
&mut Vec<PatternNote>