Posted in C# Programming, Programming

Rounding up/down in C#

Random C# Notes. Using Visual Studio 2010. Some of this information has obtained through self-discovery, books, or random Google searches from other sites. I will give credit to the original author where due.

These are just plain code notes- not meant to be a tutorial.

Code is in italics.

Round  up/down a number or variable:

Math.Round(number, x);

Rounds a number “number” by “x” amount of places.

Math.Round(37.777, 2); //will result in 37.78


Create and activate a “Reset” or “Clear” button. This is useful if you want to clear the user’s entry. This code needs to be added after double-clicking the button which will “clear” or “reset” the field.

TextBox.Clear(); //(WPF)
TextBox.ResetText(); //(Windows Form Application)
label2.Text = ” “; // This sets the code for the label as one blank space, making it look empty (it’s not really empty, its value is a blank space… but it works, WPF)

Code for an “Exit” application button or command:


I’ve got to find a better way to do this… Maybe a OneNote document…

I’ll be back with more.

Posted in Computers, Music, Programming

Writing Some Python Code

I’ve written a neat little program using Python 2.6.4, which allows me to list the folders in a directory that match a specific criteria that I’ve set.

Here is a bit of history and reason for the program, before I describe it.

When I began ripping my CD collection with EAC and iTunesEncode, I was still fairly new to EAC, and had very, very little previous exposure and experience with the program. To make a long story short, I ripped some CDs, which – without taking notice right away – need to be re-ripped due to incorrect settings in EAC and iTunesEncode, since I was still playing with the different settings and parameters.

When I went back to add these to iTunes for properly tagging, adding an album art and organizing them in my Lossless Library, I discovered that I had quite a few of these “ripped” CDs that didn’t play, so I labeled the folder name “Artist Name – Album Name + ‘Needs RE-RIP’, with the idea of later going back to these CDs and ripping them again.

But instead of going through the folder and manually picking out which ones I had earlier tagged to be re-ripped, I wrote some Python code to help me do this.
The program is quite simple: Lists the folders in the EAC – Ripped directory that have the word “RIP” anywhere in the directory name; a process that I would have had to do manually. Instead, the small program picks out those which need ripping again, puts them on a list, and saves this list to a file! Now it’s much easier to pick out the ones that I need, instead of manually going through the directory.

Now – I haven’t got much programming experience – just some Python, C, C++ stuff that I’ve learned in school and studied/practiced on my own. I used the Internet as a refresher to help me remember how to open a file, and write to it, and how to list the contents of a directory. Besides that, the rest I coded by using previous examples and experience.

Anyways, without much further blabber, here is the code and the output. Feel free to leave some comments, use it and change it a bit if need.



import os, io

def main():
count = 0
countLine = 0
musicDir = os.listdir(“/Volumes/MUSIC/EAC Ripped/EAC Ripped – Needs Tagging/”)
musicDirPath = “/Volumes/MUSIC/EAC Ripped/EAC Ripped – Needs Tagging/”
outFile = open(“/Volumes/Mac HD/Users/Juan/Desktop/Needs Rip.txt”,”w”)

print “*” * 60
print musicDirPath
print “*” * 60


for needsRip in musicDir:
if “RIP” in needsRip:
count = count + 1
if (count < 10):
print "0"+str(count), "-",needsRip
outFile.write("\n0"+str(count)+" "+needsRip)
print str(count), "-",needsRip
outFile.write("\n"+str(count)+" "+needsRip)

print "\n*** CDs that need to be re-ripped: "+str(count)+" ***"



Here is the output:
/Volumes/MUSIC/EAC Ripped/EAC Ripped – Needs Tagging/

01 – Alejandro Fernandez – Me Estoy Enamorando RE-RIP
02 – Coldplay – X&Y – RE-RIP
03 – – Universal Religion 2004 (Live from Armada at Ibiza) RE-RIP
04 – Armin van Buuren – Transparance – CD1 RE-RIP
05 – Armin van Buuren – Transparance – CD2 RE-RIP
06 – Astor Piazzolla – La Camorra RE-RIP
07 – Celine Dion – All The Way… A Decade Of Song RE-RIP
08 – Coldplay – Parachutes RE-RIP
09 – Coldplay – Viva La Vida Or Death And All His Friends RE-RIP
10 – Deep Dish – Global Underground #021- Moscow – Deep Dish (Disc 1) RE-RIP
11 – Deep Dish – Global Underground #021- Moscow – Deep Dish (Disc 2) RE-RIP
12 – Godsmack – Faceless RE-RIP
13 – Godsmack – IV RE-RIP
14 – Jonny Lang Lie to Me RE-RIP
15 – Jose Padilla – Cafe del Mar – Volumen Seis RE-RIP
16 – Counting Crows – August And Everything After – RE-RIP
17 – Michael Buble – Crazy Love – RE-RIP
18 – Ulrich Schnauss – A Strangely Isolated Place RE-RIP
19 – Led Zeppelin – Led Zeppelin II RE-RIP
20 – Led Zeppelin – Led Zeppelin III RE-RIP
21 – Nick Warren – Global Underground 011- Budapest [1] – RE-RIP
22 – Nick Warren – Nick Warren – Global Underground 011- Budapest [2]- RE-RIP
23 – Oakenfold Anthems – The Classic Perfecto Mix (Disc 3) – RE-RIP
24 – Yo-Yo Ma – Vivaldi's Cello RE-RIP
25 – zerO One – psy-fi RE-RIP
26 – Yo-Yo Ma & Friends – Songs Of Joy & Peace [Deluxe Edition] RE-RIP
27 – Paul Oakenfold – Oakenfold Anthems – The Classic Perfecto Mix (Disc 1) – RE-RIP
28 – Paul Oakenfold – Oakenfold Anthems – The Classic Perfecto Mix (Disc 2)- RE-RIP
29 – Yo-Yo Ma – Super Hits RE-RIP
30 – Zero One – Re-RIP
31 – Yo-Yo Ma – Appassionato RE-RIP
32 – 3 Doors Down – 3 Doors Down – WAV ONLY needs RE-RIP
33 – Coldplay – A Rush of Blood To The Head – RE-RIP
34 – Sarah Brightman – Harem RE-RIP
35 – Yo-Yo Ma – Obrigado Brazil RE-RIP
36 – Ricardo Arjona – Animal Nocturno RE-RIP
37 – Sarah McLachlan – Fumbling Towards Ecstasy RE-RIP
38 – Sarah McLachlan – Surfacing RE-RIP
39 – Staind – 14 Shades of Grey RE-RIP
40 – Staind – Dysfunction RE-RIP
41 – Staind – The Illusion of Progress RE-RIP
42 – Yo-Yo Ma – Soul of the Tango RE-RIP
43 – Boundaries Of Imagination – RE-RIP, errors

*** CDs that need to be re-ripped: 43 ***

Again – this is quite a basic program, but it does two things for me: Saves me some time, and, more importantly – gives me some more needed coding experience!

Additional Note: The spacing and indentation is not set correctly – not sure why it was not displayed correctly. Also, this was created on a Mac, so the directory paths are different if the program were to run in a PC.