MPCPi


#1

Hi,

Introduction: This is my very first project in the forums and only the second one using Python. While the first one was an SSHlogger to track the attacks received in the Raspberry Pi, so no more hardware than the Raspberry Pi itself was involved, this time I used the Explorer HAT Pro.

Before having with me such a great HAT I thought that it would be a good idea to do this project. After receiving it and looking at the samples I realized that drums.py is something really similar. This can be considered as a mod to the original drums.py

As I am new to almost everything related with the Raspberry Pi, except for Linux itself, I am very newbie at Python. I hope to get loads of critics, if they are constructive it’s always good. There are, for sure, better ways to write the same code.

I want to upload it to GitHub but don’t know how to do it yet, I’ll do it soon.

Background: Years ago music was one of my main hobbies, and MPC’s from Akai (see image above) were a toy I liked.

Never got one because I spent my money on turntables which I liked most.

Why not create a kind of MPC with the Explorer HAT from Piromoni?. In this project, I use touch pads from 5 to 8 to select a drum kit, and pads 1 to 4 to play the sound. This way we can play 16 loops as with the original MPC, need to be fast though!. I was lazy to look for 16 different sounds, I tested with 8. You can put your own sounds. The code is as follows:

#!/usr/bin/env python
print("""
This program turns your Explorer HAT into an Akai MPC!

Created by Iker García.
Based on the drums.py program, by Pimoroni. 

Hit any touch pad 5 to 8 to select a drum kit.
Hit any touch pad 1 to 4 to hear a drum sound.

Press CTRL+C to exit.
""")
import explorerhat
import pygame
import signal

pygame.mixer.pre_init(44100, -16, 1, 512)
pygame.mixer.init()
pygame.mixer.set_num_channels(16)

samples = ["1","2","3","4"] #This creates a default samples list, with four elements, to be updated later.
sounds = [] #This creates and empty sounds list.
def handle(ch, evt):
  if ch > 4: #This enables us to use touch pad from 5 to 8 to select a drum kit.
    if evt == 'press':
      if ch == 5:
        explorerhat.light.off() #Switches off lights in order not to confuse among drum kits.
        explorerhat.light.blue.on() #Turns on light so as to know which drum kit we are using.
        print("First drumkit selected") #Text to know which drum kit we are using.
        samples=['drumkit/808/8081.wav', 
	         'drumkit/808/8082.wav',
	         'drumkit/808/8083.wav',
	         'drumkit/808/8084.wav'] #The location of our loops.     
	
	for x in range(4): #Fills the sounds list, with our loops.
	  sounds.insert(x,(pygame.mixer.Sound(samples[x])))
  
      if ch == 6: #Same behaviour as previous channel, different loops.                                                               
        explorerhat.light.off()
        explorerhat.light.yellow.on()
        print("Second drumkit selected")
        samples=['drumkit/Jazz/Jazz1.wav',
	         'drumkit/Jazz/Jazz2.wav',
    	         'drumkit/Jazz/Jazz3.wav',
	         'drumkit/Jazz/Jazz4.wav']
       
        for x in range(4):
	  sounds.insert(x,(pygame.mixer.Sound(samples[x])))
	
      if ch == 7: #DEACTIVATED, UNLESS LOOPS ARE ADDED. 
        explorerhat.light.off()
        explorerhat.light.red.on()
        print("Third drumkit selected")
      # Write down the location of your loops.
      # Copy the for statement from previous channels.
		
      if ch == 8: #DEACTIVATED, UNLESS LOOPS ARE ADDED.
        explorerhat.light.off()
        explorerhat.light.green.on()
        print("Fourth drumkit selected")
      # Write down the location of your loops.
      # Copy the for statement from previous channels.
  
  if ch <= 4: #This enables us to use touch pads from 1 to 4 as drums.
    if evt == 'press':
      sounds[ch-1].play(loops=0) #Plays a sound
      
explorerhat.touch.pressed(handle)  #Function is called if touch pad is pressed.
explorerhat.touch.released(handle) #Function is called if touch pad is released.
signal.pause() #Sound is stopped.

Ok, it only hast one of the thousands features of a MPC, but I like to call it MPCPi.

Hope you like it and I am wishing to get a lot of opinions, even if they are bad. It’s the only way to learn.

Regards.


#2

Got a you tube video of it running? :)

You know, there is nothing stopping you recreating the entire system over the next few years. :)


#3

Thank you for your comment Richard and to the rest of you for the likes.

Excuse me for answering so late but, paradoxically, I’m busier (with pleasant duties, though) during holidays.

I don’t have a video but it’s a good idea, when I finish the project (enabling all the kits, adding sounds) I can récord one.

As I was writing the project in the forums I thought the same as you said, Richard. It would be nice to recreate a complete MPC. I’ll continue with other projects, learning and I’ll probably try in a future.

I have created a GitHub repo. I don’t know accurately how to use it but everyone is welcome to contribute, follow me and so on.

Regards.