GithubHelp home page GithubHelp logo

bmourad01 / fp3 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from opls17projects/fp3

0.0 0.0 0.0 91 KB

final project exploration #2: use a Racket library that will be part of your final project

Racket 100.00%

fp3's Introduction

rash and 2htdp/image

My name: Benjamin Mourad

I decided to expand on my FP1 submission this week.

Using rash and mpg123 package for Debian, I modified my code to play a selected MP3 file using the Linux shell.

The following function is based on the previous get-album procedure. Our needs are simple: get the path to the song we want to play.

; get the path to our song
(define (get-song-path lst artistname albumname songname)
  (filter (lambda (p)
            (and (string-ci=? (album (read-id3 p)) albumname)
                 (string-ci=? (artist (read-id3 p)) artistname)
                 (string-ci=? (song (read-id3 p)) songname)))
          lst))

And we can very simply pass on our desired information to the shell.

; replace with your desired artist, album, and song name
(define songpath (car (get-song-path myfiles "BONES" "Rotten" "Rotten")))
(define songpath-s (path->string songpath))
(rash "mpg123 $songpath-s")

Additionally, I wanted to display the corresponding album cover.

We start with a predicate for when we invoke find-files:

(define (coverpred p)
  (define ps (path->string p))
  (or (string-suffix? ps ".png") (string-suffix? ps ".jpg") (string-suffix? ps ".jpeg")))
; list of images, typically web releases contain at least one image file
; this file is the album cover
(define myimgs (find-files coverpred mypath))

After that, we convert to bitmap and scale it down to 200px by 200px:

; assume that the first image in the list is our album cover
(define cover (bitmap/file (car myimgs)))
(define cover-h (image-height cover))
(define cover-w (image-width cover))
(define factor-x (/ 200 cover-w))
(define factor-y (/ 200 cover-h))

; display the album cover
(place-image (scale/xy factor-x factor-y cover) 100 100 (rectangle 200 200 "solid" "gray"))

And that's all there is to it. An interesting thing to note is that the length of the song is displayed in the output of mpg123. Very nice.

test image

fp3's People

Contributors

bmourad01 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.