Python Forum
Assignment help: Creating a resulting “wave” from two files
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Assignment help: Creating a resulting “wave” from two files
#1
I'm currently having difficulty with a Python assignment for my introduction to programming class.

The spec requires us to create a "noise wave simulator", whereby we must look for a 'score' file in a 'scores' folder. Then we have to extract the instrument name from the score file, as well as the score bar. Then find the 'instrument' file for that instrument name in an 'instruments' folder. Once the file has been located, we have to print the resulting wave from the instrument file which has a pseudo wave to describe the shape? of the wave, with the score bar that contains a set of asterisks *.

I'm having difficulty in using the two files together, i.e. the score file and instrument file to produce the resulting waveform? Any suggestions on how to go about this?

Here's my code so far:
import sys, os

INSTRUMENT_PATH = os.listdir("instruments")

if len(sys.argv) < 2:
	print("No score file specified.")

for arg in sys.argv[1::]:
	if "--" in arg and not "/" in arg:
		print("No score file specified.")
	
	elif not os.path.exists(arg):
		print("Invalid path to score file.")
	
	else:
		if "/" in arg:
			score_path = arg
			
			with open(score_path) as score_file:
				instrument_name = score_file.readline().strip()
				instrument_notes = score_file.readline().strip().split("|")[1]
				
			print(instrument_name + ":")
			
			if instrument_name in INSTRUMENT_PATH:
				os.chdir("instruments")
				
				with open(instrument_name) as instrument_file:
					instrument_list = []
					
					for line in instrument_file:
						instrument_list.append(line.split("\t"))
					
					for elem in instrument_list:
						if int(elem[0]) >= 0:
							print(" {}: \t {}".format(int(elem[0]), elem[1].strip("\n")))

						else:
							print("{}: \t {}".format(int(elem[0]), elem[1].strip("\n")))

		else:
			pass
And here is a screenshot from the Spec provided, in case I didn't make it clear here. It also contains how the instrument and score file are structured.

https://i.imgur.com/llye3xw.png

Any help would be greatly appreciated, thank you! :)

Note: This spec example is a "simple" example meaning that the number of characters ('-', '/', '\') in the instrument file are equal to the number of characters in the score bar (*). I also want to have a testcase where there would be less asterisks given in the score bar, but still print the waveform correctly.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  I'm having trouble with my assignment for creating a math quiz thewrongnarwhal 7 8,043 Nov-14-2016, 08:06 AM
Last Post: Ofnuts

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020